diff options
author | Greg Kroah-Hartman <gregkh@suse.de> | 2009-03-23 20:07:37 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2009-04-03 17:54:27 -0400 |
commit | a9ea226670ffe24dd9b2f8ccc0909dfb14e35dd1 (patch) | |
tree | 1bcbcf933dfcdbc2a78792e3c5234a359d51f06f | |
parent | 5ca0121ff24d2efba208a0f6df2cb6e372170d1d (diff) |
Staging: serqt_usb: Lindent the code
Run Lindent on the code to give us someplace to work from
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/staging/serqt_usb/serqt_usb.c | 4026 |
1 files changed, 1945 insertions, 2081 deletions
diff --git a/drivers/staging/serqt_usb/serqt_usb.c b/drivers/staging/serqt_usb/serqt_usb.c index 7ababa0dfa7b..c9a7499c7866 100644 --- a/drivers/staging/serqt_usb/serqt_usb.c +++ b/drivers/staging/serqt_usb/serqt_usb.c | |||
@@ -20,34 +20,31 @@ | |||
20 | //#define DEBUG_ON | 20 | //#define DEBUG_ON |
21 | //#undef dbg | 21 | //#undef dbg |
22 | #ifdef DEBUG_ON | 22 | #ifdef DEBUG_ON |
23 | #define mydbg(const...) printk(const) | 23 | #define mydbg(const...) printk(const) |
24 | #else | 24 | #else |
25 | #define mydbg(const...) | 25 | #define mydbg(const...) |
26 | #endif | 26 | #endif |
27 | 27 | ||
28 | |||
29 | /* parity check flag */ | 28 | /* parity check flag */ |
30 | #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK)) | 29 | #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK)) |
31 | 30 | ||
32 | |||
33 | #define SERIAL_TTY_MAJOR 0 /* Nice legal number now */ | 31 | #define SERIAL_TTY_MAJOR 0 /* Nice legal number now */ |
34 | #define SERIAL_TTY_MINORS 255 /* loads of devices :) */ | 32 | #define SERIAL_TTY_MINORS 255 /* loads of devices :) */ |
35 | #define MAX_NUM_PORTS 8 /* The maximum number of ports one device can grab at once */ | 33 | #define MAX_NUM_PORTS 8 /* The maximum number of ports one device can grab at once */ |
36 | #define PREFUFF_LEVEL_CONSERVATIVE 128 | 34 | #define PREFUFF_LEVEL_CONSERVATIVE 128 |
37 | #define ATC_DISABLED 0x00 | 35 | #define ATC_DISABLED 0x00 |
38 | 36 | ||
39 | #define RR_BITS 0x03 //for clearing clock bits | 37 | #define RR_BITS 0x03 //for clearing clock bits |
40 | #define DUPMODE_BITS 0xc0 | 38 | #define DUPMODE_BITS 0xc0 |
41 | 39 | ||
42 | #define RS232_MODE 0x00 | 40 | #define RS232_MODE 0x00 |
43 | #define RTSCTS_TO_CONNECTOR 0x40 | 41 | #define RTSCTS_TO_CONNECTOR 0x40 |
44 | #define CLKS_X4 0x02 /// | 42 | #define CLKS_X4 0x02 /// |
45 | 43 | ||
46 | #define LOOPMODE_BITS 0x41 //LOOP1 = b6, LOOP0 = b0 (PORT B) | 44 | #define LOOPMODE_BITS 0x41 //LOOP1 = b6, LOOP0 = b0 (PORT B) |
47 | #define ALL_LOOPBACK 0x01 | 45 | #define ALL_LOOPBACK 0x01 |
48 | #define MODEM_CTRL 0x40 | 46 | #define MODEM_CTRL 0x40 |
49 | 47 | ||
50 | |||
51 | #define THISCHAR data[i] | 48 | #define THISCHAR data[i] |
52 | #define NEXTCHAR data[i + 1] | 49 | #define NEXTCHAR data[i + 1] |
53 | #define THIRDCHAR data[i + 2] | 50 | #define THIRDCHAR data[i + 2] |
@@ -58,7 +55,6 @@ | |||
58 | #define FULLPWRBIT 0x00000080 | 55 | #define FULLPWRBIT 0x00000080 |
59 | #define NEXT_BOARD_POWER_BIT 0x00000004 | 56 | #define NEXT_BOARD_POWER_BIT 0x00000004 |
60 | 57 | ||
61 | |||
62 | #define SERIAL_LSR_OE 0x02 | 58 | #define SERIAL_LSR_OE 0x02 |
63 | #define SERIAL_LSR_PE 0x04 | 59 | #define SERIAL_LSR_PE 0x04 |
64 | #define SERIAL_LSR_FE 0x08 | 60 | #define SERIAL_LSR_FE 0x08 |
@@ -76,7 +72,6 @@ | |||
76 | #define LINE_STATUS_REGISTER 0x05 | 72 | #define LINE_STATUS_REGISTER 0x05 |
77 | #define MODEM_STATUS_REGISTER 0x06 | 73 | #define MODEM_STATUS_REGISTER 0x06 |
78 | 74 | ||
79 | |||
80 | #define SERIAL_MCR_DTR 0x01 | 75 | #define SERIAL_MCR_DTR 0x01 |
81 | #define SERIAL_MCR_RTS 0x02 | 76 | #define SERIAL_MCR_RTS 0x02 |
82 | #define SERIAL_MCR_LOOP 0x10 | 77 | #define SERIAL_MCR_LOOP 0x10 |
@@ -100,7 +95,6 @@ | |||
100 | #define MAX_BAUD_RATE 460800 | 95 | #define MAX_BAUD_RATE 460800 |
101 | #define MAX_BAUD_REMAINDER 4608 | 96 | #define MAX_BAUD_REMAINDER 4608 |
102 | 97 | ||
103 | |||
104 | #define QT_SET_GET_DEVICE 0xc2 | 98 | #define QT_SET_GET_DEVICE 0xc2 |
105 | #define QT_OPEN_CLOSE_CHANNEL 0xca | 99 | #define QT_OPEN_CLOSE_CHANNEL 0xca |
106 | #define QT_GET_SET_PREBUF_TRIG_LVL 0xcc | 100 | #define QT_GET_SET_PREBUF_TRIG_LVL 0xcc |
@@ -119,8 +113,7 @@ | |||
119 | #define SERIALQT_GET_THIS_UNIT _IOR(SERIALQT_PCI_IOC_MAGIC, 3, void *) | 113 | #define SERIALQT_GET_THIS_UNIT _IOR(SERIALQT_PCI_IOC_MAGIC, 3, void *) |
120 | #define SERIALQT_READ_QOPR _IOR(SERIALQT_PCI_IOC_MAGIC, 4, int) | 114 | #define SERIALQT_READ_QOPR _IOR(SERIALQT_PCI_IOC_MAGIC, 4, int) |
121 | #define SERIALQT_READ_QMCR _IOR(SERIALQT_PCI_IOC_MAGIC, 5, int) | 115 | #define SERIALQT_READ_QMCR _IOR(SERIALQT_PCI_IOC_MAGIC, 5, int) |
122 | #define SERIALQT_IS422_EXTENDED _IOR(SERIALQT_PCI_IOC_MAGIC, 6, int) //returns successful if 422 extended | 116 | #define SERIALQT_IS422_EXTENDED _IOR(SERIALQT_PCI_IOC_MAGIC, 6, int) //returns successful if 422 extended |
123 | |||
124 | 117 | ||
125 | #define USBD_TRANSFER_DIRECTION_IN 0xc0 | 118 | #define USBD_TRANSFER_DIRECTION_IN 0xc0 |
126 | #define USBD_TRANSFER_DIRECTION_OUT 0x40 | 119 | #define USBD_TRANSFER_DIRECTION_OUT 0x40 |
@@ -129,7 +122,7 @@ | |||
129 | #define ATC_RTS_ENABLED 0x02 | 122 | #define ATC_RTS_ENABLED 0x02 |
130 | #define ATC_DTR_ENABLED 0x01 | 123 | #define ATC_DTR_ENABLED 0x01 |
131 | 124 | ||
132 | #define RR_BITS 0x03 //for clearing clock bits | 125 | #define RR_BITS 0x03 //for clearing clock bits |
133 | #define DUPMODE_BITS 0xc0 | 126 | #define DUPMODE_BITS 0xc0 |
134 | 127 | ||
135 | #define FULL_DUPLEX 0x00 | 128 | #define FULL_DUPLEX 0x00 |
@@ -147,75 +140,71 @@ | |||
147 | #define QMCR_ALL_LOOPBACK 0x10 | 140 | #define QMCR_ALL_LOOPBACK 0x10 |
148 | #define QMCR_MODEM_CONTROL 0X00 | 141 | #define QMCR_MODEM_CONTROL 0X00 |
149 | 142 | ||
150 | |||
151 | |||
152 | #define SERIALQT_IOC_MAXNR 6 | 143 | #define SERIALQT_IOC_MAXNR 6 |
153 | 144 | ||
154 | struct usb_serial_port { | 145 | struct usb_serial_port { |
155 | struct usb_serial *serial; /* pointer back to the owner of this port */ | 146 | struct usb_serial *serial; /* pointer back to the owner of this port */ |
156 | struct tty_struct * tty; /* the coresponding tty for this port */ | 147 | struct tty_struct *tty; /* the coresponding tty for this port */ |
157 | unsigned char number; | 148 | unsigned char number; |
158 | char active; /* someone has this device open */ | 149 | char active; /* someone has this device open */ |
159 | 150 | ||
160 | unsigned char * interrupt_in_buffer; | 151 | unsigned char *interrupt_in_buffer; |
161 | struct urb * interrupt_in_urb; | 152 | struct urb *interrupt_in_urb; |
162 | __u8 interrupt_in_endpointAddress; | 153 | __u8 interrupt_in_endpointAddress; |
163 | 154 | ||
164 | unsigned char * bulk_in_buffer; | 155 | unsigned char *bulk_in_buffer; |
165 | unsigned char * xfer_to_tty_buffer; | 156 | unsigned char *xfer_to_tty_buffer; |
166 | struct urb * read_urb; | 157 | struct urb *read_urb; |
167 | __u8 bulk_in_endpointAddress; | 158 | __u8 bulk_in_endpointAddress; |
168 | 159 | ||
169 | unsigned char * bulk_out_buffer; | 160 | unsigned char *bulk_out_buffer; |
170 | int bulk_out_size; | 161 | int bulk_out_size; |
171 | struct urb * write_urb; | 162 | struct urb *write_urb; |
172 | __u8 bulk_out_endpointAddress; | 163 | __u8 bulk_out_endpointAddress; |
173 | 164 | ||
174 | wait_queue_head_t write_wait; | 165 | wait_queue_head_t write_wait; |
175 | wait_queue_head_t wait; | 166 | wait_queue_head_t wait; |
176 | struct work_struct work; | 167 | struct work_struct work; |
177 | 168 | ||
178 | int open_count; /* number of times this port has been opened */ | 169 | int open_count; /* number of times this port has been opened */ |
179 | struct semaphore sem; /* locks this structure */ | 170 | struct semaphore sem; /* locks this structure */ |
180 | 171 | ||
181 | __u8 shadowLCR; /* last LCR value received */ | 172 | __u8 shadowLCR; /* last LCR value received */ |
182 | __u8 shadowMCR; /* last MCR value received */ | 173 | __u8 shadowMCR; /* last MCR value received */ |
183 | __u8 shadowMSR; /* last MSR value received */ | 174 | __u8 shadowMSR; /* last MSR value received */ |
184 | __u8 shadowLSR; /* last LSR value received */ | 175 | __u8 shadowLSR; /* last LSR value received */ |
185 | int RxHolding; | 176 | int RxHolding; |
186 | char closePending; | 177 | char closePending; |
187 | int ReadBulkStopped; | 178 | int ReadBulkStopped; |
188 | 179 | ||
189 | void * private; /* data private to the specific port */ | 180 | void *private; /* data private to the specific port */ |
190 | }; | 181 | }; |
191 | 182 | ||
192 | struct identity { | 183 | struct identity { |
193 | int index; | 184 | int index; |
194 | int n_identity; | 185 | int n_identity; |
195 | }; | 186 | }; |
196 | 187 | ||
197 | struct usb_serial { | 188 | struct usb_serial { |
198 | struct usb_device * dev; | 189 | struct usb_device *dev; |
199 | struct usb_interface * interface; /* the interface for this device */ | 190 | struct usb_interface *interface; /* the interface for this device */ |
200 | struct tty_driver * tty_driver; /* the tty_driver for this device */ | 191 | struct tty_driver *tty_driver; /* the tty_driver for this device */ |
201 | unsigned char minor; /* the starting minor number for this device */ | 192 | unsigned char minor; /* the starting minor number for this device */ |
202 | unsigned char num_ports; /* the number of ports this device has */ | 193 | unsigned char num_ports; /* the number of ports this device has */ |
203 | char num_interrupt_in; /* number of interrupt in endpoints we have */ | 194 | char num_interrupt_in; /* number of interrupt in endpoints we have */ |
204 | char num_bulk_in; /* number of bulk in endpoints we have */ | 195 | char num_bulk_in; /* number of bulk in endpoints we have */ |
205 | char num_bulk_out; /* number of bulk out endpoints we have */ | 196 | char num_bulk_out; /* number of bulk out endpoints we have */ |
206 | unsigned char num_OpenCount; /* the number of ports this device has */ | 197 | unsigned char num_OpenCount; /* the number of ports this device has */ |
207 | 198 | ||
208 | 199 | __u16 vendor; /* vendor id of this device */ | |
209 | __u16 vendor; /* vendor id of this device */ | 200 | __u16 product; /* product id of this device */ |
210 | __u16 product; /* product id of this device */ | 201 | struct usb_serial_port port[MAX_NUM_PORTS]; |
211 | struct usb_serial_port port[MAX_NUM_PORTS]; | 202 | |
212 | 203 | void *private; /* data private to the specific driver */ | |
213 | void * private; /* data private to the specific driver */ | ||
214 | }; | 204 | }; |
215 | 205 | ||
216 | 206 | static inline int port_paranoia_check(struct usb_serial_port *port, | |
217 | 207 | const char *function) | |
218 | static inline int port_paranoia_check (struct usb_serial_port *port, const char *function) | ||
219 | { | 208 | { |
220 | if (!port) { | 209 | if (!port) { |
221 | dbg("%s - port == NULL", function); | 210 | dbg("%s - port == NULL", function); |
@@ -233,9 +222,9 @@ static inline int port_paranoia_check (struct usb_serial_port *port, const char | |||
233 | return 0; | 222 | return 0; |
234 | } | 223 | } |
235 | 224 | ||
236 | |||
237 | /* Inline functions to check the sanity of a pointer that is passed to us */ | 225 | /* Inline functions to check the sanity of a pointer that is passed to us */ |
238 | static inline int serial_paranoia_check (struct usb_serial *serial, const char *function) | 226 | static inline int serial_paranoia_check(struct usb_serial *serial, |
227 | const char *function) | ||
239 | { | 228 | { |
240 | if (!serial) { | 229 | if (!serial) { |
241 | dbg("%s - serial == NULL\n", function); | 230 | dbg("%s - serial == NULL\n", function); |
@@ -245,13 +234,13 @@ static inline int serial_paranoia_check (struct usb_serial *serial, const char * | |||
245 | return 0; | 234 | return 0; |
246 | } | 235 | } |
247 | 236 | ||
248 | 237 | static inline struct usb_serial *get_usb_serial(struct usb_serial_port *port, | |
249 | static inline struct usb_serial* get_usb_serial (struct usb_serial_port *port, const char *function) | 238 | const char *function) |
250 | { | 239 | { |
251 | /* if no port was specified, or it fails a paranoia check */ | 240 | /* if no port was specified, or it fails a paranoia check */ |
252 | if (!port || | 241 | if (!port || |
253 | port_paranoia_check (port, function) || | 242 | port_paranoia_check(port, function) || |
254 | serial_paranoia_check (port->serial, function)) { | 243 | serial_paranoia_check(port->serial, function)) { |
255 | /* then say that we dont have a valid usb_serial thing, which will | 244 | /* then say that we dont have a valid usb_serial thing, which will |
256 | * end up genrating -ENODEV return values */ | 245 | * end up genrating -ENODEV return values */ |
257 | return NULL; | 246 | return NULL; |
@@ -260,90 +249,99 @@ static inline struct usb_serial* get_usb_serial (struct usb_serial_port *port, c | |||
260 | return port->serial; | 249 | return port->serial; |
261 | } | 250 | } |
262 | 251 | ||
263 | 252 | struct qt_get_device_data { | |
264 | struct qt_get_device_data | ||
265 | { | ||
266 | __u8 porta; | 253 | __u8 porta; |
267 | __u8 portb; | 254 | __u8 portb; |
268 | __u8 portc; | 255 | __u8 portc; |
269 | }; | 256 | }; |
270 | 257 | ||
271 | struct qt_open_channel_data | 258 | struct qt_open_channel_data { |
272 | { | ||
273 | __u8 line_status; | 259 | __u8 line_status; |
274 | __u8 modem_status; | 260 | __u8 modem_status; |
275 | }; | 261 | }; |
276 | 262 | ||
277 | static void ProcessLineStatus(struct usb_serial_port *port, unsigned char line_status); | 263 | static void ProcessLineStatus(struct usb_serial_port *port, |
278 | static void ProcessModemStatus(struct usb_serial_port *port, unsigned char modem_status); | 264 | unsigned char line_status); |
265 | static void ProcessModemStatus(struct usb_serial_port *port, | ||
266 | unsigned char modem_status); | ||
279 | static void ProcessRxChar(struct usb_serial_port *port, unsigned char Data); | 267 | static void ProcessRxChar(struct usb_serial_port *port, unsigned char Data); |
280 | static struct usb_serial *get_free_serial (int num_ports, int *minor); | 268 | static struct usb_serial *get_free_serial(int num_ports, int *minor); |
281 | |||
282 | 269 | ||
283 | static int serqt_probe(struct usb_interface *interface, | 270 | static int serqt_probe(struct usb_interface *interface, |
284 | const struct usb_device_id *id); | 271 | const struct usb_device_id *id); |
285 | |||
286 | 272 | ||
287 | static void serqt_usb_disconnect(struct usb_interface *interface); | 273 | static void serqt_usb_disconnect(struct usb_interface *interface); |
288 | static int box_set_device(struct usb_serial *serial, struct qt_get_device_data *pDeviceData); | 274 | static int box_set_device(struct usb_serial *serial, |
289 | static int box_get_device(struct usb_serial *serial, struct qt_get_device_data *pDeviceData); | 275 | struct qt_get_device_data *pDeviceData); |
290 | static int serial_open (struct tty_struct *tty, struct file * filp); | 276 | static int box_get_device(struct usb_serial *serial, |
291 | static void serial_close(struct tty_struct *tty, struct file * filp); | 277 | struct qt_get_device_data *pDeviceData); |
292 | static int serial_write_room (struct tty_struct *tty); | 278 | static int serial_open(struct tty_struct *tty, struct file *filp); |
293 | static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg); | 279 | static void serial_close(struct tty_struct *tty, struct file *filp); |
294 | static void serial_set_termios (struct tty_struct *tty, struct ktermios * old); | 280 | static int serial_write_room(struct tty_struct *tty); |
295 | static int serial_write (struct tty_struct * tty, const unsigned char *buf, int count); | 281 | static int serial_ioctl(struct tty_struct *tty, struct file *file, |
296 | 282 | unsigned int cmd, unsigned long arg); | |
297 | static void serial_throttle (struct tty_struct * tty); | 283 | static void serial_set_termios(struct tty_struct *tty, struct ktermios *old); |
298 | static void serial_unthrottle (struct tty_struct * tty); | 284 | static int serial_write(struct tty_struct *tty, const unsigned char *buf, |
299 | static int serial_break (struct tty_struct *tty, int break_state); | 285 | int count); |
300 | static int serial_chars_in_buffer (struct tty_struct *tty); | 286 | |
301 | static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data); | 287 | static void serial_throttle(struct tty_struct *tty); |
302 | 288 | static void serial_unthrottle(struct tty_struct *tty); | |
303 | static int qt_open (struct usb_serial_port *port, struct file *filp); | 289 | static int serial_break(struct tty_struct *tty, int break_state); |
290 | static int serial_chars_in_buffer(struct tty_struct *tty); | ||
291 | static int serial_read_proc(char *page, char **start, off_t off, int count, | ||
292 | int *eof, void *data); | ||
293 | |||
294 | static int qt_open(struct usb_serial_port *port, struct file *filp); | ||
304 | static int BoxSetPrebufferLevel(struct usb_serial *serial); | 295 | static int BoxSetPrebufferLevel(struct usb_serial *serial); |
305 | 296 | ||
306 | static int BoxSetATC(struct usb_serial *serial, __u16 n_Mode); | 297 | static int BoxSetATC(struct usb_serial *serial, __u16 n_Mode); |
307 | static int BoxSetUart(struct usb_serial *serial, unsigned short Uart_Number, unsigned short default_divisor, unsigned char default_LCR ); | 298 | static int BoxSetUart(struct usb_serial *serial, unsigned short Uart_Number, |
308 | 299 | unsigned short default_divisor, | |
309 | 300 | unsigned char default_LCR); | |
310 | static int BoxOPenCloseChannel(struct usb_serial *serial, __u16 Uart_Number, __u16 OpenClose, struct qt_open_channel_data *pDeviceData); | 301 | |
311 | static void qt_close (struct usb_serial_port *port, struct file * filp); | 302 | static int BoxOPenCloseChannel(struct usb_serial *serial, __u16 Uart_Number, |
312 | static int BoxGetRegister(struct usb_serial *serial, unsigned short Uart_Number,unsigned short Register_Num, __u8 *pValue); | 303 | __u16 OpenClose, |
313 | static int BoxSetRegister(struct usb_serial *serial, unsigned short Uart_Number, unsigned short Register_Num, unsigned short Value ); | 304 | struct qt_open_channel_data *pDeviceData); |
305 | static void qt_close(struct usb_serial_port *port, struct file *filp); | ||
306 | static int BoxGetRegister(struct usb_serial *serial, unsigned short Uart_Number, | ||
307 | unsigned short Register_Num, __u8 * pValue); | ||
308 | static int BoxSetRegister(struct usb_serial *serial, unsigned short Uart_Number, | ||
309 | unsigned short Register_Num, unsigned short Value); | ||
314 | static void qt_write_bulk_callback(struct urb *urb); | 310 | static void qt_write_bulk_callback(struct urb *urb); |
315 | static int qt_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count); | 311 | static int qt_write(struct usb_serial_port *port, int from_user, |
312 | const unsigned char *buf, int count); | ||
316 | static void port_softint(struct work_struct *work); | 313 | static void port_softint(struct work_struct *work); |
317 | static int qt_write_room (struct usb_serial_port *port); | 314 | static int qt_write_room(struct usb_serial_port *port); |
318 | static int qt_chars_in_buffer (struct usb_serial_port *port); | 315 | static int qt_chars_in_buffer(struct usb_serial_port *port); |
319 | static int qt_ioctl(struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); | 316 | static int qt_ioctl(struct usb_serial_port *port, struct file *file, |
320 | static void qt_set_termios(struct usb_serial_port *port, struct ktermios *old_termios); | 317 | unsigned int cmd, unsigned long arg); |
321 | static int BoxSetHW_FlowCtrl(struct usb_serial *serial, unsigned int UartNumber, int bSet); | 318 | static void qt_set_termios(struct usb_serial_port *port, |
319 | struct ktermios *old_termios); | ||
320 | static int BoxSetHW_FlowCtrl(struct usb_serial *serial, unsigned int UartNumber, | ||
321 | int bSet); | ||
322 | static int BoxDisable_SW_FlowCtrl(struct usb_serial *serial, __u16 UartNumber); | 322 | static int BoxDisable_SW_FlowCtrl(struct usb_serial *serial, __u16 UartNumber); |
323 | static int EmulateWriteQMCR_Reg(int index, unsigned uc_value); | 323 | static int EmulateWriteQMCR_Reg(int index, unsigned uc_value); |
324 | static int EmulateReadQMCR_Reg(int index, unsigned *uc_value); | 324 | static int EmulateReadQMCR_Reg(int index, unsigned *uc_value); |
325 | static struct usb_serial *find_the_box(unsigned int index); | 325 | static struct usb_serial *find_the_box(unsigned int index); |
326 | int ioctl_serial_usb (struct inode *innod, struct file *filp, unsigned int cmd, unsigned long arg); | 326 | int ioctl_serial_usb(struct inode *innod, struct file *filp, unsigned int cmd, |
327 | unsigned long arg); | ||
327 | 328 | ||
328 | 329 | static int BoxSetSW_FlowCtrl(struct usb_serial *serial, __u16 Uart, | |
329 | static int BoxSetSW_FlowCtrl(struct usb_serial *serial, __u16 Uart, unsigned char stop_char, unsigned char start_char); | 330 | unsigned char stop_char, unsigned char start_char); |
330 | static void qt_read_bulk_callback(struct urb *urb); | 331 | static void qt_read_bulk_callback(struct urb *urb); |
331 | 332 | ||
332 | static void port_sofrint(void *private); | 333 | static void port_sofrint(void *private); |
333 | 334 | ||
334 | static void return_serial(struct usb_serial *serial); | 335 | static void return_serial(struct usb_serial *serial); |
335 | 336 | ||
336 | 337 | static int serial_tiocmset(struct tty_struct *tty, struct file *file, | |
337 | static int serial_tiocmset (struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear); | 338 | unsigned int set, unsigned int clear); |
338 | static int serial_tiocmget(struct tty_struct *tty, struct file *file); | 339 | static int serial_tiocmget(struct tty_struct *tty, struct file *file); |
339 | 340 | ||
341 | static int qt_tiocmset(struct usb_serial_port *port, struct file *file, | ||
342 | unsigned int value); | ||
340 | 343 | ||
341 | 344 | static int qt_tiocmget(struct usb_serial_port *port, struct file *file); | |
342 | static int qt_tiocmset(struct usb_serial_port *port, struct file * file, unsigned int value); | ||
343 | |||
344 | static int qt_tiocmget(struct usb_serial_port *port, struct file * file); | ||
345 | |||
346 | |||
347 | 345 | ||
348 | /* Version Information */ | 346 | /* Version Information */ |
349 | #define DRIVER_VERSION "v2.14" | 347 | #define DRIVER_VERSION "v2.14" |
@@ -370,34 +368,39 @@ static int qt_tiocmget(struct usb_serial_port *port, struct file * file); | |||
370 | #define DEVICE_ID_QUATECH_RS422_16_PORT_C 0xC0B2 //HSU200C | 368 | #define DEVICE_ID_QUATECH_RS422_16_PORT_C 0xC0B2 //HSU200C |
371 | #define DEVICE_ID_QUATECH_RS422_16_PORT_D 0xC0B3 //HSU200D | 369 | #define DEVICE_ID_QUATECH_RS422_16_PORT_D 0xC0B3 //HSU200D |
372 | 370 | ||
373 | |||
374 | /* table of Quatech devices */ | 371 | /* table of Quatech devices */ |
375 | static struct usb_device_id serqt_table [] = { | 372 | static struct usb_device_id serqt_table[] = { |
376 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_SINGLE_PORT)}, | 373 | {USB_DEVICE |
377 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_SINGLE_PORT)}, | 374 | (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_SINGLE_PORT)}, |
378 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_DUAL_PORT)}, | 375 | {USB_DEVICE |
379 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_DUAL_PORT)}, | 376 | (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_SINGLE_PORT)}, |
380 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_FOUR_PORT)}, | 377 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_DUAL_PORT)}, |
381 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_FOUR_PORT)}, | 378 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_DUAL_PORT)}, |
382 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_EIGHT_PORT_A)}, | 379 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_FOUR_PORT)}, |
383 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_EIGHT_PORT_B)}, | 380 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_FOUR_PORT)}, |
384 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_EIGHT_PORT_A)}, | 381 | {USB_DEVICE |
385 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_EIGHT_PORT_B)}, | 382 | (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_EIGHT_PORT_A)}, |
386 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_A)}, | 383 | {USB_DEVICE |
387 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_B)}, | 384 | (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_EIGHT_PORT_B)}, |
388 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_C)}, | 385 | {USB_DEVICE |
389 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_D)}, | 386 | (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_EIGHT_PORT_A)}, |
390 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_A)}, | 387 | {USB_DEVICE |
391 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_B)}, | 388 | (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_EIGHT_PORT_B)}, |
392 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_C)}, | 389 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_A)}, |
393 | { USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_D)}, | 390 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_B)}, |
394 | {} /* Terminating entry */ | 391 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_C)}, |
392 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_D)}, | ||
393 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_A)}, | ||
394 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_B)}, | ||
395 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_C)}, | ||
396 | {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_D)}, | ||
397 | {} /* Terminating entry */ | ||
395 | }; | 398 | }; |
399 | |||
396 | MODULE_DEVICE_TABLE(usb, serqt_table); | 400 | MODULE_DEVICE_TABLE(usb, serqt_table); |
397 | 401 | ||
398 | static int major_number; | 402 | static int major_number; |
399 | static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; /* initially all NULL */ | 403 | static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; /* initially all NULL */ |
400 | |||
401 | 404 | ||
402 | /* table of Quatech 422devices */ | 405 | /* table of Quatech 422devices */ |
403 | static unsigned int serqt_422_table[] = { | 406 | static unsigned int serqt_422_table[] = { |
@@ -410,66 +413,64 @@ static unsigned int serqt_422_table[] = { | |||
410 | DEVICE_ID_QUATECH_RS422_16_PORT_B, | 413 | DEVICE_ID_QUATECH_RS422_16_PORT_B, |
411 | DEVICE_ID_QUATECH_RS422_16_PORT_C, | 414 | DEVICE_ID_QUATECH_RS422_16_PORT_C, |
412 | DEVICE_ID_QUATECH_RS422_16_PORT_D, | 415 | DEVICE_ID_QUATECH_RS422_16_PORT_D, |
413 | 0 /* terminate with zero */ | 416 | 0 /* terminate with zero */ |
414 | }; | 417 | }; |
415 | 418 | ||
416 | |||
417 | |||
418 | /* usb specific object needed to register this driver with the usb subsystem */ | 419 | /* usb specific object needed to register this driver with the usb subsystem */ |
419 | static struct usb_driver serqt_usb_driver = { | 420 | static struct usb_driver serqt_usb_driver = { |
420 | .name = "quatech-usb-serial", | 421 | .name = "quatech-usb-serial", |
421 | .probe = serqt_probe, | 422 | .probe = serqt_probe, |
422 | .disconnect = serqt_usb_disconnect, | 423 | .disconnect = serqt_usb_disconnect, |
423 | .id_table = serqt_table, | 424 | .id_table = serqt_table, |
424 | }; | 425 | }; |
425 | 426 | ||
426 | static struct ktermios *serial_termios[SERIAL_TTY_MINORS]; | 427 | static struct ktermios *serial_termios[SERIAL_TTY_MINORS]; |
427 | static struct ktermios *serial_termios_locked[SERIAL_TTY_MINORS]; | 428 | static struct ktermios *serial_termios_locked[SERIAL_TTY_MINORS]; |
428 | 429 | ||
429 | static const struct tty_operations serial_ops = { | 430 | static const struct tty_operations serial_ops = { |
430 | .open = serial_open, | 431 | .open = serial_open, |
431 | .close = serial_close, | 432 | .close = serial_close, |
432 | .write = serial_write, | 433 | .write = serial_write, |
433 | .write_room = serial_write_room, | 434 | .write_room = serial_write_room, |
434 | .ioctl = serial_ioctl, | 435 | .ioctl = serial_ioctl, |
435 | .set_termios = serial_set_termios, | 436 | .set_termios = serial_set_termios, |
436 | .throttle = serial_throttle, | 437 | .throttle = serial_throttle, |
437 | .unthrottle = serial_unthrottle, | 438 | .unthrottle = serial_unthrottle, |
438 | .break_ctl = serial_break, | 439 | .break_ctl = serial_break, |
439 | .chars_in_buffer = serial_chars_in_buffer, | 440 | .chars_in_buffer = serial_chars_in_buffer, |
440 | .read_proc = serial_read_proc, | 441 | .read_proc = serial_read_proc, |
441 | .tiocmset = serial_tiocmset, | 442 | .tiocmset = serial_tiocmset, |
442 | .tiocmget = serial_tiocmget, | 443 | .tiocmget = serial_tiocmget, |
443 | }; | 444 | }; |
444 | 445 | ||
445 | static struct tty_driver serial_tty_driver = { | 446 | static struct tty_driver serial_tty_driver = { |
446 | .magic = TTY_DRIVER_MAGIC, | 447 | .magic = TTY_DRIVER_MAGIC, |
447 | .driver_name = "Quatech usb-serial", | 448 | .driver_name = "Quatech usb-serial", |
448 | .name = "ttyQT_USB", | 449 | .name = "ttyQT_USB", |
449 | .major = SERIAL_TTY_MAJOR, | 450 | .major = SERIAL_TTY_MAJOR, |
450 | .minor_start = 0, | 451 | .minor_start = 0, |
451 | .num = SERIAL_TTY_MINORS, | 452 | .num = SERIAL_TTY_MINORS, |
452 | .type = TTY_DRIVER_TYPE_SERIAL, | 453 | .type = TTY_DRIVER_TYPE_SERIAL, |
453 | .subtype = SERIAL_TYPE_NORMAL, | 454 | .subtype = SERIAL_TYPE_NORMAL, |
454 | .flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV, | 455 | .flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV, |
455 | 456 | ||
456 | .termios = serial_termios, | 457 | .termios = serial_termios, |
457 | .termios_locked = serial_termios_locked, | 458 | .termios_locked = serial_termios_locked, |
458 | .init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL, | 459 | .init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL, |
459 | 460 | ||
460 | .init_termios.c_iflag = ICRNL | IXON, | 461 | .init_termios.c_iflag = ICRNL | IXON, |
461 | .init_termios.c_oflag = OPOST, | 462 | .init_termios.c_oflag = OPOST, |
462 | 463 | ||
463 | .init_termios.c_lflag= ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN, | 464 | .init_termios.c_lflag = |
465 | ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN, | ||
464 | }; | 466 | }; |
465 | 467 | ||
466 | //fops for parent device | 468 | //fops for parent device |
467 | static struct file_operations serialqt_usb_fops = { | 469 | static struct file_operations serialqt_usb_fops = { |
468 | .ioctl = ioctl_serial_usb, | 470 | .ioctl = ioctl_serial_usb, |
469 | 471 | ||
470 | }; | 472 | }; |
471 | 473 | ||
472 | |||
473 | /** | 474 | /** |
474 | * serqt_probe | 475 | * serqt_probe |
475 | * | 476 | * |
@@ -478,341 +479,299 @@ static struct file_operations serialqt_usb_fops = { | |||
478 | * | 479 | * |
479 | */ | 480 | */ |
480 | static int serqt_probe(struct usb_interface *interface, | 481 | static int serqt_probe(struct usb_interface *interface, |
481 | const struct usb_device_id *id) | 482 | const struct usb_device_id *id) |
482 | { | 483 | { |
483 | struct usb_device *dev = interface_to_usbdev(interface); | 484 | struct usb_device *dev = interface_to_usbdev(interface); |
484 | struct usb_serial *serial = NULL; | 485 | struct usb_serial *serial = NULL; |
485 | struct usb_serial_port *port; | 486 | struct usb_serial_port *port; |
486 | struct usb_endpoint_descriptor *endpoint; | 487 | struct usb_endpoint_descriptor *endpoint; |
487 | struct usb_endpoint_descriptor *interrupt_in_endpoint[MAX_NUM_PORTS]; | 488 | struct usb_endpoint_descriptor *interrupt_in_endpoint[MAX_NUM_PORTS]; |
488 | struct usb_endpoint_descriptor *bulk_in_endpoint[MAX_NUM_PORTS]; | 489 | struct usb_endpoint_descriptor *bulk_in_endpoint[MAX_NUM_PORTS]; |
489 | struct usb_endpoint_descriptor *bulk_out_endpoint[MAX_NUM_PORTS]; | 490 | struct usb_endpoint_descriptor *bulk_out_endpoint[MAX_NUM_PORTS]; |
490 | int minor; | 491 | int minor; |
491 | int buffer_size; | 492 | int buffer_size; |
492 | int i; | 493 | int i; |
493 | struct usb_host_interface *iface_desc; | 494 | struct usb_host_interface *iface_desc; |
494 | int num_interrupt_in = 0; | 495 | int num_interrupt_in = 0; |
495 | int num_bulk_in = 0; | 496 | int num_bulk_in = 0; |
496 | int num_bulk_out = 0; | 497 | int num_bulk_out = 0; |
497 | int num_ports; | 498 | int num_ports; |
498 | struct qt_get_device_data DeviceData; | 499 | struct qt_get_device_data DeviceData; |
499 | int status; | 500 | int status; |
500 | 501 | ||
501 | mydbg("In %s\n", __FUNCTION__); | 502 | mydbg("In %s\n", __FUNCTION__); |
502 | 503 | ||
503 | /* let's find the endpoints needed */ | 504 | /* let's find the endpoints needed */ |
504 | /* check out the endpoints */ | 505 | /* check out the endpoints */ |
505 | iface_desc = interface->cur_altsetting;; | 506 | iface_desc = interface->cur_altsetting;; |
506 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) | 507 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { |
507 | { | 508 | endpoint = &iface_desc->endpoint[i].desc; |
508 | endpoint = &iface_desc->endpoint[i].desc; | 509 | |
509 | 510 | if ((endpoint->bEndpointAddress & 0x80) && | |
510 | if ((endpoint->bEndpointAddress & 0x80) && | 511 | ((endpoint->bmAttributes & 3) == 0x02)) { |
511 | ((endpoint->bmAttributes & 3) == 0x02)) | 512 | /* we found a bulk in endpoint */ |
512 | { | 513 | mydbg("found bulk in"); |
513 | /* we found a bulk in endpoint */ | 514 | bulk_in_endpoint[num_bulk_in] = endpoint; |
514 | mydbg("found bulk in"); | 515 | ++num_bulk_in; |
515 | bulk_in_endpoint[num_bulk_in] = endpoint; | 516 | } |
516 | ++num_bulk_in; | 517 | |
517 | } | 518 | if (((endpoint->bEndpointAddress & 0x80) == 0x00) && |
518 | 519 | ((endpoint->bmAttributes & 3) == 0x02)) { | |
519 | if (((endpoint->bEndpointAddress & 0x80) == 0x00) && | 520 | /* we found a bulk out endpoint */ |
520 | ((endpoint->bmAttributes & 3) == 0x02)) | 521 | mydbg("found bulk out\n"); |
521 | { | 522 | bulk_out_endpoint[num_bulk_out] = endpoint; |
522 | /* we found a bulk out endpoint */ | 523 | ++num_bulk_out; |
523 | mydbg("found bulk out\n"); | 524 | } |
524 | bulk_out_endpoint[num_bulk_out] = endpoint; | 525 | |
525 | ++num_bulk_out; | 526 | if ((endpoint->bEndpointAddress & 0x80) && |
526 | } | 527 | ((endpoint->bmAttributes & 3) == 0x03)) { |
527 | 528 | /* we found a interrupt in endpoint */ | |
528 | if ((endpoint->bEndpointAddress & 0x80) && | 529 | mydbg("found interrupt in\n"); |
529 | ((endpoint->bmAttributes & 3) == 0x03)) | 530 | interrupt_in_endpoint[num_interrupt_in] = endpoint; |
530 | { | 531 | ++num_interrupt_in; |
531 | /* we found a interrupt in endpoint */ | 532 | } |
532 | mydbg("found interrupt in\n"); | 533 | } |
533 | interrupt_in_endpoint[num_interrupt_in] = endpoint; | 534 | |
534 | ++num_interrupt_in; | 535 | /* found all that we need */ |
535 | } | 536 | dev_info(&interface->dev, "Quatech converter detected\n"); |
536 | } | 537 | num_ports = num_bulk_out; |
537 | 538 | if (num_ports == 0) { | |
538 | /* found all that we need */ | 539 | err("Quatech device with no bulk out, not allowed."); |
539 | dev_info(&interface->dev, "Quatech converter detected\n"); | 540 | return -ENODEV; |
540 | num_ports = num_bulk_out; | 541 | |
541 | if (num_ports == 0) | 542 | } |
542 | { | 543 | |
543 | err("Quatech device with no bulk out, not allowed."); | 544 | serial = get_free_serial(num_ports, &minor); |
544 | return -ENODEV; | 545 | if (serial == NULL) { |
545 | 546 | err("No more free serial devices"); | |
546 | } | 547 | return -ENODEV; |
547 | 548 | } | |
548 | serial = get_free_serial (num_ports, &minor); | 549 | |
549 | if (serial == NULL) | 550 | serial->dev = dev; |
550 | { | 551 | serial->interface = interface; |
551 | err("No more free serial devices"); | 552 | serial->minor = minor; |
552 | return -ENODEV; | 553 | serial->num_ports = num_ports; |
553 | } | 554 | serial->num_bulk_in = num_bulk_in; |
554 | 555 | serial->num_bulk_out = num_bulk_out; | |
555 | serial->dev = dev; | 556 | serial->num_interrupt_in = num_interrupt_in; |
556 | serial->interface = interface; | 557 | serial->vendor = dev->descriptor.idVendor; |
557 | serial->minor = minor; | 558 | serial->product = dev->descriptor.idProduct; |
558 | serial->num_ports = num_ports; | 559 | |
559 | serial->num_bulk_in = num_bulk_in; | 560 | /* set up the endpoint information */ |
560 | serial->num_bulk_out = num_bulk_out; | 561 | for (i = 0; i < num_bulk_in; ++i) { |
561 | serial->num_interrupt_in = num_interrupt_in; | 562 | endpoint = bulk_in_endpoint[i]; |
562 | serial->vendor = dev->descriptor.idVendor; | 563 | port = &serial->port[i]; |
563 | serial->product = dev->descriptor.idProduct; | 564 | port->read_urb = usb_alloc_urb(0, GFP_KERNEL); |
564 | 565 | if (!port->read_urb) { | |
565 | 566 | err("No free urbs available"); | |
566 | /* set up the endpoint information */ | 567 | goto probe_error; |
567 | for (i = 0; i < num_bulk_in; ++i) | 568 | } |
568 | { | 569 | buffer_size = endpoint->wMaxPacketSize; |
569 | endpoint = bulk_in_endpoint[i]; | 570 | port->bulk_in_endpointAddress = endpoint->bEndpointAddress; |
570 | port = &serial->port[i]; | 571 | port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); |
571 | port->read_urb = usb_alloc_urb (0, GFP_KERNEL); | 572 | port->xfer_to_tty_buffer = kmalloc(buffer_size, GFP_KERNEL); |
572 | if (!port->read_urb) | 573 | if (!port->bulk_in_buffer) { |
573 | { | 574 | err("Couldn't allocate bulk_in_buffer"); |
574 | err("No free urbs available"); | 575 | goto probe_error; |
575 | goto probe_error; | 576 | } |
576 | } | 577 | usb_fill_bulk_urb(port->read_urb, dev, |
577 | buffer_size = endpoint->wMaxPacketSize; | 578 | usb_rcvbulkpipe(dev, |
578 | port->bulk_in_endpointAddress = endpoint->bEndpointAddress; | 579 | endpoint->bEndpointAddress), |
579 | port->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL); | 580 | port->bulk_in_buffer, buffer_size, |
580 | port->xfer_to_tty_buffer = kmalloc (buffer_size, GFP_KERNEL); | 581 | qt_read_bulk_callback, port); |
581 | if (!port->bulk_in_buffer) | 582 | } |
582 | { | 583 | |
583 | err("Couldn't allocate bulk_in_buffer"); | 584 | for (i = 0; i < num_bulk_out; ++i) { |
584 | goto probe_error; | 585 | endpoint = bulk_out_endpoint[i]; |
585 | } | 586 | port = &serial->port[i]; |
586 | usb_fill_bulk_urb (port->read_urb, dev, | 587 | port->write_urb = usb_alloc_urb(0, GFP_KERNEL); |
587 | usb_rcvbulkpipe (dev, | 588 | if (!port->write_urb) { |
588 | endpoint->bEndpointAddress), | 589 | err("No free urbs available"); |
589 | port->bulk_in_buffer, buffer_size, | 590 | goto probe_error; |
590 | qt_read_bulk_callback, | 591 | } |
591 | port); | 592 | buffer_size = endpoint->wMaxPacketSize; |
592 | } | 593 | port->bulk_out_size = buffer_size; |
593 | 594 | port->bulk_out_endpointAddress = endpoint->bEndpointAddress; | |
594 | for (i = 0; i < num_bulk_out; ++i) | 595 | port->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL); |
595 | { | 596 | if (!port->bulk_out_buffer) { |
596 | endpoint = bulk_out_endpoint[i]; | 597 | err("Couldn't allocate bulk_out_buffer"); |
597 | port = &serial->port[i]; | 598 | goto probe_error; |
598 | port->write_urb = usb_alloc_urb (0, GFP_KERNEL); | 599 | } |
599 | if (!port->write_urb) | 600 | usb_fill_bulk_urb(port->write_urb, dev, |
600 | { | 601 | usb_sndbulkpipe(dev, |
601 | err("No free urbs available"); | 602 | endpoint->bEndpointAddress), |
602 | goto probe_error; | 603 | port->bulk_out_buffer, buffer_size, |
603 | } | 604 | qt_write_bulk_callback, port); |
604 | buffer_size = endpoint->wMaxPacketSize; | 605 | |
605 | port->bulk_out_size = buffer_size; | 606 | } |
606 | port->bulk_out_endpointAddress = endpoint->bEndpointAddress; | 607 | |
607 | port->bulk_out_buffer = kmalloc (buffer_size, GFP_KERNEL); | 608 | //For us numb of bulkin or out = number of ports |
608 | if (!port->bulk_out_buffer) | 609 | |
609 | { | 610 | mydbg("%s - setting up %d port structures for this device\n", |
610 | err("Couldn't allocate bulk_out_buffer"); | 611 | __FUNCTION__, num_bulk_in); |
611 | goto probe_error; | 612 | for (i = 0; i < num_bulk_in; ++i) { |
612 | } | 613 | port = &serial->port[i]; |
613 | usb_fill_bulk_urb (port->write_urb, dev, | 614 | port->number = i + serial->minor; |
614 | usb_sndbulkpipe (dev, | 615 | port->serial = serial; |
615 | endpoint->bEndpointAddress), | 616 | |
616 | port->bulk_out_buffer, buffer_size, | 617 | INIT_WORK(&port->work, port_softint); |
617 | qt_write_bulk_callback, | 618 | |
618 | port); | 619 | init_MUTEX(&port->sem); |
619 | 620 | ||
620 | 621 | } | |
621 | } | 622 | status = box_get_device(serial, &DeviceData); |
622 | 623 | if (status < 0) { | |
623 | //For us numb of bulkin or out = number of ports | 624 | mydbg(__FILE__ "box_get_device failed"); |
624 | 625 | goto probe_error; | |
625 | mydbg("%s - setting up %d port structures for this device\n", __FUNCTION__, num_bulk_in); | 626 | } |
626 | for (i = 0; i < num_bulk_in; ++i) | 627 | |
627 | { | 628 | mydbg(__FILE__ "DeviceData.portb = 0x%x", DeviceData.portb); |
628 | port = &serial->port[i]; | 629 | |
629 | port->number = i + serial->minor; | 630 | DeviceData.portb &= ~FULLPWRBIT; |
630 | port->serial = serial; | 631 | mydbg(__FILE__ "Changing DeviceData.portb to 0x%x", DeviceData.portb); |
631 | 632 | ||
632 | INIT_WORK(&port->work, port_softint); | 633 | status = box_set_device(serial, &DeviceData); |
633 | 634 | if (status < 0) { | |
634 | init_MUTEX (&port->sem); | 635 | mydbg(__FILE__ "box_set_device failed\n"); |
635 | 636 | goto probe_error; | |
636 | 637 | } | |
637 | 638 | ||
638 | } | 639 | /* initialize the devfs nodes for this device and let the user know what ports we are bound to */ |
639 | status = box_get_device(serial, &DeviceData); | 640 | for (i = 0; i < serial->num_ports; ++i) { |
640 | if (status < 0) | 641 | dev_info(&interface->dev, |
641 | { | 642 | "Converter now attached to ttyUSB%d (or usb/tts/%d for devfs)", |
642 | mydbg(__FILE__"box_get_device failed"); | 643 | serial->port[i].number, serial->port[i].number); |
643 | goto probe_error; | 644 | } |
644 | } | ||
645 | |||
646 | mydbg(__FILE__"DeviceData.portb = 0x%x",DeviceData.portb); | ||
647 | |||
648 | DeviceData.portb &= ~FULLPWRBIT; | ||
649 | mydbg(__FILE__"Changing DeviceData.portb to 0x%x",DeviceData.portb); | ||
650 | |||
651 | status = box_set_device(serial, &DeviceData); | ||
652 | if (status < 0) | ||
653 | { | ||
654 | mydbg(__FILE__"box_set_device failed\n"); | ||
655 | goto probe_error; | ||
656 | } | ||
657 | |||
658 | |||
659 | |||
660 | /* initialize the devfs nodes for this device and let the user know what ports we are bound to */ | ||
661 | for (i = 0; i < serial->num_ports; ++i) | ||
662 | { | ||
663 | dev_info(&interface->dev, "Converter now attached to ttyUSB%d (or usb/tts/%d for devfs)", | ||
664 | serial->port[i].number, serial->port[i].number); | ||
665 | } | ||
666 | 645 | ||
667 | //usb_serial_console_init (debug, minor); | 646 | //usb_serial_console_init (debug, minor); |
668 | 647 | ||
669 | ///***********TAG add start next board here ****/// | 648 | ///***********TAG add start next board here ****/// |
670 | status = box_get_device(serial, &DeviceData); | 649 | status = box_get_device(serial, &DeviceData); |
671 | if (status < 0) | 650 | if (status < 0) { |
672 | { | 651 | mydbg(__FILE__ "box_get_device failed"); |
673 | mydbg(__FILE__"box_get_device failed"); | 652 | goto probe_error; |
674 | goto probe_error; | 653 | } |
675 | } | 654 | //*****************and before we power up lets initialiaze parnent device stuff here before |
676 | 655 | //*****************we set thmem via any other method such as the property pages | |
677 | //*****************and before we power up lets initialiaze parnent device stuff here before | 656 | switch (serial->product) { |
678 | //*****************we set thmem via any other method such as the property pages | 657 | case DEVICE_ID_QUATECH_RS232_SINGLE_PORT: |
679 | switch (serial->product) | 658 | case DEVICE_ID_QUATECH_RS232_DUAL_PORT: |
680 | { | 659 | case DEVICE_ID_QUATECH_RS232_FOUR_PORT: |
681 | case DEVICE_ID_QUATECH_RS232_SINGLE_PORT: | 660 | case DEVICE_ID_QUATECH_RS232_EIGHT_PORT_A: |
682 | case DEVICE_ID_QUATECH_RS232_DUAL_PORT: | 661 | case DEVICE_ID_QUATECH_RS232_EIGHT_PORT_B: |
683 | case DEVICE_ID_QUATECH_RS232_FOUR_PORT: | 662 | case DEVICE_ID_QUATECH_RS232_16_PORT_A: |
684 | case DEVICE_ID_QUATECH_RS232_EIGHT_PORT_A: | 663 | case DEVICE_ID_QUATECH_RS232_16_PORT_B: |
685 | case DEVICE_ID_QUATECH_RS232_EIGHT_PORT_B: | 664 | case DEVICE_ID_QUATECH_RS232_16_PORT_C: |
686 | case DEVICE_ID_QUATECH_RS232_16_PORT_A: | 665 | case DEVICE_ID_QUATECH_RS232_16_PORT_D: |
687 | case DEVICE_ID_QUATECH_RS232_16_PORT_B: | 666 | DeviceData.porta &= ~(RR_BITS | DUPMODE_BITS); |
688 | case DEVICE_ID_QUATECH_RS232_16_PORT_C: | 667 | DeviceData.porta |= CLKS_X4; |
689 | case DEVICE_ID_QUATECH_RS232_16_PORT_D: | 668 | DeviceData.portb &= ~(LOOPMODE_BITS); |
690 | DeviceData.porta &= ~(RR_BITS | DUPMODE_BITS); | 669 | DeviceData.portb |= RS232_MODE; |
691 | DeviceData.porta |= CLKS_X4; | 670 | break; |
692 | DeviceData.portb &= ~(LOOPMODE_BITS); | 671 | |
693 | DeviceData.portb |= RS232_MODE; | 672 | case DEVICE_ID_QUATECH_RS422_SINGLE_PORT: |
694 | break; | 673 | case DEVICE_ID_QUATECH_RS422_DUAL_PORT: |
695 | 674 | case DEVICE_ID_QUATECH_RS422_FOUR_PORT: | |
696 | 675 | case DEVICE_ID_QUATECH_RS422_EIGHT_PORT_A: | |
697 | case DEVICE_ID_QUATECH_RS422_SINGLE_PORT: | 676 | case DEVICE_ID_QUATECH_RS422_EIGHT_PORT_B: |
698 | case DEVICE_ID_QUATECH_RS422_DUAL_PORT: | 677 | case DEVICE_ID_QUATECH_RS422_16_PORT_A: |
699 | case DEVICE_ID_QUATECH_RS422_FOUR_PORT: | 678 | case DEVICE_ID_QUATECH_RS422_16_PORT_B: |
700 | case DEVICE_ID_QUATECH_RS422_EIGHT_PORT_A: | 679 | case DEVICE_ID_QUATECH_RS422_16_PORT_C: |
701 | case DEVICE_ID_QUATECH_RS422_EIGHT_PORT_B: | 680 | case DEVICE_ID_QUATECH_RS422_16_PORT_D: |
702 | case DEVICE_ID_QUATECH_RS422_16_PORT_A: | 681 | DeviceData.porta &= ~(RR_BITS | DUPMODE_BITS); |
703 | case DEVICE_ID_QUATECH_RS422_16_PORT_B: | 682 | DeviceData.porta |= CLKS_X4; |
704 | case DEVICE_ID_QUATECH_RS422_16_PORT_C: | 683 | DeviceData.portb &= ~(LOOPMODE_BITS); |
705 | case DEVICE_ID_QUATECH_RS422_16_PORT_D: | 684 | DeviceData.portb |= ALL_LOOPBACK; |
706 | DeviceData.porta &= ~(RR_BITS | DUPMODE_BITS); | 685 | break; |
707 | DeviceData.porta |= CLKS_X4; | 686 | default: |
708 | DeviceData.portb &= ~(LOOPMODE_BITS); | 687 | DeviceData.porta &= ~(RR_BITS | DUPMODE_BITS); |
709 | DeviceData.portb |= ALL_LOOPBACK; | 688 | DeviceData.porta |= CLKS_X4; |
710 | break; | 689 | DeviceData.portb &= ~(LOOPMODE_BITS); |
711 | default: | 690 | DeviceData.portb |= RS232_MODE; |
712 | DeviceData.porta &= ~(RR_BITS | DUPMODE_BITS); | 691 | break; |
713 | DeviceData.porta |= CLKS_X4; | ||
714 | DeviceData.portb &= ~(LOOPMODE_BITS); | ||
715 | DeviceData.portb |= RS232_MODE; | ||
716 | break; | ||
717 | |||
718 | } | ||
719 | status = BoxSetPrebufferLevel(serial); //sets to default vaue | ||
720 | if (status < 0) | ||
721 | { | ||
722 | mydbg(__FILE__"BoxSetPrebufferLevel failed\n"); | ||
723 | goto probe_error; | ||
724 | } | ||
725 | |||
726 | status = BoxSetATC(serial, ATC_DISABLED); | ||
727 | if (status < 0) | ||
728 | { | ||
729 | mydbg(__FILE__"BoxSetATC failed\n"); | ||
730 | goto probe_error; | ||
731 | } | ||
732 | //**************************************************************************** | ||
733 | mydbg(__FILE__"DeviceData.portb = 0x%x",DeviceData.portb); | ||
734 | |||
735 | DeviceData.portb |= NEXT_BOARD_POWER_BIT; | ||
736 | mydbg(__FILE__"Changing DeviceData.portb to 0x%x",DeviceData.portb); | ||
737 | |||
738 | status = box_set_device(serial, &DeviceData); | ||
739 | if (status < 0) | ||
740 | { | ||
741 | mydbg(__FILE__"box_set_device failed\n"); | ||
742 | goto probe_error; | ||
743 | } | ||
744 | |||
745 | |||
746 | mydbg("Exit Success %s\n", __FUNCTION__); | ||
747 | |||
748 | usb_set_intfdata (interface, serial); | ||
749 | return 0; | ||
750 | 692 | ||
693 | } | ||
694 | status = BoxSetPrebufferLevel(serial); //sets to default vaue | ||
695 | if (status < 0) { | ||
696 | mydbg(__FILE__ "BoxSetPrebufferLevel failed\n"); | ||
697 | goto probe_error; | ||
698 | } | ||
751 | 699 | ||
700 | status = BoxSetATC(serial, ATC_DISABLED); | ||
701 | if (status < 0) { | ||
702 | mydbg(__FILE__ "BoxSetATC failed\n"); | ||
703 | goto probe_error; | ||
704 | } | ||
705 | //**************************************************************************** | ||
706 | mydbg(__FILE__ "DeviceData.portb = 0x%x", DeviceData.portb); | ||
752 | 707 | ||
753 | probe_error: | 708 | DeviceData.portb |= NEXT_BOARD_POWER_BIT; |
754 | 709 | mydbg(__FILE__ "Changing DeviceData.portb to 0x%x", DeviceData.portb); | |
755 | for (i = 0; i < num_bulk_in; ++i) | 710 | |
756 | { | 711 | status = box_set_device(serial, &DeviceData); |
757 | port = &serial->port[i]; | 712 | if (status < 0) { |
758 | if (port->read_urb) | 713 | mydbg(__FILE__ "box_set_device failed\n"); |
759 | usb_free_urb (port->read_urb); | 714 | goto probe_error; |
760 | if (port->bulk_in_buffer) | 715 | } |
761 | kfree (port->bulk_in_buffer); | ||
762 | } | ||
763 | for (i = 0; i < num_bulk_out; ++i) | ||
764 | { | ||
765 | port = &serial->port[i]; | ||
766 | if (port->write_urb) | ||
767 | usb_free_urb (port->write_urb); | ||
768 | if (port->bulk_out_buffer) | ||
769 | kfree (port->bulk_out_buffer); | ||
770 | |||
771 | if (port->xfer_to_tty_buffer) | ||
772 | kfree (port->xfer_to_tty_buffer); | ||
773 | } | ||
774 | for (i = 0; i < num_interrupt_in; ++i) | ||
775 | { | ||
776 | port = &serial->port[i]; | ||
777 | if (port->interrupt_in_urb) | ||
778 | usb_free_urb (port->interrupt_in_urb); | ||
779 | if (port->interrupt_in_buffer) | ||
780 | kfree (port->interrupt_in_buffer); | ||
781 | } | ||
782 | |||
783 | |||
784 | /* return the minor range that this device had */ | ||
785 | return_serial (serial); | ||
786 | mydbg("Exit fail %s\n", __FUNCTION__); | ||
787 | |||
788 | /* free up any memory that we allocated */ | ||
789 | kfree (serial); | ||
790 | return -EIO; | ||
791 | } | ||
792 | 716 | ||
717 | mydbg("Exit Success %s\n", __FUNCTION__); | ||
793 | 718 | ||
719 | usb_set_intfdata(interface, serial); | ||
720 | return 0; | ||
794 | 721 | ||
722 | probe_error: | ||
723 | |||
724 | for (i = 0; i < num_bulk_in; ++i) { | ||
725 | port = &serial->port[i]; | ||
726 | if (port->read_urb) | ||
727 | usb_free_urb(port->read_urb); | ||
728 | if (port->bulk_in_buffer) | ||
729 | kfree(port->bulk_in_buffer); | ||
730 | } | ||
731 | for (i = 0; i < num_bulk_out; ++i) { | ||
732 | port = &serial->port[i]; | ||
733 | if (port->write_urb) | ||
734 | usb_free_urb(port->write_urb); | ||
735 | if (port->bulk_out_buffer) | ||
736 | kfree(port->bulk_out_buffer); | ||
737 | |||
738 | if (port->xfer_to_tty_buffer) | ||
739 | kfree(port->xfer_to_tty_buffer); | ||
740 | } | ||
741 | for (i = 0; i < num_interrupt_in; ++i) { | ||
742 | port = &serial->port[i]; | ||
743 | if (port->interrupt_in_urb) | ||
744 | usb_free_urb(port->interrupt_in_urb); | ||
745 | if (port->interrupt_in_buffer) | ||
746 | kfree(port->interrupt_in_buffer); | ||
747 | } | ||
795 | 748 | ||
749 | /* return the minor range that this device had */ | ||
750 | return_serial(serial); | ||
751 | mydbg("Exit fail %s\n", __FUNCTION__); | ||
796 | 752 | ||
753 | /* free up any memory that we allocated */ | ||
754 | kfree(serial); | ||
755 | return -EIO; | ||
756 | } | ||
797 | 757 | ||
798 | //returns the serial_table array pointers that are taken | 758 | //returns the serial_table array pointers that are taken |
799 | //up in consecutive positions for each port to a common usb_serial structure | 759 | //up in consecutive positions for each port to a common usb_serial structure |
800 | //back to NULL | 760 | //back to NULL |
801 | static void return_serial(struct usb_serial *serial) | 761 | static void return_serial(struct usb_serial *serial) |
802 | { | 762 | { |
803 | int i; | 763 | int i; |
804 | 764 | ||
805 | mydbg("%s\n", __FUNCTION__); | 765 | mydbg("%s\n", __FUNCTION__); |
806 | 766 | ||
807 | if (serial == NULL) | 767 | if (serial == NULL) |
808 | return; | 768 | return; |
809 | 769 | ||
810 | for (i = 0; i < serial->num_ports; ++i) | 770 | for (i = 0; i < serial->num_ports; ++i) { |
811 | { | 771 | serial_table[serial->minor + i] = NULL; |
812 | serial_table[serial->minor + i] = NULL; | 772 | } |
813 | } | ||
814 | 773 | ||
815 | return; | 774 | return; |
816 | } | 775 | } |
817 | 776 | ||
818 | //Finds the first locatio int the serial_table array where it can fit | 777 | //Finds the first locatio int the serial_table array where it can fit |
@@ -820,808 +779,748 @@ static void return_serial(struct usb_serial *serial) | |||
820 | //,allocates a stucture points to it in all the structures, and returns the index | 779 | //,allocates a stucture points to it in all the structures, and returns the index |
821 | //to the first location in the array in the "minor" variable. | 780 | //to the first location in the array in the "minor" variable. |
822 | 781 | ||
823 | static struct usb_serial *get_free_serial (int num_ports, int *minor) | 782 | static struct usb_serial *get_free_serial(int num_ports, int *minor) |
824 | { | 783 | { |
825 | struct usb_serial *serial = NULL; | 784 | struct usb_serial *serial = NULL; |
826 | int i, j; | 785 | int i, j; |
827 | int good_spot; | 786 | int good_spot; |
828 | 787 | ||
829 | mydbg("%s %d\n", __FUNCTION__, num_ports); | 788 | mydbg("%s %d\n", __FUNCTION__, num_ports); |
830 | 789 | ||
831 | *minor = 0; | 790 | *minor = 0; |
832 | for (i = 0; i < SERIAL_TTY_MINORS; ++i) | 791 | for (i = 0; i < SERIAL_TTY_MINORS; ++i) { |
833 | { | 792 | if (serial_table[i]) |
834 | if (serial_table[i]) | 793 | continue; |
835 | continue; | 794 | |
836 | 795 | good_spot = 1; | |
837 | good_spot = 1; | 796 | //find a spot in the array where you can fit consecutive positions |
838 | //find a spot in the array where you can fit consecutive positions | 797 | //to put the pointers to the usb_serail allocated structure for all |
839 | //to put the pointers to the usb_serail allocated structure for all | 798 | //the minor numbers (ie. ports) |
840 | //the minor numbers (ie. ports) | 799 | for (j = 1; j <= num_ports - 1; ++j) |
841 | for (j = 1; j <= num_ports-1; ++j) | 800 | if (serial_table[i + j]) |
842 | if (serial_table[i+j]) | 801 | good_spot = 0; |
843 | good_spot = 0; | 802 | if (good_spot == 0) |
844 | if (good_spot == 0) | 803 | continue; |
845 | continue; | 804 | |
846 | 805 | if (!(serial = kmalloc(sizeof(struct usb_serial), GFP_KERNEL))) { | |
847 | if (!(serial = kmalloc(sizeof(struct usb_serial), GFP_KERNEL))) | 806 | err("%s - Out of memory", __FUNCTION__); |
848 | { | 807 | return NULL; |
849 | err("%s - Out of memory", __FUNCTION__); | 808 | } |
850 | return NULL; | 809 | memset(serial, 0, sizeof(struct usb_serial)); |
851 | } | 810 | serial_table[i] = serial; |
852 | memset(serial, 0, sizeof(struct usb_serial)); | 811 | *minor = i; |
853 | serial_table[i] = serial; | 812 | mydbg("%s - minor base = %d\n", __FUNCTION__, *minor); |
854 | *minor = i; | 813 | //copy in the pointer into the array starting a the *minor position |
855 | mydbg("%s - minor base = %d\n", __FUNCTION__, *minor); | 814 | //*minor is the index into the array |
856 | //copy in the pointer into the array starting a the *minor position | 815 | for (i = *minor + 1; |
857 | //*minor is the index into the array | 816 | (i < (*minor + num_ports)) && (i < SERIAL_TTY_MINORS); ++i) |
858 | for (i = *minor+1; (i < (*minor + num_ports)) && (i < SERIAL_TTY_MINORS); ++i) | 817 | serial_table[i] = serial; |
859 | serial_table[i] = serial; | 818 | return serial; |
860 | return serial; | 819 | } |
861 | } | 820 | return NULL; |
862 | return NULL; | ||
863 | } | 821 | } |
864 | 822 | ||
865 | static int flip_that( struct tty_struct *tty, __u16 UartNumber, struct usb_serial *serial) | 823 | static int flip_that(struct tty_struct *tty, __u16 UartNumber, |
824 | struct usb_serial *serial) | ||
866 | { | 825 | { |
867 | tty_flip_buffer_push(tty); | 826 | tty_flip_buffer_push(tty); |
868 | tty_schedule_flip(tty); | 827 | tty_schedule_flip(tty); |
869 | return 0; | 828 | return 0; |
870 | } | 829 | } |
871 | 830 | ||
872 | //Handles processing and moving data to the tty layer | 831 | //Handles processing and moving data to the tty layer |
873 | static void port_sofrint(void *private) | 832 | static void port_sofrint(void *private) |
874 | { | 833 | { |
875 | struct usb_serial_port *port = (struct usb_serial_port *)private; | 834 | struct usb_serial_port *port = (struct usb_serial_port *)private; |
876 | struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); | 835 | struct usb_serial *serial = get_usb_serial(port, __FUNCTION__); |
877 | struct tty_struct *tty = port->tty; | 836 | struct tty_struct *tty = port->tty; |
878 | unsigned char *data = port->read_urb->transfer_buffer; | 837 | unsigned char *data = port->read_urb->transfer_buffer; |
879 | unsigned int UartNumber; | 838 | unsigned int UartNumber; |
880 | struct urb *urb = port->read_urb; | 839 | struct urb *urb = port->read_urb; |
881 | unsigned int RxCount = urb->actual_length; | 840 | unsigned int RxCount = urb->actual_length; |
882 | int i, result; | 841 | int i, result; |
883 | int flag, flag_data; | 842 | int flag, flag_data; |
884 | |||
885 | //UartNumber = MINOR(port->tty->device) - serial->minor; | ||
886 | UartNumber = tty->index - serial->minor; | ||
887 | |||
888 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | ||
889 | mydbg ("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding); | ||
890 | |||
891 | if (port_paranoia_check (port, __FUNCTION__) != 0) { | ||
892 | mydbg("%s - port_paranoia_check, exiting\n", __FUNCTION__); | ||
893 | port->ReadBulkStopped = 1; | ||
894 | return; | ||
895 | } | ||
896 | |||
897 | if (!serial) { | ||
898 | mydbg("%s - bad serial pointer, exiting\n", __FUNCTION__); | ||
899 | return; | ||
900 | } | ||
901 | if (port->closePending == 1) //Were closing , stop reading | ||
902 | { | ||
903 | mydbg("%s - (port->closepending == 1\n", __FUNCTION__); | ||
904 | port->ReadBulkStopped = 1; | ||
905 | return; | ||
906 | } | ||
907 | |||
908 | //RxHolding is asserted by throttle, if we assert it, we're not receiving any more | ||
909 | //characters and let the box handle the flow control | ||
910 | if (port->RxHolding == 1) { | ||
911 | port->ReadBulkStopped = 1; | ||
912 | return; | ||
913 | } | ||
914 | |||
915 | if (urb->status) { | ||
916 | port->ReadBulkStopped = 1; | ||
917 | |||
918 | mydbg("%s - nonzero read bulk status received: %d\n", __FUNCTION__, urb->status); | ||
919 | return; | ||
920 | } | ||
921 | |||
922 | |||
923 | tty = port->tty; | ||
924 | mydbg("%s - port %d, tty =0x%p\n", __FUNCTION__, port->number, tty); | ||
925 | |||
926 | |||
927 | if (tty && RxCount) { | ||
928 | flag_data = 0; | ||
929 | for (i = 0; i < RxCount ; ++i) { | ||
930 | //Look ahead code here | ||
931 | |||
932 | if ((i <= (RxCount - 3)) && (THISCHAR == 0x1b) && (NEXTCHAR == 0x1b)) { | ||
933 | flag = 0; | ||
934 | switch (THIRDCHAR) { | ||
935 | case 0x00: | ||
936 | //Line status change 4th byte must follow | ||
937 | if (i > (RxCount - 4)) { | ||
938 | mydbg("Illegal escape sequences in received data\n"); | ||
939 | break; | ||
940 | } | ||
941 | ProcessLineStatus(port, FOURTHCHAR); | ||
942 | i += 3; | ||
943 | flag = 1; | ||
944 | break; | ||
945 | |||
946 | case 0x01: | ||
947 | //Modem status status change 4th byte must follow | ||
948 | mydbg("Modem status status. \n"); | ||
949 | |||
950 | if (i > (RxCount - 4)) { | ||
951 | mydbg("Illegal escape sequences in received data\n"); | ||
952 | break; | ||
953 | } | ||
954 | ProcessModemStatus(port, FOURTHCHAR); | ||
955 | i += 3; | ||
956 | flag = 1; | ||
957 | break; | ||
958 | case 0xff: | ||
959 | mydbg("No status sequence. \n"); | ||
960 | |||
961 | ProcessRxChar(port, THISCHAR); | ||
962 | ProcessRxChar(port, NEXTCHAR); | ||
963 | i += 2; | ||
964 | break; | ||
965 | |||
966 | }//end switch | ||
967 | if (flag == 1) | ||
968 | continue; | ||
969 | } //endif | ||
970 | |||
971 | if(tty && urb->actual_length) { | ||
972 | tty_buffer_request_room(tty, 1); | ||
973 | tty_insert_flip_string(tty, (data + i), 1); | ||
974 | } | ||
975 | |||
976 | 843 | ||
977 | }//endfor | 844 | //UartNumber = MINOR(port->tty->device) - serial->minor; |
845 | UartNumber = tty->index - serial->minor; | ||
978 | 846 | ||
979 | tty_flip_buffer_push(tty); | 847 | mydbg("%s - port %d\n", __FUNCTION__, port->number); |
848 | mydbg("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding); | ||
980 | 849 | ||
981 | }//endif | 850 | if (port_paranoia_check(port, __FUNCTION__) != 0) { |
851 | mydbg("%s - port_paranoia_check, exiting\n", __FUNCTION__); | ||
852 | port->ReadBulkStopped = 1; | ||
853 | return; | ||
854 | } | ||
982 | 855 | ||
983 | /* Continue trying to always read */ | 856 | if (!serial) { |
984 | usb_fill_bulk_urb (port->read_urb, serial->dev, | 857 | mydbg("%s - bad serial pointer, exiting\n", __FUNCTION__); |
985 | usb_rcvbulkpipe (serial->dev, | 858 | return; |
986 | port->bulk_in_endpointAddress), | 859 | } |
987 | port->read_urb->transfer_buffer, | 860 | if (port->closePending == 1) //Were closing , stop reading |
988 | port->read_urb->transfer_buffer_length, | 861 | { |
989 | qt_read_bulk_callback, port); | 862 | mydbg("%s - (port->closepending == 1\n", __FUNCTION__); |
990 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); | 863 | port->ReadBulkStopped = 1; |
991 | if (result) | 864 | return; |
992 | mydbg("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); | 865 | } |
993 | else | 866 | //RxHolding is asserted by throttle, if we assert it, we're not receiving any more |
994 | { | 867 | //characters and let the box handle the flow control |
995 | if (tty && RxCount) | 868 | if (port->RxHolding == 1) { |
996 | flip_that(tty, UartNumber, serial); | 869 | port->ReadBulkStopped = 1; |
997 | } | 870 | return; |
871 | } | ||
998 | 872 | ||
873 | if (urb->status) { | ||
874 | port->ReadBulkStopped = 1; | ||
999 | 875 | ||
1000 | return; | 876 | mydbg("%s - nonzero read bulk status received: %d\n", |
877 | __FUNCTION__, urb->status); | ||
878 | return; | ||
879 | } | ||
1001 | 880 | ||
1002 | } | 881 | tty = port->tty; |
882 | mydbg("%s - port %d, tty =0x%p\n", __FUNCTION__, port->number, tty); | ||
883 | |||
884 | if (tty && RxCount) { | ||
885 | flag_data = 0; | ||
886 | for (i = 0; i < RxCount; ++i) { | ||
887 | //Look ahead code here | ||
888 | |||
889 | if ((i <= (RxCount - 3)) && (THISCHAR == 0x1b) | ||
890 | && (NEXTCHAR == 0x1b)) { | ||
891 | flag = 0; | ||
892 | switch (THIRDCHAR) { | ||
893 | case 0x00: | ||
894 | //Line status change 4th byte must follow | ||
895 | if (i > (RxCount - 4)) { | ||
896 | mydbg | ||
897 | ("Illegal escape sequences in received data\n"); | ||
898 | break; | ||
899 | } | ||
900 | ProcessLineStatus(port, FOURTHCHAR); | ||
901 | i += 3; | ||
902 | flag = 1; | ||
903 | break; | ||
904 | |||
905 | case 0x01: | ||
906 | //Modem status status change 4th byte must follow | ||
907 | mydbg("Modem status status. \n"); | ||
908 | |||
909 | if (i > (RxCount - 4)) { | ||
910 | mydbg | ||
911 | ("Illegal escape sequences in received data\n"); | ||
912 | break; | ||
913 | } | ||
914 | ProcessModemStatus(port, FOURTHCHAR); | ||
915 | i += 3; | ||
916 | flag = 1; | ||
917 | break; | ||
918 | case 0xff: | ||
919 | mydbg("No status sequence. \n"); | ||
920 | |||
921 | ProcessRxChar(port, THISCHAR); | ||
922 | ProcessRxChar(port, NEXTCHAR); | ||
923 | i += 2; | ||
924 | break; | ||
925 | |||
926 | } //end switch | ||
927 | if (flag == 1) | ||
928 | continue; | ||
929 | } //endif | ||
930 | |||
931 | if (tty && urb->actual_length) { | ||
932 | tty_buffer_request_room(tty, 1); | ||
933 | tty_insert_flip_string(tty, (data + i), 1); | ||
934 | } | ||
935 | |||
936 | } //endfor | ||
937 | |||
938 | tty_flip_buffer_push(tty); | ||
939 | |||
940 | } //endif | ||
941 | |||
942 | /* Continue trying to always read */ | ||
943 | usb_fill_bulk_urb(port->read_urb, serial->dev, | ||
944 | usb_rcvbulkpipe(serial->dev, | ||
945 | port->bulk_in_endpointAddress), | ||
946 | port->read_urb->transfer_buffer, | ||
947 | port->read_urb->transfer_buffer_length, | ||
948 | qt_read_bulk_callback, port); | ||
949 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); | ||
950 | if (result) | ||
951 | mydbg("%s - failed resubmitting read urb, error %d", | ||
952 | __FUNCTION__, result); | ||
953 | else { | ||
954 | if (tty && RxCount) | ||
955 | flip_that(tty, UartNumber, serial); | ||
956 | } | ||
1003 | 957 | ||
958 | return; | ||
1004 | 959 | ||
960 | } | ||
1005 | 961 | ||
1006 | static void qt_read_bulk_callback(struct urb *urb) | 962 | static void qt_read_bulk_callback(struct urb *urb) |
1007 | { | 963 | { |
1008 | 964 | ||
1009 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; | 965 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; |
1010 | 966 | ||
967 | if (urb->status) { | ||
1011 | 968 | ||
1012 | if (urb->status) | 969 | port->ReadBulkStopped = 1; |
1013 | { | 970 | mydbg("%s - nonzero write bulk status received: %d\n", |
1014 | 971 | __FUNCTION__, urb->status); | |
1015 | port->ReadBulkStopped = 1; | 972 | return; |
1016 | mydbg("%s - nonzero write bulk status received: %d\n", __FUNCTION__, urb->status); | 973 | } |
1017 | return; | ||
1018 | } | ||
1019 | 974 | ||
1020 | port_sofrint((void *) port); | 975 | port_sofrint((void *)port); |
1021 | schedule_work(&port->work); | 976 | schedule_work(&port->work); |
1022 | } | 977 | } |
1023 | 978 | ||
979 | static void ProcessRxChar(struct usb_serial_port *port, unsigned char Data) | ||
980 | { | ||
981 | struct tty_struct *tty; | ||
982 | struct urb *urb = port->read_urb; | ||
983 | tty = port->tty; | ||
984 | /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */ | ||
1024 | 985 | ||
1025 | static void ProcessRxChar(struct usb_serial_port *port, unsigned char Data){ | 986 | if (tty && urb->actual_length) { |
1026 | struct tty_struct *tty; | ||
1027 | struct urb *urb = port->read_urb; | ||
1028 | tty = port->tty; | ||
1029 | /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */ | ||
1030 | |||
1031 | if(tty && urb->actual_length) | ||
1032 | { | ||
1033 | tty_buffer_request_room(tty, 1); | 987 | tty_buffer_request_room(tty, 1); |
1034 | tty_insert_flip_string(tty, &Data, 1); | 988 | tty_insert_flip_string(tty, &Data, 1); |
1035 | //tty_flip_buffer_push(tty); | 989 | //tty_flip_buffer_push(tty); |
1036 | 990 | ||
1037 | |||
1038 | } | 991 | } |
1039 | 992 | ||
1040 | return; | 993 | return; |
1041 | } | 994 | } |
1042 | 995 | ||
1043 | static void ProcessLineStatus(struct usb_serial_port *port, unsigned char line_status){ | 996 | static void ProcessLineStatus(struct usb_serial_port *port, |
997 | unsigned char line_status) | ||
998 | { | ||
1044 | 999 | ||
1045 | port->shadowLSR = line_status & (SERIAL_LSR_OE | SERIAL_LSR_PE | SERIAL_LSR_FE | | 1000 | port->shadowLSR = |
1046 | SERIAL_LSR_BI); | 1001 | line_status & (SERIAL_LSR_OE | SERIAL_LSR_PE | SERIAL_LSR_FE | |
1047 | return; | 1002 | SERIAL_LSR_BI); |
1003 | return; | ||
1048 | } | 1004 | } |
1049 | 1005 | ||
1006 | static void ProcessModemStatus(struct usb_serial_port *port, | ||
1007 | unsigned char modem_status) | ||
1008 | { | ||
1050 | 1009 | ||
1051 | static void ProcessModemStatus(struct usb_serial_port *port, unsigned char modem_status){ | 1010 | port->shadowMSR = modem_status; |
1052 | 1011 | wake_up_interruptible(&port->wait); | |
1053 | port->shadowMSR = modem_status; | 1012 | return; |
1054 | wake_up_interruptible(&port->wait); | ||
1055 | return; | ||
1056 | } | 1013 | } |
1057 | 1014 | ||
1015 | static void serqt_usb_disconnect(struct usb_interface *interface) | ||
1016 | { | ||
1017 | struct usb_serial *serial = usb_get_intfdata(interface); | ||
1018 | //struct device *dev = &interface->dev; | ||
1019 | struct usb_serial_port *port; | ||
1020 | int i; | ||
1058 | 1021 | ||
1022 | mydbg("%s\n", __FUNCTION__); | ||
1023 | if (serial) { | ||
1059 | 1024 | ||
1025 | serial->dev = NULL; | ||
1060 | 1026 | ||
1027 | for (i = 0; i < serial->num_ports; ++i) | ||
1028 | serial->port[i].open_count = 0; | ||
1061 | 1029 | ||
1030 | for (i = 0; i < serial->num_bulk_in; ++i) { | ||
1031 | port = &serial->port[i]; | ||
1032 | if (port->read_urb) { | ||
1033 | usb_unlink_urb(port->read_urb); | ||
1034 | usb_free_urb(port->read_urb); | ||
1035 | } | ||
1036 | if (port->bulk_in_buffer) | ||
1037 | kfree(port->bulk_in_buffer); | ||
1038 | } | ||
1039 | for (i = 0; i < serial->num_bulk_out; ++i) { | ||
1040 | port = &serial->port[i]; | ||
1041 | if (port->write_urb) { | ||
1042 | usb_unlink_urb(port->write_urb); | ||
1043 | usb_free_urb(port->write_urb); | ||
1044 | } | ||
1045 | if (port->bulk_out_buffer) | ||
1046 | kfree(port->bulk_out_buffer); | ||
1047 | } | ||
1048 | for (i = 0; i < serial->num_interrupt_in; ++i) { | ||
1049 | port = &serial->port[i]; | ||
1050 | if (port->interrupt_in_urb) { | ||
1051 | usb_unlink_urb(port->interrupt_in_urb); | ||
1052 | usb_free_urb(port->interrupt_in_urb); | ||
1053 | } | ||
1054 | if (port->interrupt_in_buffer) | ||
1055 | kfree(port->interrupt_in_buffer); | ||
1056 | } | ||
1062 | 1057 | ||
1063 | static void serqt_usb_disconnect(struct usb_interface *interface){ | 1058 | /* return the minor range that this device had */ |
1064 | struct usb_serial *serial = usb_get_intfdata (interface); | 1059 | return_serial(serial); |
1065 | //struct device *dev = &interface->dev; | ||
1066 | struct usb_serial_port *port; | ||
1067 | int i; | ||
1068 | |||
1069 | mydbg ("%s\n", __FUNCTION__); | ||
1070 | if (serial) | ||
1071 | { | ||
1072 | |||
1073 | serial->dev = NULL; | ||
1074 | |||
1075 | for (i = 0; i < serial->num_ports; ++i) | ||
1076 | serial->port[i].open_count = 0; | ||
1077 | |||
1078 | for (i = 0; i < serial->num_bulk_in; ++i) | ||
1079 | { | ||
1080 | port = &serial->port[i]; | ||
1081 | if (port->read_urb) | ||
1082 | { | ||
1083 | usb_unlink_urb (port->read_urb); | ||
1084 | usb_free_urb (port->read_urb); | ||
1085 | } | ||
1086 | if (port->bulk_in_buffer) | ||
1087 | kfree (port->bulk_in_buffer); | ||
1088 | } | ||
1089 | for (i = 0; i < serial->num_bulk_out; ++i) | ||
1090 | { | ||
1091 | port = &serial->port[i]; | ||
1092 | if (port->write_urb) | ||
1093 | { | ||
1094 | usb_unlink_urb (port->write_urb); | ||
1095 | usb_free_urb (port->write_urb); | ||
1096 | } | ||
1097 | if (port->bulk_out_buffer) | ||
1098 | kfree (port->bulk_out_buffer); | ||
1099 | } | ||
1100 | for (i = 0; i < serial->num_interrupt_in; ++i) | ||
1101 | { | ||
1102 | port = &serial->port[i]; | ||
1103 | if (port->interrupt_in_urb) | ||
1104 | { | ||
1105 | usb_unlink_urb (port->interrupt_in_urb); | ||
1106 | usb_free_urb (port->interrupt_in_urb); | ||
1107 | } | ||
1108 | if (port->interrupt_in_buffer) | ||
1109 | kfree (port->interrupt_in_buffer); | ||
1110 | } | ||
1111 | |||
1112 | |||
1113 | /* return the minor range that this device had */ | ||
1114 | return_serial (serial); | ||
1115 | |||
1116 | /* free up any memory that we allocated */ | ||
1117 | kfree (serial); | ||
1118 | |||
1119 | |||
1120 | 1060 | ||
1121 | } else | 1061 | /* free up any memory that we allocated */ |
1122 | { | 1062 | kfree(serial); |
1123 | dev_info(&interface->dev, "device disconnected"); | ||
1124 | } | ||
1125 | 1063 | ||
1064 | } else { | ||
1065 | dev_info(&interface->dev, "device disconnected"); | ||
1066 | } | ||
1126 | 1067 | ||
1127 | } | 1068 | } |
1128 | 1069 | ||
1129 | 1070 | static struct usb_serial *get_serial_by_minor(unsigned int minor) | |
1130 | |||
1131 | |||
1132 | |||
1133 | |||
1134 | |||
1135 | static struct usb_serial *get_serial_by_minor (unsigned int minor) | ||
1136 | { | 1071 | { |
1137 | return serial_table[minor]; | 1072 | return serial_table[minor]; |
1138 | } | 1073 | } |
1139 | 1074 | ||
1140 | /***************************************************************************** | 1075 | /***************************************************************************** |
1141 | * Driver tty interface functions | 1076 | * Driver tty interface functions |
1142 | *****************************************************************************/ | 1077 | *****************************************************************************/ |
1143 | static int serial_open (struct tty_struct *tty, struct file * filp){ | 1078 | static int serial_open(struct tty_struct *tty, struct file *filp) |
1144 | struct usb_serial *serial; | 1079 | { |
1145 | struct usb_serial_port *port; | 1080 | struct usb_serial *serial; |
1146 | unsigned int portNumber; | 1081 | struct usb_serial_port *port; |
1147 | int retval = 0; | 1082 | unsigned int portNumber; |
1083 | int retval = 0; | ||
1148 | 1084 | ||
1149 | mydbg("%s\n", __FUNCTION__); | 1085 | mydbg("%s\n", __FUNCTION__); |
1150 | 1086 | ||
1151 | /* initialize the pointer incase something fails */ | 1087 | /* initialize the pointer incase something fails */ |
1152 | tty->driver_data = NULL; | 1088 | tty->driver_data = NULL; |
1153 | 1089 | ||
1154 | /* get the serial object associated with this tty pointer */ | 1090 | /* get the serial object associated with this tty pointer */ |
1155 | //serial = get_serial_by_minor (MINOR(tty->device)); | 1091 | //serial = get_serial_by_minor (MINOR(tty->device)); |
1156 | 1092 | ||
1157 | /* get the serial object associated with this tty pointer */ | 1093 | /* get the serial object associated with this tty pointer */ |
1158 | serial = get_serial_by_minor(tty->index); | 1094 | serial = get_serial_by_minor(tty->index); |
1159 | 1095 | ||
1096 | if (serial_paranoia_check(serial, __FUNCTION__)) | ||
1097 | return -ENODEV; | ||
1160 | 1098 | ||
1161 | if (serial_paranoia_check (serial, __FUNCTION__)) | 1099 | /* set up our port structure making the tty driver remember our port object, and us it */ |
1162 | return -ENODEV; | 1100 | portNumber = tty->index - serial->minor; |
1163 | 1101 | port = &serial->port[portNumber]; | |
1164 | 1102 | tty->driver_data = port; | |
1165 | /* set up our port structure making the tty driver remember our port object, and us it */ | ||
1166 | portNumber = tty->index - serial->minor; | ||
1167 | port = &serial->port[portNumber]; | ||
1168 | tty->driver_data = port; | ||
1169 | |||
1170 | down (&port->sem); | ||
1171 | port->tty = tty; | ||
1172 | 1103 | ||
1104 | down(&port->sem); | ||
1105 | port->tty = tty; | ||
1173 | 1106 | ||
1174 | ++port->open_count; | 1107 | ++port->open_count; |
1175 | if (port->open_count == 1) | 1108 | if (port->open_count == 1) { |
1176 | { | 1109 | port->closePending = 0; |
1177 | port->closePending = 0; | 1110 | mydbg("%s port->closepending = 0\n", __FUNCTION__); |
1178 | mydbg("%s port->closepending = 0\n", __FUNCTION__); | ||
1179 | 1111 | ||
1180 | port->RxHolding = 0; | 1112 | port->RxHolding = 0; |
1181 | mydbg("%s port->RxHolding = 0\n", __FUNCTION__); | 1113 | mydbg("%s port->RxHolding = 0\n", __FUNCTION__); |
1182 | 1114 | ||
1183 | retval = qt_open(port, filp); | 1115 | retval = qt_open(port, filp); |
1184 | } | 1116 | } |
1185 | 1117 | ||
1186 | if (retval) | 1118 | if (retval) { |
1187 | { | 1119 | port->open_count = 0; |
1188 | port->open_count = 0; | 1120 | } |
1189 | } | 1121 | mydbg("%s returning port->closePending = %d\n", __FUNCTION__, |
1190 | mydbg("%s returning port->closePending = %d\n", __FUNCTION__, port->closePending); | 1122 | port->closePending); |
1191 | 1123 | ||
1192 | up (&port->sem); | 1124 | up(&port->sem); |
1193 | return retval; | 1125 | return retval; |
1194 | } | 1126 | } |
1127 | |||
1195 | /***************************************************************************** | 1128 | /***************************************************************************** |
1196 | *device's specific driver functions | 1129 | *device's specific driver functions |
1197 | *****************************************************************************/ | 1130 | *****************************************************************************/ |
1198 | static int qt_open (struct usb_serial_port *port, struct file *filp){ | 1131 | static int qt_open(struct usb_serial_port *port, struct file *filp) |
1199 | struct usb_serial *serial = port->serial; | 1132 | { |
1200 | int result = 0; | 1133 | struct usb_serial *serial = port->serial; |
1201 | unsigned int UartNumber; | 1134 | int result = 0; |
1202 | struct qt_get_device_data DeviceData; | 1135 | unsigned int UartNumber; |
1203 | struct qt_open_channel_data ChannelData; | 1136 | struct qt_get_device_data DeviceData; |
1204 | unsigned short default_divisor = 0x30; //gives 9600 baud rate | 1137 | struct qt_open_channel_data ChannelData; |
1205 | unsigned char default_LCR = SERIAL_8_DATA; // 8, none , 1 | 1138 | unsigned short default_divisor = 0x30; //gives 9600 baud rate |
1206 | int status = 0; | 1139 | unsigned char default_LCR = SERIAL_8_DATA; // 8, none , 1 |
1207 | 1140 | int status = 0; | |
1208 | |||
1209 | |||
1210 | |||
1211 | if (port_paranoia_check (port, __FUNCTION__)) | ||
1212 | return -ENODEV; | ||
1213 | |||
1214 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | ||
1215 | |||
1216 | /* force low_latency on so that our tty_push actually forces the data through, | ||
1217 | otherwise it is scheduled, and with high data rates (like with OHCI) data | ||
1218 | can get lost. */ | ||
1219 | if (port->tty) | ||
1220 | port->tty->low_latency = 0; | ||
1221 | |||
1222 | |||
1223 | UartNumber = port->tty->index - serial->minor; | ||
1224 | 1141 | ||
1225 | status = box_get_device(serial, &DeviceData); | 1142 | if (port_paranoia_check(port, __FUNCTION__)) |
1226 | if (status < 0) | 1143 | return -ENODEV; |
1227 | { | ||
1228 | mydbg(__FILE__"box_get_device failed\n"); | ||
1229 | return status; | ||
1230 | } | ||
1231 | serial->num_OpenCount++; | ||
1232 | mydbg("%s serial->num_OpenCount = %d\n", __FUNCTION__, serial->num_OpenCount); | ||
1233 | //Open uart channel | ||
1234 | 1144 | ||
1235 | //Port specific setups | 1145 | mydbg("%s - port %d\n", __FUNCTION__, port->number); |
1236 | status = BoxOPenCloseChannel(serial, UartNumber, 1, &ChannelData); | ||
1237 | if (status < 0) | ||
1238 | { | ||
1239 | mydbg(__FILE__"BoxOPenCloseChannel failed\n"); | ||
1240 | return status; | ||
1241 | } | ||
1242 | mydbg(__FILE__"BoxOPenCloseChannel completed.\n"); | ||
1243 | 1146 | ||
1244 | port->shadowLSR = ChannelData.line_status & | 1147 | /* force low_latency on so that our tty_push actually forces the data through, |
1245 | (SERIAL_LSR_OE | SERIAL_LSR_PE | SERIAL_LSR_FE | SERIAL_LSR_BI); | 1148 | otherwise it is scheduled, and with high data rates (like with OHCI) data |
1149 | can get lost. */ | ||
1150 | if (port->tty) | ||
1151 | port->tty->low_latency = 0; | ||
1246 | 1152 | ||
1247 | port->shadowMSR = ChannelData.modem_status & | 1153 | UartNumber = port->tty->index - serial->minor; |
1248 | (SERIAL_MSR_CTS | SERIAL_MSR_DSR | SERIAL_MSR_RI | SERIAL_MSR_CD); | ||
1249 | 1154 | ||
1155 | status = box_get_device(serial, &DeviceData); | ||
1156 | if (status < 0) { | ||
1157 | mydbg(__FILE__ "box_get_device failed\n"); | ||
1158 | return status; | ||
1159 | } | ||
1160 | serial->num_OpenCount++; | ||
1161 | mydbg("%s serial->num_OpenCount = %d\n", __FUNCTION__, | ||
1162 | serial->num_OpenCount); | ||
1163 | //Open uart channel | ||
1164 | |||
1165 | //Port specific setups | ||
1166 | status = BoxOPenCloseChannel(serial, UartNumber, 1, &ChannelData); | ||
1167 | if (status < 0) { | ||
1168 | mydbg(__FILE__ "BoxOPenCloseChannel failed\n"); | ||
1169 | return status; | ||
1170 | } | ||
1171 | mydbg(__FILE__ "BoxOPenCloseChannel completed.\n"); | ||
1250 | 1172 | ||
1251 | //Set Baud rate to default and turn off (default)flow control here | 1173 | port->shadowLSR = ChannelData.line_status & |
1252 | status = BoxSetUart(serial, UartNumber, default_divisor, default_LCR); | 1174 | (SERIAL_LSR_OE | SERIAL_LSR_PE | SERIAL_LSR_FE | SERIAL_LSR_BI); |
1253 | if (status < 0) | ||
1254 | { | ||
1255 | mydbg(__FILE__"BoxSetUart failed\n"); | ||
1256 | return status; | ||
1257 | } | ||
1258 | mydbg(__FILE__"BoxSetUart completed.\n"); | ||
1259 | 1175 | ||
1176 | port->shadowMSR = ChannelData.modem_status & | ||
1177 | (SERIAL_MSR_CTS | SERIAL_MSR_DSR | SERIAL_MSR_RI | SERIAL_MSR_CD); | ||
1260 | 1178 | ||
1261 | //Put this here to make it responsive to stty and defauls set by the tty layer | 1179 | //Set Baud rate to default and turn off (default)flow control here |
1262 | qt_set_termios(port, NULL); | 1180 | status = BoxSetUart(serial, UartNumber, default_divisor, default_LCR); |
1181 | if (status < 0) { | ||
1182 | mydbg(__FILE__ "BoxSetUart failed\n"); | ||
1183 | return status; | ||
1184 | } | ||
1185 | mydbg(__FILE__ "BoxSetUart completed.\n"); | ||
1263 | 1186 | ||
1187 | //Put this here to make it responsive to stty and defauls set by the tty layer | ||
1188 | qt_set_termios(port, NULL); | ||
1264 | 1189 | ||
1265 | //Initialize the wait que head | 1190 | //Initialize the wait que head |
1266 | init_waitqueue_head(&(port->wait)); | 1191 | init_waitqueue_head(&(port->wait)); |
1267 | 1192 | ||
1268 | /* if we have a bulk endpoint, start reading from it */ | 1193 | /* if we have a bulk endpoint, start reading from it */ |
1269 | if (serial->num_bulk_in) | 1194 | if (serial->num_bulk_in) { |
1270 | { | 1195 | /* Start reading from the device */ |
1271 | /* Start reading from the device */ | 1196 | usb_fill_bulk_urb(port->read_urb, serial->dev, |
1272 | usb_fill_bulk_urb (port->read_urb, serial->dev, | 1197 | usb_rcvbulkpipe(serial->dev, |
1273 | usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), | 1198 | port-> |
1274 | port->read_urb->transfer_buffer, | 1199 | bulk_in_endpointAddress), |
1275 | port->read_urb->transfer_buffer_length, | 1200 | port->read_urb->transfer_buffer, |
1276 | qt_read_bulk_callback, | 1201 | port->read_urb->transfer_buffer_length, |
1277 | port); | 1202 | qt_read_bulk_callback, port); |
1278 | 1203 | ||
1279 | port->ReadBulkStopped = 0; | 1204 | port->ReadBulkStopped = 0; |
1280 | 1205 | ||
1281 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); | 1206 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); |
1282 | 1207 | ||
1283 | if (result) | 1208 | if (result) { |
1284 | { | 1209 | err("%s - failed resubmitting read urb, error %d\n", |
1285 | err("%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); | 1210 | __FUNCTION__, result); |
1286 | port->ReadBulkStopped = 1; | 1211 | port->ReadBulkStopped = 1; |
1287 | } | 1212 | } |
1288 | 1213 | ||
1289 | } | 1214 | } |
1290 | 1215 | ||
1291 | return result; | 1216 | return result; |
1292 | } | 1217 | } |
1293 | 1218 | ||
1294 | static void serial_close(struct tty_struct *tty, struct file * filp){ | 1219 | static void serial_close(struct tty_struct *tty, struct file *filp) |
1295 | struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; | 1220 | { |
1296 | struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); | 1221 | struct usb_serial_port *port = |
1297 | 1222 | (struct usb_serial_port *)tty->driver_data; | |
1298 | if (!serial) | 1223 | struct usb_serial *serial = get_usb_serial(port, __FUNCTION__); |
1299 | return; | ||
1300 | 1224 | ||
1301 | down (&port->sem); | 1225 | if (!serial) |
1226 | return; | ||
1302 | 1227 | ||
1303 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | 1228 | down(&port->sem); |
1304 | 1229 | ||
1305 | /* if disconnect beat us to the punch here, there's nothing to do */ | 1230 | mydbg("%s - port %d\n", __FUNCTION__, port->number); |
1306 | if (tty->driver_data) | ||
1307 | { | ||
1308 | if (!port->open_count) | ||
1309 | { | ||
1310 | mydbg ("%s - port not opened\n", __FUNCTION__); | ||
1311 | goto exit; | ||
1312 | } | ||
1313 | 1231 | ||
1314 | --port->open_count; | 1232 | /* if disconnect beat us to the punch here, there's nothing to do */ |
1315 | if (port->open_count <= 0) | 1233 | if (tty->driver_data) { |
1316 | { | 1234 | if (!port->open_count) { |
1317 | port->closePending = 1; | 1235 | mydbg("%s - port not opened\n", __FUNCTION__); |
1318 | mydbg ("%s - port->closePending = 1\n", __FUNCTION__); | 1236 | goto exit; |
1237 | } | ||
1319 | 1238 | ||
1320 | if (serial->dev) | 1239 | --port->open_count; |
1321 | { | 1240 | if (port->open_count <= 0) { |
1322 | qt_close(port, filp); | 1241 | port->closePending = 1; |
1323 | port->open_count = 0; | 1242 | mydbg("%s - port->closePending = 1\n", __FUNCTION__); |
1324 | } | ||
1325 | } | ||
1326 | 1243 | ||
1327 | } | 1244 | if (serial->dev) { |
1245 | qt_close(port, filp); | ||
1246 | port->open_count = 0; | ||
1247 | } | ||
1248 | } | ||
1328 | 1249 | ||
1329 | exit: | 1250 | } |
1330 | up (&port->sem); | ||
1331 | 1251 | ||
1332 | mydbg("%s - %d return\n", __FUNCTION__, port->number); | 1252 | exit: |
1253 | up(&port->sem); | ||
1333 | 1254 | ||
1255 | mydbg("%s - %d return\n", __FUNCTION__, port->number); | ||
1334 | 1256 | ||
1335 | } | 1257 | } |
1336 | 1258 | ||
1337 | static void qt_close (struct usb_serial_port *port, struct file *filp){ | 1259 | static void qt_close(struct usb_serial_port *port, struct file *filp) |
1338 | unsigned long jift = jiffies + 10 * HZ; | 1260 | { |
1339 | __u8 LSR_Value, MCR_Value; | 1261 | unsigned long jift = jiffies + 10 * HZ; |
1340 | struct usb_serial *serial = port->serial; | 1262 | __u8 LSR_Value, MCR_Value; |
1341 | int status; | 1263 | struct usb_serial *serial = port->serial; |
1342 | unsigned int UartNumber; | 1264 | int status; |
1343 | 1265 | unsigned int UartNumber; | |
1344 | struct qt_open_channel_data ChannelData; | ||
1345 | status = 0; | ||
1346 | LSR_Value = 0; | ||
1347 | |||
1348 | |||
1349 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | ||
1350 | UartNumber = port->tty->index - serial->minor; | ||
1351 | |||
1352 | /* shutdown any bulk reads that might be going on */ | ||
1353 | if (serial->num_bulk_out) | ||
1354 | usb_unlink_urb (port->write_urb); | ||
1355 | if (serial->num_bulk_in) | ||
1356 | usb_unlink_urb (port->read_urb); | ||
1357 | |||
1358 | |||
1359 | //wait up to 30 seconds for transmitter to empty | ||
1360 | do | ||
1361 | { | ||
1362 | status = BoxGetRegister(serial, UartNumber, LINE_STATUS_REGISTER, &LSR_Value); | ||
1363 | if (status < 0) | ||
1364 | { | ||
1365 | mydbg(__FILE__"box_get_device failed\n"); | ||
1366 | break; | ||
1367 | } | ||
1368 | |||
1369 | if ((LSR_Value & SERIAL_LSR_TEMT) && (port->ReadBulkStopped == 1)) | ||
1370 | break; | ||
1371 | schedule(); | ||
1372 | |||
1373 | |||
1374 | } | ||
1375 | while (jiffies <= jift); | ||
1376 | |||
1377 | if(jiffies > jift) | ||
1378 | mydbg("%s - port %d timout of checking transmitter empty\n", __FUNCTION__, port->number); | ||
1379 | else | ||
1380 | mydbg("%s - port %d checking transmitter empty succeded\n", __FUNCTION__, port->number); | ||
1381 | |||
1382 | 1266 | ||
1267 | struct qt_open_channel_data ChannelData; | ||
1268 | status = 0; | ||
1269 | LSR_Value = 0; | ||
1383 | 1270 | ||
1384 | status = BoxGetRegister(serial, UartNumber, MODEM_CONTROL_REGISTER, &MCR_Value); | 1271 | mydbg("%s - port %d\n", __FUNCTION__, port->number); |
1385 | mydbg(__FILE__"BoxGetRegister MCR = 0x%x.\n", MCR_Value); | 1272 | UartNumber = port->tty->index - serial->minor; |
1273 | |||
1274 | /* shutdown any bulk reads that might be going on */ | ||
1275 | if (serial->num_bulk_out) | ||
1276 | usb_unlink_urb(port->write_urb); | ||
1277 | if (serial->num_bulk_in) | ||
1278 | usb_unlink_urb(port->read_urb); | ||
1279 | |||
1280 | //wait up to 30 seconds for transmitter to empty | ||
1281 | do { | ||
1282 | status = | ||
1283 | BoxGetRegister(serial, UartNumber, LINE_STATUS_REGISTER, | ||
1284 | &LSR_Value); | ||
1285 | if (status < 0) { | ||
1286 | mydbg(__FILE__ "box_get_device failed\n"); | ||
1287 | break; | ||
1288 | } | ||
1386 | 1289 | ||
1290 | if ((LSR_Value & SERIAL_LSR_TEMT) | ||
1291 | && (port->ReadBulkStopped == 1)) | ||
1292 | break; | ||
1293 | schedule(); | ||
1387 | 1294 | ||
1388 | if (status >= 0) | 1295 | } |
1389 | { | 1296 | while (jiffies <= jift); |
1390 | MCR_Value &= ~(SERIAL_MCR_DTR | SERIAL_MCR_RTS); | 1297 | |
1298 | if (jiffies > jift) | ||
1299 | mydbg("%s - port %d timout of checking transmitter empty\n", | ||
1300 | __FUNCTION__, port->number); | ||
1301 | else | ||
1302 | mydbg("%s - port %d checking transmitter empty succeded\n", | ||
1303 | __FUNCTION__, port->number); | ||
1304 | |||
1305 | status = | ||
1306 | BoxGetRegister(serial, UartNumber, MODEM_CONTROL_REGISTER, | ||
1307 | &MCR_Value); | ||
1308 | mydbg(__FILE__ "BoxGetRegister MCR = 0x%x.\n", MCR_Value); | ||
1309 | |||
1310 | if (status >= 0) { | ||
1311 | MCR_Value &= ~(SERIAL_MCR_DTR | SERIAL_MCR_RTS); | ||
1391 | // status = BoxSetRegister(serial, UartNumber, MODEM_CONTROL_REGISTER, MCR_Value); | 1312 | // status = BoxSetRegister(serial, UartNumber, MODEM_CONTROL_REGISTER, MCR_Value); |
1392 | } | 1313 | } |
1393 | |||
1394 | |||
1395 | //Close uart channel | ||
1396 | status = BoxOPenCloseChannel(serial, UartNumber, 0, &ChannelData); | ||
1397 | if(status < 0) | ||
1398 | mydbg("%s - port %d BoxOPenCloseChannel failed.\n", __FUNCTION__, port->number); | ||
1399 | 1314 | ||
1400 | serial->num_OpenCount--; | 1315 | //Close uart channel |
1316 | status = BoxOPenCloseChannel(serial, UartNumber, 0, &ChannelData); | ||
1317 | if (status < 0) | ||
1318 | mydbg("%s - port %d BoxOPenCloseChannel failed.\n", | ||
1319 | __FUNCTION__, port->number); | ||
1401 | 1320 | ||
1321 | serial->num_OpenCount--; | ||
1402 | 1322 | ||
1403 | } | 1323 | } |
1404 | 1324 | ||
1405 | 1325 | static int serial_write(struct tty_struct *tty, const unsigned char *buf, | |
1406 | 1326 | int count) | |
1407 | static int serial_write (struct tty_struct * tty, const unsigned char *buf, int count) | ||
1408 | { | 1327 | { |
1409 | struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; | 1328 | struct usb_serial_port *port = |
1410 | struct usb_serial *serial; | 1329 | (struct usb_serial_port *)tty->driver_data; |
1411 | int retval = -EINVAL; | 1330 | struct usb_serial *serial; |
1412 | unsigned int UartNumber; | 1331 | int retval = -EINVAL; |
1413 | int from_user = 0; | 1332 | unsigned int UartNumber; |
1414 | 1333 | int from_user = 0; | |
1415 | |||
1416 | serial = get_usb_serial (port, __FUNCTION__); | ||
1417 | if(serial == NULL) | ||
1418 | return -ENODEV; | ||
1419 | //This can happen if we get disconnected a | ||
1420 | if (port->open_count == 0) | ||
1421 | { | ||
1422 | return -ENODEV; | ||
1423 | } | ||
1424 | UartNumber = port->tty->index - serial->minor; | ||
1425 | |||
1426 | mydbg("%s - port %d, %d byte(s)\n", __FUNCTION__, port->number, count); | ||
1427 | mydbg("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding); | ||
1428 | |||
1429 | if (!port->open_count) | ||
1430 | { | ||
1431 | mydbg("%s - port not opened\n", __FUNCTION__); | ||
1432 | goto exit; | ||
1433 | } | ||
1434 | |||
1435 | retval = qt_write(port, from_user, buf, count); | ||
1436 | |||
1437 | exit: | ||
1438 | return retval; | ||
1439 | } | ||
1440 | |||
1441 | |||
1442 | static int qt_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count){ | ||
1443 | int result; | ||
1444 | unsigned int UartNumber; | ||
1445 | |||
1446 | struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); | ||
1447 | if(serial == NULL) | ||
1448 | return -ENODEV; | ||
1449 | |||
1450 | 1334 | ||
1335 | serial = get_usb_serial(port, __FUNCTION__); | ||
1336 | if (serial == NULL) | ||
1337 | return -ENODEV; | ||
1338 | //This can happen if we get disconnected a | ||
1339 | if (port->open_count == 0) { | ||
1340 | return -ENODEV; | ||
1341 | } | ||
1342 | UartNumber = port->tty->index - serial->minor; | ||
1451 | 1343 | ||
1452 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | 1344 | mydbg("%s - port %d, %d byte(s)\n", __FUNCTION__, port->number, count); |
1345 | mydbg("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding); | ||
1453 | 1346 | ||
1454 | if (count == 0) | 1347 | if (!port->open_count) { |
1455 | { | 1348 | mydbg("%s - port not opened\n", __FUNCTION__); |
1456 | mydbg("%s - write request of 0 bytes\n", __FUNCTION__); | 1349 | goto exit; |
1457 | return(0); | 1350 | } |
1458 | } | ||
1459 | 1351 | ||
1352 | retval = qt_write(port, from_user, buf, count); | ||
1460 | 1353 | ||
1461 | UartNumber = port->tty->index - serial->minor; | 1354 | exit: |
1462 | /* only do something if we have a bulk out endpoint */ | 1355 | return retval; |
1463 | if (serial->num_bulk_out) | 1356 | } |
1464 | { | ||
1465 | if (port->write_urb->status == -EINPROGRESS) | ||
1466 | { | ||
1467 | mydbg("%s - already writing\n", __FUNCTION__); | ||
1468 | return(0); | ||
1469 | } | ||
1470 | 1357 | ||
1471 | count = (count > port->bulk_out_size) ? port->bulk_out_size : count; | 1358 | static int qt_write(struct usb_serial_port *port, int from_user, |
1359 | const unsigned char *buf, int count) | ||
1360 | { | ||
1361 | int result; | ||
1362 | unsigned int UartNumber; | ||
1472 | 1363 | ||
1473 | if (from_user) | 1364 | struct usb_serial *serial = get_usb_serial(port, __FUNCTION__); |
1474 | { | 1365 | if (serial == NULL) |
1475 | if (copy_from_user(port->write_urb->transfer_buffer, buf, count)) | 1366 | return -ENODEV; |
1476 | return -EFAULT; | ||
1477 | } else | ||
1478 | { | ||
1479 | memcpy (port->write_urb->transfer_buffer, buf, count); | ||
1480 | } | ||
1481 | 1367 | ||
1482 | //usb_serial_debug_data(__FILE__, __FUNCTION__, count, port->write_urb->transfer_buffer); | 1368 | mydbg("%s - port %d\n", __FUNCTION__, port->number); |
1483 | 1369 | ||
1484 | /* set up our urb */ | 1370 | if (count == 0) { |
1371 | mydbg("%s - write request of 0 bytes\n", __FUNCTION__); | ||
1372 | return (0); | ||
1373 | } | ||
1485 | 1374 | ||
1375 | UartNumber = port->tty->index - serial->minor; | ||
1376 | /* only do something if we have a bulk out endpoint */ | ||
1377 | if (serial->num_bulk_out) { | ||
1378 | if (port->write_urb->status == -EINPROGRESS) { | ||
1379 | mydbg("%s - already writing\n", __FUNCTION__); | ||
1380 | return (0); | ||
1381 | } | ||
1486 | 1382 | ||
1487 | usb_fill_bulk_urb (port->write_urb, serial->dev, | 1383 | count = |
1488 | usb_sndbulkpipe (serial->dev, | 1384 | (count > port->bulk_out_size) ? port->bulk_out_size : count; |
1489 | port->bulk_out_endpointAddress), | ||
1490 | port->write_urb->transfer_buffer, count, | ||
1491 | qt_write_bulk_callback, port); | ||
1492 | 1385 | ||
1386 | if (from_user) { | ||
1387 | if (copy_from_user | ||
1388 | (port->write_urb->transfer_buffer, buf, count)) | ||
1389 | return -EFAULT; | ||
1390 | } else { | ||
1391 | memcpy(port->write_urb->transfer_buffer, buf, count); | ||
1392 | } | ||
1493 | 1393 | ||
1394 | //usb_serial_debug_data(__FILE__, __FUNCTION__, count, port->write_urb->transfer_buffer); | ||
1494 | 1395 | ||
1396 | /* set up our urb */ | ||
1495 | 1397 | ||
1398 | usb_fill_bulk_urb(port->write_urb, serial->dev, | ||
1399 | usb_sndbulkpipe(serial->dev, | ||
1400 | port-> | ||
1401 | bulk_out_endpointAddress), | ||
1402 | port->write_urb->transfer_buffer, count, | ||
1403 | qt_write_bulk_callback, port); | ||
1496 | 1404 | ||
1497 | /* send the data out the bulk port */ | 1405 | /* send the data out the bulk port */ |
1498 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); | 1406 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); |
1499 | if (result) | 1407 | if (result) |
1500 | mydbg("%s - failed submitting write urb, error %d\n", __FUNCTION__, result); | 1408 | mydbg("%s - failed submitting write urb, error %d\n", |
1501 | else | 1409 | __FUNCTION__, result); |
1502 | result = count; | 1410 | else |
1411 | result = count; | ||
1503 | 1412 | ||
1504 | return result; | 1413 | return result; |
1505 | } | 1414 | } |
1506 | 1415 | ||
1507 | /* no bulk out, so return 0 bytes written */ | 1416 | /* no bulk out, so return 0 bytes written */ |
1508 | return(0); | 1417 | return (0); |
1509 | } | 1418 | } |
1510 | 1419 | ||
1511 | |||
1512 | |||
1513 | static void qt_write_bulk_callback(struct urb *urb) | 1420 | static void qt_write_bulk_callback(struct urb *urb) |
1514 | { | 1421 | { |
1515 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; | 1422 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; |
1516 | struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); | 1423 | struct usb_serial *serial = get_usb_serial(port, __FUNCTION__); |
1517 | |||
1518 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | ||
1519 | |||
1520 | if (!serial) | ||
1521 | { | ||
1522 | mydbg("%s - bad serial pointer, exiting\n", __FUNCTION__); | ||
1523 | return; | ||
1524 | } | ||
1525 | |||
1526 | if (urb->status) | ||
1527 | { | ||
1528 | mydbg("%s - nonzero write bulk status received: %d\n", __FUNCTION__, urb->status); | ||
1529 | return; | ||
1530 | } | ||
1531 | // | ||
1532 | port_softint(&port->work); | ||
1533 | schedule_work(&port->work); | ||
1534 | |||
1535 | return; | ||
1536 | } | ||
1537 | |||
1538 | 1424 | ||
1539 | static void port_softint(struct work_struct *work) | 1425 | mydbg("%s - port %d\n", __FUNCTION__, port->number); |
1540 | { | ||
1541 | struct usb_serial_port *port = | ||
1542 | container_of(work, struct usb_serial_port, work); | ||
1543 | struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); | ||
1544 | struct tty_struct *tty; | ||
1545 | 1426 | ||
1427 | if (!serial) { | ||
1428 | mydbg("%s - bad serial pointer, exiting\n", __FUNCTION__); | ||
1429 | return; | ||
1430 | } | ||
1546 | 1431 | ||
1547 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | 1432 | if (urb->status) { |
1433 | mydbg("%s - nonzero write bulk status received: %d\n", | ||
1434 | __FUNCTION__, urb->status); | ||
1435 | return; | ||
1436 | } | ||
1437 | // | ||
1438 | port_softint(&port->work); | ||
1439 | schedule_work(&port->work); | ||
1548 | 1440 | ||
1441 | return; | ||
1442 | } | ||
1549 | 1443 | ||
1444 | static void port_softint(struct work_struct *work) | ||
1445 | { | ||
1446 | struct usb_serial_port *port = | ||
1447 | container_of(work, struct usb_serial_port, work); | ||
1448 | struct usb_serial *serial = get_usb_serial(port, __FUNCTION__); | ||
1449 | struct tty_struct *tty; | ||
1550 | 1450 | ||
1551 | if (!serial) | 1451 | mydbg("%s - port %d\n", __FUNCTION__, port->number); |
1552 | return; | ||
1553 | 1452 | ||
1453 | if (!serial) | ||
1454 | return; | ||
1554 | 1455 | ||
1555 | tty = port->tty; | 1456 | tty = port->tty; |
1556 | if (!tty) | 1457 | if (!tty) |
1557 | return; | 1458 | return; |
1558 | #if 0 | 1459 | #if 0 |
1559 | if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup) | 1460 | if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) |
1560 | { | 1461 | && tty->ldisc.write_wakeup) { |
1561 | mydbg("%s - write wakeup call.\n", __FUNCTION__); | 1462 | mydbg("%s - write wakeup call.\n", __FUNCTION__); |
1562 | (tty->ldisc.write_wakeup)(tty); | 1463 | (tty->ldisc.write_wakeup) (tty); |
1563 | } | 1464 | } |
1564 | #endif | 1465 | #endif |
1565 | 1466 | ||
1566 | wake_up_interruptible(&tty->write_wait); | 1467 | wake_up_interruptible(&tty->write_wait); |
1567 | } | 1468 | } |
1568 | static int serial_write_room (struct tty_struct *tty) | 1469 | static int serial_write_room(struct tty_struct *tty) |
1569 | { | 1470 | { |
1570 | struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; | 1471 | struct usb_serial_port *port = |
1571 | struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); | 1472 | (struct usb_serial_port *)tty->driver_data; |
1572 | int retval = -EINVAL; | 1473 | struct usb_serial *serial = get_usb_serial(port, __FUNCTION__); |
1474 | int retval = -EINVAL; | ||
1573 | 1475 | ||
1574 | if (!serial) | 1476 | if (!serial) |
1575 | return -ENODEV; | 1477 | return -ENODEV; |
1576 | 1478 | ||
1577 | down (&port->sem); | 1479 | down(&port->sem); |
1578 | 1480 | ||
1579 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | 1481 | mydbg("%s - port %d\n", __FUNCTION__, port->number); |
1580 | 1482 | ||
1581 | if (!port->open_count) | 1483 | if (!port->open_count) { |
1582 | { | 1484 | mydbg("%s - port not open\n", __FUNCTION__); |
1583 | mydbg("%s - port not open\n", __FUNCTION__); | 1485 | goto exit; |
1584 | goto exit; | 1486 | } |
1585 | } | ||
1586 | 1487 | ||
1587 | retval = qt_write_room(port); | 1488 | retval = qt_write_room(port); |
1588 | 1489 | ||
1589 | exit: | 1490 | exit: |
1590 | up (&port->sem); | 1491 | up(&port->sem); |
1591 | return retval; | 1492 | return retval; |
1592 | } | 1493 | } |
1593 | static int qt_write_room (struct usb_serial_port *port) | 1494 | static int qt_write_room(struct usb_serial_port *port) |
1594 | { | 1495 | { |
1595 | struct usb_serial *serial = port->serial; | 1496 | struct usb_serial *serial = port->serial; |
1596 | int room = 0; | 1497 | int room = 0; |
1597 | if (port->closePending == 1) | 1498 | if (port->closePending == 1) { |
1598 | { | 1499 | mydbg("%s - port->closePending == 1\n", __FUNCTION__); |
1599 | mydbg("%s - port->closePending == 1\n", __FUNCTION__); | 1500 | return -ENODEV; |
1600 | return -ENODEV; | 1501 | } |
1601 | } | ||
1602 | |||
1603 | 1502 | ||
1604 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | 1503 | mydbg("%s - port %d\n", __FUNCTION__, port->number); |
1605 | 1504 | ||
1606 | if (serial->num_bulk_out) | 1505 | if (serial->num_bulk_out) { |
1607 | { | 1506 | if (port->write_urb->status != -EINPROGRESS) |
1608 | if (port->write_urb->status != -EINPROGRESS) | 1507 | room = port->bulk_out_size; |
1609 | room = port->bulk_out_size; | 1508 | } |
1610 | } | ||
1611 | 1509 | ||
1612 | mydbg("%s - returns %d\n", __FUNCTION__, room); | 1510 | mydbg("%s - returns %d\n", __FUNCTION__, room); |
1613 | return(room); | 1511 | return (room); |
1614 | } | 1512 | } |
1615 | static int serial_chars_in_buffer (struct tty_struct *tty) | 1513 | static int serial_chars_in_buffer(struct tty_struct *tty) |
1616 | { | 1514 | { |
1617 | struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; | 1515 | struct usb_serial_port *port = |
1618 | struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); | 1516 | (struct usb_serial_port *)tty->driver_data; |
1517 | struct usb_serial *serial = get_usb_serial(port, __FUNCTION__); | ||
1619 | int retval = -EINVAL; | 1518 | int retval = -EINVAL; |
1620 | 1519 | ||
1621 | if (!serial) | 1520 | if (!serial) |
1622 | return -ENODEV; | 1521 | return -ENODEV; |
1623 | 1522 | ||
1624 | down (&port->sem); | 1523 | down(&port->sem); |
1625 | 1524 | ||
1626 | mydbg("%s = port %d\n", __FUNCTION__, port->number); | 1525 | mydbg("%s = port %d\n", __FUNCTION__, port->number); |
1627 | 1526 | ||
@@ -1633,275 +1532,267 @@ static int serial_chars_in_buffer (struct tty_struct *tty) | |||
1633 | retval = qt_chars_in_buffer(port); | 1532 | retval = qt_chars_in_buffer(port); |
1634 | 1533 | ||
1635 | exit: | 1534 | exit: |
1636 | up (&port->sem); | 1535 | up(&port->sem); |
1637 | return retval; | 1536 | return retval; |
1638 | } | 1537 | } |
1639 | 1538 | ||
1640 | 1539 | static int qt_chars_in_buffer(struct usb_serial_port *port) | |
1641 | |||
1642 | static int qt_chars_in_buffer (struct usb_serial_port *port) | ||
1643 | { | 1540 | { |
1644 | struct usb_serial *serial = port->serial; | 1541 | struct usb_serial *serial = port->serial; |
1645 | int chars = 0; | 1542 | int chars = 0; |
1646 | 1543 | ||
1647 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | 1544 | mydbg("%s - port %d\n", __FUNCTION__, port->number); |
1648 | 1545 | ||
1649 | if (serial->num_bulk_out) | 1546 | if (serial->num_bulk_out) { |
1650 | { | 1547 | if (port->write_urb->status == -EINPROGRESS) |
1651 | if (port->write_urb->status == -EINPROGRESS) | 1548 | chars = port->write_urb->transfer_buffer_length; |
1652 | chars = port->write_urb->transfer_buffer_length; | 1549 | } |
1653 | } | ||
1654 | 1550 | ||
1655 | mydbg("%s - returns %d\n", __FUNCTION__, chars); | 1551 | mydbg("%s - returns %d\n", __FUNCTION__, chars); |
1656 | return(chars); | 1552 | return (chars); |
1657 | } | 1553 | } |
1658 | 1554 | ||
1659 | 1555 | static int serial_tiocmset(struct tty_struct *tty, struct file *file, | |
1660 | static int serial_tiocmset (struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear) | 1556 | unsigned int set, unsigned int clear) |
1661 | { | 1557 | { |
1662 | 1558 | ||
1663 | struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; | 1559 | struct usb_serial_port *port = |
1664 | struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); | 1560 | (struct usb_serial_port *)tty->driver_data; |
1665 | int retval = -ENODEV; | 1561 | struct usb_serial *serial = get_usb_serial(port, __FUNCTION__); |
1666 | unsigned int UartNumber; | 1562 | int retval = -ENODEV; |
1667 | mydbg("In %s \n", __FUNCTION__); | 1563 | unsigned int UartNumber; |
1668 | 1564 | mydbg("In %s \n", __FUNCTION__); | |
1669 | if (!serial) | ||
1670 | return -ENODEV; | ||
1671 | 1565 | ||
1566 | if (!serial) | ||
1567 | return -ENODEV; | ||
1672 | 1568 | ||
1673 | UartNumber = port->tty->index - serial->minor; | 1569 | UartNumber = port->tty->index - serial->minor; |
1674 | |||
1675 | 1570 | ||
1676 | down (&port->sem); | 1571 | down(&port->sem); |
1677 | 1572 | ||
1678 | mydbg("%s - port %d \n", __FUNCTION__, port->number); | 1573 | mydbg("%s - port %d \n", __FUNCTION__, port->number); |
1679 | mydbg ("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding); | 1574 | mydbg("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding); |
1680 | 1575 | ||
1681 | if (!port->open_count) | 1576 | if (!port->open_count) { |
1682 | { | 1577 | mydbg("%s - port not open\n", __FUNCTION__); |
1683 | mydbg ("%s - port not open\n", __FUNCTION__); | 1578 | goto exit; |
1684 | goto exit; | 1579 | } |
1685 | } | ||
1686 | 1580 | ||
1687 | retval = qt_tiocmset(port, file, set); | 1581 | retval = qt_tiocmset(port, file, set); |
1688 | 1582 | ||
1689 | exit: | 1583 | exit: |
1690 | up (&port->sem); | 1584 | up(&port->sem); |
1691 | return retval; | 1585 | return retval; |
1692 | } | 1586 | } |
1693 | 1587 | ||
1694 | 1588 | static int qt_tiocmset(struct usb_serial_port *port, struct file *file, | |
1695 | static int qt_tiocmset(struct usb_serial_port *port, struct file * file, unsigned int value) | 1589 | unsigned int value) |
1696 | { | 1590 | { |
1697 | 1591 | ||
1698 | __u8 MCR_Value; | 1592 | __u8 MCR_Value; |
1699 | int status; | 1593 | int status; |
1700 | unsigned int UartNumber; | 1594 | unsigned int UartNumber; |
1701 | |||
1702 | 1595 | ||
1703 | struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); | 1596 | struct usb_serial *serial = get_usb_serial(port, __FUNCTION__); |
1704 | if(serial == NULL) | 1597 | if (serial == NULL) |
1705 | return -ENODEV; | 1598 | return -ENODEV; |
1706 | 1599 | ||
1707 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | 1600 | mydbg("%s - port %d\n", __FUNCTION__, port->number); |
1708 | 1601 | ||
1709 | /**************************************************************************************/ | 1602 | /**************************************************************************************/ |
1710 | /** TIOCMGET | 1603 | /** TIOCMGET |
1711 | */ | 1604 | */ |
1712 | UartNumber = port->tty->index - serial->minor; | 1605 | UartNumber = port->tty->index - serial->minor; |
1713 | status = BoxGetRegister(port->serial, UartNumber, MODEM_CONTROL_REGISTER, &MCR_Value); | 1606 | status = |
1714 | if (status < 0) | 1607 | BoxGetRegister(port->serial, UartNumber, MODEM_CONTROL_REGISTER, |
1715 | return -ESPIPE; | 1608 | &MCR_Value); |
1716 | 1609 | if (status < 0) | |
1717 | //Turn off the RTS and DTR and loopbcck and then only | 1610 | return -ESPIPE; |
1718 | //trun on what was asked for | 1611 | |
1719 | MCR_Value &= ~(SERIAL_MCR_RTS | SERIAL_MCR_DTR | SERIAL_MCR_LOOP); | 1612 | //Turn off the RTS and DTR and loopbcck and then only |
1720 | if (value & TIOCM_RTS) | 1613 | //trun on what was asked for |
1721 | MCR_Value |= SERIAL_MCR_RTS; | 1614 | MCR_Value &= ~(SERIAL_MCR_RTS | SERIAL_MCR_DTR | SERIAL_MCR_LOOP); |
1722 | if (value & TIOCM_DTR) | 1615 | if (value & TIOCM_RTS) |
1723 | MCR_Value |= SERIAL_MCR_DTR; | 1616 | MCR_Value |= SERIAL_MCR_RTS; |
1724 | if (value & TIOCM_LOOP) | 1617 | if (value & TIOCM_DTR) |
1725 | MCR_Value |= SERIAL_MCR_LOOP; | 1618 | MCR_Value |= SERIAL_MCR_DTR; |
1726 | 1619 | if (value & TIOCM_LOOP) | |
1727 | status = BoxSetRegister(port->serial, UartNumber, MODEM_CONTROL_REGISTER, MCR_Value); | 1620 | MCR_Value |= SERIAL_MCR_LOOP; |
1728 | if (status < 0) | 1621 | |
1729 | return -ESPIPE; | 1622 | status = |
1730 | else | 1623 | BoxSetRegister(port->serial, UartNumber, MODEM_CONTROL_REGISTER, |
1731 | return 0; | 1624 | MCR_Value); |
1625 | if (status < 0) | ||
1626 | return -ESPIPE; | ||
1627 | else | ||
1628 | return 0; | ||
1732 | } | 1629 | } |
1733 | 1630 | ||
1734 | static int serial_tiocmget(struct tty_struct *tty, struct file *file) | 1631 | static int serial_tiocmget(struct tty_struct *tty, struct file *file) |
1735 | { | 1632 | { |
1736 | 1633 | ||
1737 | struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; | 1634 | struct usb_serial_port *port = |
1635 | (struct usb_serial_port *)tty->driver_data; | ||
1738 | 1636 | ||
1739 | struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); | 1637 | struct usb_serial *serial = get_usb_serial(port, __FUNCTION__); |
1740 | int retval = -ENODEV; | 1638 | int retval = -ENODEV; |
1741 | unsigned int UartNumber; | 1639 | unsigned int UartNumber; |
1742 | mydbg("In %s \n", __FUNCTION__); | 1640 | mydbg("In %s \n", __FUNCTION__); |
1743 | 1641 | ||
1744 | if (!serial) | 1642 | if (!serial) |
1745 | return -ENODEV; | 1643 | return -ENODEV; |
1746 | |||
1747 | |||
1748 | UartNumber = port->tty->index - serial->minor; | ||
1749 | 1644 | ||
1645 | UartNumber = port->tty->index - serial->minor; | ||
1750 | 1646 | ||
1751 | down (&port->sem); | 1647 | down(&port->sem); |
1752 | 1648 | ||
1753 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | 1649 | mydbg("%s - port %d\n", __FUNCTION__, port->number); |
1754 | mydbg ("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding); | 1650 | mydbg("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding); |
1755 | 1651 | ||
1756 | if (!port->open_count) | 1652 | if (!port->open_count) { |
1757 | { | 1653 | mydbg("%s - port not open\n", __FUNCTION__); |
1758 | mydbg ("%s - port not open\n", __FUNCTION__); | 1654 | goto exit; |
1759 | goto exit; | 1655 | } |
1760 | } | ||
1761 | 1656 | ||
1762 | retval = qt_tiocmget(port, file); | 1657 | retval = qt_tiocmget(port, file); |
1763 | 1658 | ||
1764 | exit: | 1659 | exit: |
1765 | up (&port->sem); | 1660 | up(&port->sem); |
1766 | return retval; | 1661 | return retval; |
1767 | } | 1662 | } |
1768 | 1663 | ||
1769 | 1664 | static int qt_tiocmget(struct usb_serial_port *port, struct file *file) | |
1770 | |||
1771 | static int qt_tiocmget(struct usb_serial_port *port, struct file * file) | ||
1772 | { | 1665 | { |
1773 | 1666 | ||
1774 | __u8 MCR_Value; | 1667 | __u8 MCR_Value; |
1775 | __u8 MSR_Value; | 1668 | __u8 MSR_Value; |
1776 | unsigned int result = 0; | 1669 | unsigned int result = 0; |
1777 | int status; | 1670 | int status; |
1778 | unsigned int UartNumber; | 1671 | unsigned int UartNumber; |
1779 | struct tty_struct * tty; | 1672 | struct tty_struct *tty; |
1780 | 1673 | ||
1674 | struct usb_serial *serial = get_usb_serial(port, __FUNCTION__); | ||
1675 | if (serial == NULL) | ||
1676 | return -ENODEV; | ||
1677 | tty = port->tty; | ||
1781 | 1678 | ||
1782 | struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); | 1679 | mydbg("%s - port %d, tty =0x%p\n", __FUNCTION__, port->number, tty); |
1783 | if(serial == NULL) | ||
1784 | return -ENODEV; | ||
1785 | tty = port->tty; | ||
1786 | |||
1787 | mydbg("%s - port %d, tty =0x%p\n", __FUNCTION__, port->number, tty); | ||
1788 | 1680 | ||
1789 | /**************************************************************************************/ | 1681 | /**************************************************************************************/ |
1790 | /** TIOCMGET | 1682 | /** TIOCMGET |
1791 | */ | 1683 | */ |
1792 | UartNumber = port->tty->index - serial->minor; | 1684 | UartNumber = port->tty->index - serial->minor; |
1793 | status = BoxGetRegister(port->serial, UartNumber, MODEM_CONTROL_REGISTER, &MCR_Value); | 1685 | status = |
1794 | if (status >= 0) | 1686 | BoxGetRegister(port->serial, UartNumber, MODEM_CONTROL_REGISTER, |
1795 | { | 1687 | &MCR_Value); |
1796 | status = BoxGetRegister(port->serial, UartNumber, MODEM_STATUS_REGISTER, &MSR_Value); | 1688 | if (status >= 0) { |
1797 | 1689 | status = | |
1798 | } | 1690 | BoxGetRegister(port->serial, UartNumber, |
1799 | 1691 | MODEM_STATUS_REGISTER, &MSR_Value); | |
1800 | if (status >= 0) | ||
1801 | { | ||
1802 | result = ((MCR_Value & SERIAL_MCR_DTR) ? TIOCM_DTR: 0) | ||
1803 | //DTR IS SET | ||
1804 | | ((MCR_Value & SERIAL_MCR_RTS) ? TIOCM_RTS: 0) | ||
1805 | //RTS IS SET | ||
1806 | | ((MSR_Value & SERIAL_MSR_CTS) ? TIOCM_CTS: 0) | ||
1807 | //CTS is set | ||
1808 | | ((MSR_Value & SERIAL_MSR_CD) ? TIOCM_CAR: 0) | ||
1809 | //Carrier detect is set | ||
1810 | | ((MSR_Value & SERIAL_MSR_RI) ? TIOCM_RI: 0) | ||
1811 | //Ring indicator set | ||
1812 | | ((MSR_Value & SERIAL_MSR_DSR) ? TIOCM_DSR: 0); | ||
1813 | //DSR is set | ||
1814 | return result; | ||
1815 | |||
1816 | } | ||
1817 | else | ||
1818 | return -ESPIPE; | ||
1819 | //endif tatus => 0 | ||
1820 | } | ||
1821 | |||
1822 | 1692 | ||
1693 | } | ||
1823 | 1694 | ||
1824 | static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg) | 1695 | if (status >= 0) { |
1825 | { | 1696 | result = ((MCR_Value & SERIAL_MCR_DTR) ? TIOCM_DTR : 0) |
1697 | //DTR IS SET | ||
1698 | | ((MCR_Value & SERIAL_MCR_RTS) ? TIOCM_RTS : 0) | ||
1699 | //RTS IS SET | ||
1700 | | ((MSR_Value & SERIAL_MSR_CTS) ? TIOCM_CTS : 0) | ||
1701 | //CTS is set | ||
1702 | | ((MSR_Value & SERIAL_MSR_CD) ? TIOCM_CAR : 0) | ||
1703 | //Carrier detect is set | ||
1704 | | ((MSR_Value & SERIAL_MSR_RI) ? TIOCM_RI : 0) | ||
1705 | //Ring indicator set | ||
1706 | | ((MSR_Value & SERIAL_MSR_DSR) ? TIOCM_DSR : 0); | ||
1707 | //DSR is set | ||
1708 | return result; | ||
1826 | 1709 | ||
1827 | struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; | 1710 | } else |
1828 | struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); | 1711 | return -ESPIPE; |
1829 | int retval = -ENODEV; | 1712 | //endif tatus => 0 |
1830 | unsigned int UartNumber; | 1713 | } |
1831 | mydbg("In %s \n", __FUNCTION__); | ||
1832 | 1714 | ||
1833 | if (!serial) | 1715 | static int serial_ioctl(struct tty_struct *tty, struct file *file, |
1834 | return -ENODEV; | 1716 | unsigned int cmd, unsigned long arg) |
1717 | { | ||
1835 | 1718 | ||
1719 | struct usb_serial_port *port = | ||
1720 | (struct usb_serial_port *)tty->driver_data; | ||
1721 | struct usb_serial *serial = get_usb_serial(port, __FUNCTION__); | ||
1722 | int retval = -ENODEV; | ||
1723 | unsigned int UartNumber; | ||
1724 | mydbg("In %s \n", __FUNCTION__); | ||
1836 | 1725 | ||
1837 | UartNumber = port->tty->index - serial->minor; | 1726 | if (!serial) |
1727 | return -ENODEV; | ||
1838 | 1728 | ||
1729 | UartNumber = port->tty->index - serial->minor; | ||
1839 | 1730 | ||
1840 | down (&port->sem); | 1731 | down(&port->sem); |
1841 | 1732 | ||
1842 | mydbg("%s - port %d, cmd 0x%.4x\n", __FUNCTION__, port->number, cmd); | 1733 | mydbg("%s - port %d, cmd 0x%.4x\n", __FUNCTION__, port->number, cmd); |
1843 | mydbg ("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding); | 1734 | mydbg("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding); |
1844 | 1735 | ||
1845 | if (!port->open_count) | 1736 | if (!port->open_count) { |
1846 | { | 1737 | mydbg("%s - port not open\n", __FUNCTION__); |
1847 | mydbg ("%s - port not open\n", __FUNCTION__); | 1738 | goto exit; |
1848 | goto exit; | 1739 | } |
1849 | } | ||
1850 | 1740 | ||
1851 | retval = qt_ioctl(port, file, cmd, arg); | 1741 | retval = qt_ioctl(port, file, cmd, arg); |
1852 | 1742 | ||
1853 | exit: | 1743 | exit: |
1854 | up (&port->sem); | 1744 | up(&port->sem); |
1855 | return retval; | 1745 | return retval; |
1856 | } | 1746 | } |
1857 | static int qt_ioctl(struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) | 1747 | static int qt_ioctl(struct usb_serial_port *port, struct file *file, |
1748 | unsigned int cmd, unsigned long arg) | ||
1858 | { | 1749 | { |
1859 | __u8 MCR_Value; | 1750 | __u8 MCR_Value; |
1860 | __u8 MSR_Value; | 1751 | __u8 MSR_Value; |
1861 | unsigned short Prev_MSR_Value; | 1752 | unsigned short Prev_MSR_Value; |
1862 | unsigned int value, result = 0; | 1753 | unsigned int value, result = 0; |
1863 | int status; | 1754 | int status; |
1864 | unsigned int UartNumber; | 1755 | unsigned int UartNumber; |
1865 | struct tty_struct * tty; | 1756 | struct tty_struct *tty; |
1866 | 1757 | ||
1867 | 1758 | struct usb_serial *serial = get_usb_serial(port, __FUNCTION__); | |
1868 | struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); | 1759 | if (serial == NULL) |
1869 | if(serial == NULL) | 1760 | return -ENODEV; |
1870 | return -ENODEV; | 1761 | tty = port->tty; |
1871 | tty = port->tty; | ||
1872 | 1762 | ||
1873 | mydbg("%s - port %d, tty =0x%p\n", __FUNCTION__, port->number, tty); | 1763 | mydbg("%s - port %d, tty =0x%p\n", __FUNCTION__, port->number, tty); |
1874 | 1764 | ||
1875 | /**************************************************************************************/ | 1765 | /**************************************************************************************/ |
1876 | /** TIOCMGET | 1766 | /** TIOCMGET |
1877 | */ | 1767 | */ |
1878 | UartNumber = port->tty->index - serial->minor; | 1768 | UartNumber = port->tty->index - serial->minor; |
1879 | 1769 | ||
1880 | if(cmd == TIOCMGET) | 1770 | if (cmd == TIOCMGET) { |
1881 | { | 1771 | MCR_Value = port->shadowMCR; |
1882 | MCR_Value = port->shadowMCR; | 1772 | MSR_Value = port->shadowMSR; |
1883 | MSR_Value = port->shadowMSR; | 1773 | |
1884 | 1774 | { | |
1885 | { | 1775 | result = ((MCR_Value & SERIAL_MCR_DTR) ? TIOCM_DTR : 0) |
1886 | result = ((MCR_Value & SERIAL_MCR_DTR) ? TIOCM_DTR: 0) | 1776 | //DTR IS SET |
1887 | //DTR IS SET | 1777 | | ((MCR_Value & SERIAL_MCR_RTS) ? TIOCM_RTS : 0) |
1888 | | ((MCR_Value & SERIAL_MCR_RTS) ? TIOCM_RTS: 0) | 1778 | //RTS IS SET |
1889 | //RTS IS SET | 1779 | | ((MSR_Value & SERIAL_MSR_CTS) ? TIOCM_CTS : 0) |
1890 | | ((MSR_Value & SERIAL_MSR_CTS) ? TIOCM_CTS: 0) | 1780 | //CTS is set |
1891 | //CTS is set | 1781 | | ((MSR_Value & SERIAL_MSR_CD) ? TIOCM_CAR : 0) |
1892 | | ((MSR_Value & SERIAL_MSR_CD) ? TIOCM_CAR: 0) | 1782 | //Carrier detect is set |
1893 | //Carrier detect is set | 1783 | | ((MSR_Value & SERIAL_MSR_RI) ? TIOCM_RI : 0) |
1894 | | ((MSR_Value & SERIAL_MSR_RI) ? TIOCM_RI: 0) | 1784 | //Ring indicator set |
1895 | //Ring indicator set | 1785 | | ((MSR_Value & SERIAL_MSR_DSR) ? TIOCM_DSR : 0); |
1896 | | ((MSR_Value & SERIAL_MSR_DSR) ? TIOCM_DSR: 0); | 1786 | //DSR is set |
1897 | //DSR is set | 1787 | if (copy_to_user |
1898 | if(copy_to_user((unsigned int *)arg, &result, sizeof(unsigned int))) | 1788 | ((unsigned int *)arg, &result, |
1899 | return -EFAULT; | 1789 | sizeof(unsigned int))) |
1900 | return 0; | 1790 | return -EFAULT; |
1901 | 1791 | return 0; | |
1902 | }//endif tatus => 0 | 1792 | |
1903 | 1793 | } //endif tatus => 0 | |
1904 | }//endif(cmd == TIOCMGET) | 1794 | |
1795 | } //endif(cmd == TIOCMGET) | ||
1905 | /**************************************************************************************/ | 1796 | /**************************************************************************************/ |
1906 | /** End TIOCMGET | 1797 | /** End TIOCMGET |
1907 | */ | 1798 | */ |
@@ -1910,110 +1801,115 @@ static int qt_ioctl(struct usb_serial_port *port, struct file * file, unsigned i | |||
1910 | 1801 | ||
1911 | /**************************************************************************************/ | 1802 | /**************************************************************************************/ |
1912 | 1803 | ||
1913 | if(cmd == TIOCMBIS || cmd == TIOCMBIC || cmd == TIOCMSET) | 1804 | if (cmd == TIOCMBIS || cmd == TIOCMBIC || cmd == TIOCMSET) { |
1914 | { | 1805 | status = |
1915 | status = BoxGetRegister(port->serial, UartNumber, MODEM_CONTROL_REGISTER, &MCR_Value); | 1806 | BoxGetRegister(port->serial, UartNumber, |
1916 | if (status < 0) | 1807 | MODEM_CONTROL_REGISTER, &MCR_Value); |
1917 | return -ESPIPE; | 1808 | if (status < 0) |
1918 | if (copy_from_user(&value, (unsigned int *)arg, sizeof(unsigned int))) | 1809 | return -ESPIPE; |
1919 | return -EFAULT; | 1810 | if (copy_from_user |
1920 | 1811 | (&value, (unsigned int *)arg, sizeof(unsigned int))) | |
1921 | switch (cmd) | 1812 | return -EFAULT; |
1922 | { | 1813 | |
1923 | case TIOCMBIS: | 1814 | switch (cmd) { |
1924 | if (value & TIOCM_RTS) | 1815 | case TIOCMBIS: |
1925 | MCR_Value |= SERIAL_MCR_RTS; | 1816 | if (value & TIOCM_RTS) |
1926 | if (value & TIOCM_DTR) | 1817 | MCR_Value |= SERIAL_MCR_RTS; |
1927 | MCR_Value |= SERIAL_MCR_DTR; | 1818 | if (value & TIOCM_DTR) |
1928 | if (value & TIOCM_LOOP) | 1819 | MCR_Value |= SERIAL_MCR_DTR; |
1929 | MCR_Value |= SERIAL_MCR_LOOP; | 1820 | if (value & TIOCM_LOOP) |
1930 | break; | 1821 | MCR_Value |= SERIAL_MCR_LOOP; |
1931 | case TIOCMBIC: | 1822 | break; |
1932 | if (value & TIOCM_RTS) | 1823 | case TIOCMBIC: |
1933 | MCR_Value &= ~SERIAL_MCR_RTS; | 1824 | if (value & TIOCM_RTS) |
1934 | if (value & TIOCM_DTR) | 1825 | MCR_Value &= ~SERIAL_MCR_RTS; |
1935 | MCR_Value &= ~SERIAL_MCR_DTR; | 1826 | if (value & TIOCM_DTR) |
1936 | if (value & TIOCM_LOOP) | 1827 | MCR_Value &= ~SERIAL_MCR_DTR; |
1937 | MCR_Value &= ~SERIAL_MCR_LOOP; | 1828 | if (value & TIOCM_LOOP) |
1938 | break; | 1829 | MCR_Value &= ~SERIAL_MCR_LOOP; |
1939 | case TIOCMSET: | 1830 | break; |
1940 | //Turn off the RTS and DTR and loopbcck and then only | 1831 | case TIOCMSET: |
1941 | //trun on what was asked for | 1832 | //Turn off the RTS and DTR and loopbcck and then only |
1942 | MCR_Value &= ~(SERIAL_MCR_RTS | SERIAL_MCR_DTR | SERIAL_MCR_LOOP); | 1833 | //trun on what was asked for |
1943 | if (value & TIOCM_RTS) | 1834 | MCR_Value &= |
1944 | MCR_Value |= SERIAL_MCR_RTS; | 1835 | ~(SERIAL_MCR_RTS | SERIAL_MCR_DTR | |
1945 | if (value & TIOCM_DTR) | 1836 | SERIAL_MCR_LOOP); |
1946 | MCR_Value |= SERIAL_MCR_DTR; | 1837 | if (value & TIOCM_RTS) |
1947 | if (value & TIOCM_LOOP) | 1838 | MCR_Value |= SERIAL_MCR_RTS; |
1948 | MCR_Value |= SERIAL_MCR_LOOP; | 1839 | if (value & TIOCM_DTR) |
1949 | break; | 1840 | MCR_Value |= SERIAL_MCR_DTR; |
1950 | default: | 1841 | if (value & TIOCM_LOOP) |
1951 | break; | 1842 | MCR_Value |= SERIAL_MCR_LOOP; |
1952 | 1843 | break; | |
1953 | } | 1844 | default: |
1954 | status = BoxSetRegister(port->serial, UartNumber, MODEM_CONTROL_REGISTER, MCR_Value); | 1845 | break; |
1955 | if (status < 0) | 1846 | |
1956 | return -ESPIPE; | 1847 | } |
1957 | else | 1848 | status = |
1958 | { | 1849 | BoxSetRegister(port->serial, UartNumber, |
1959 | port->shadowMCR = MCR_Value; | 1850 | MODEM_CONTROL_REGISTER, MCR_Value); |
1960 | return 0; | 1851 | if (status < 0) |
1961 | } | 1852 | return -ESPIPE; |
1962 | 1853 | else { | |
1963 | 1854 | port->shadowMCR = MCR_Value; | |
1964 | } | 1855 | return 0; |
1856 | } | ||
1857 | |||
1858 | } | ||
1965 | /**************************************************************************************/ | 1859 | /**************************************************************************************/ |
1966 | /** TIOCMBIS, TIOCMBIC, AND TIOCMSET end | 1860 | /** TIOCMBIS, TIOCMBIC, AND TIOCMSET end |
1967 | */ | 1861 | */ |
1968 | /**************************************************************************************/ | 1862 | /**************************************************************************************/ |
1969 | 1863 | ||
1970 | if(cmd == TIOCMIWAIT) | 1864 | if (cmd == TIOCMIWAIT) { |
1971 | { | 1865 | DECLARE_WAITQUEUE(wait, current); |
1972 | DECLARE_WAITQUEUE(wait, current); | 1866 | Prev_MSR_Value = port->shadowMSR & SERIAL_MSR_MASK; |
1973 | Prev_MSR_Value = port->shadowMSR & SERIAL_MSR_MASK; | 1867 | while (1) { |
1974 | while(1) | 1868 | add_wait_queue(&port->wait, &wait); |
1975 | { | 1869 | set_current_state(TASK_INTERRUPTIBLE); |
1976 | add_wait_queue(&port->wait, &wait); | 1870 | schedule(); |
1977 | set_current_state(TASK_INTERRUPTIBLE); | 1871 | remove_wait_queue(&port->wait, &wait); |
1978 | schedule(); | 1872 | /* see if a signal woke us up */ |
1979 | remove_wait_queue(&port->wait, &wait); | 1873 | if (signal_pending(current)) |
1980 | /* see if a signal woke us up */ | 1874 | return -ERESTARTSYS; |
1981 | if(signal_pending(current)) | 1875 | MSR_Value = port->shadowMSR & SERIAL_MSR_MASK; |
1982 | return -ERESTARTSYS; | 1876 | if (MSR_Value == Prev_MSR_Value) |
1983 | MSR_Value = port->shadowMSR & SERIAL_MSR_MASK; | 1877 | return -EIO; //no change error |
1984 | if(MSR_Value == Prev_MSR_Value) | 1878 | |
1985 | return -EIO; //no change error | 1879 | if ((arg & TIOCM_RNG |
1986 | 1880 | && ((Prev_MSR_Value & SERIAL_MSR_RI) == | |
1987 | if((arg & TIOCM_RNG && ((Prev_MSR_Value & SERIAL_MSR_RI) == | 1881 | (MSR_Value & SERIAL_MSR_RI))) |
1988 | (MSR_Value & SERIAL_MSR_RI))) || | 1882 | || (arg & TIOCM_DSR |
1989 | (arg & TIOCM_DSR && ((Prev_MSR_Value & SERIAL_MSR_DSR) == | 1883 | && ((Prev_MSR_Value & SERIAL_MSR_DSR) == |
1990 | (MSR_Value & SERIAL_MSR_DSR))) || | 1884 | (MSR_Value & SERIAL_MSR_DSR))) |
1991 | (arg & TIOCM_CD && ((Prev_MSR_Value & SERIAL_MSR_CD) == | 1885 | || (arg & TIOCM_CD |
1992 | (MSR_Value & SERIAL_MSR_CD))) || | 1886 | && ((Prev_MSR_Value & SERIAL_MSR_CD) == |
1993 | (arg & TIOCM_CTS && ((Prev_MSR_Value & SERIAL_MSR_CTS) == | 1887 | (MSR_Value & SERIAL_MSR_CD))) |
1994 | (MSR_Value & SERIAL_MSR_CTS)))) | 1888 | || (arg & TIOCM_CTS |
1995 | { | 1889 | && ((Prev_MSR_Value & SERIAL_MSR_CTS) == |
1996 | return 0; | 1890 | (MSR_Value & SERIAL_MSR_CTS)))) { |
1997 | } | 1891 | return 0; |
1998 | 1892 | } | |
1999 | }//endwhile | 1893 | |
2000 | 1894 | } //endwhile | |
2001 | } | 1895 | |
2002 | mydbg("%s -No ioctl for that one. port = %d\n", __FUNCTION__, port->number); | 1896 | } |
2003 | 1897 | mydbg("%s -No ioctl for that one. port = %d\n", __FUNCTION__, | |
2004 | 1898 | port->number); | |
2005 | return -ENOIOCTLCMD; | 1899 | |
1900 | return -ENOIOCTLCMD; | ||
2006 | } | 1901 | } |
2007 | 1902 | ||
2008 | static void serial_set_termios (struct tty_struct *tty, struct ktermios *old) | 1903 | static void serial_set_termios(struct tty_struct *tty, struct ktermios *old) |
2009 | { | 1904 | { |
2010 | struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; | 1905 | struct usb_serial_port *port = |
2011 | struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); | 1906 | (struct usb_serial_port *)tty->driver_data; |
1907 | struct usb_serial *serial = get_usb_serial(port, __FUNCTION__); | ||
2012 | 1908 | ||
2013 | if (!serial) | 1909 | if (!serial) |
2014 | return; | 1910 | return; |
2015 | 1911 | ||
2016 | down (&port->sem); | 1912 | down(&port->sem); |
2017 | 1913 | ||
2018 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | 1914 | mydbg("%s - port %d\n", __FUNCTION__, port->number); |
2019 | 1915 | ||
@@ -2023,210 +1919,197 @@ static void serial_set_termios (struct tty_struct *tty, struct ktermios *old) | |||
2023 | } | 1919 | } |
2024 | 1920 | ||
2025 | /* pass on to the driver specific version of this function if it is available */ | 1921 | /* pass on to the driver specific version of this function if it is available */ |
2026 | qt_set_termios(port, old); | 1922 | qt_set_termios(port, old); |
2027 | 1923 | ||
2028 | exit: | 1924 | exit: |
2029 | up (&port->sem); | 1925 | up(&port->sem); |
2030 | } | 1926 | } |
2031 | 1927 | ||
2032 | static void qt_set_termios(struct usb_serial_port *port, struct ktermios *old_termios) | 1928 | static void qt_set_termios(struct usb_serial_port *port, |
1929 | struct ktermios *old_termios) | ||
2033 | { | 1930 | { |
2034 | unsigned int cflag; | 1931 | unsigned int cflag; |
2035 | int baud, divisor, remainder; | 1932 | int baud, divisor, remainder; |
2036 | unsigned char LCR_change_to = 0; | 1933 | unsigned char LCR_change_to = 0; |
2037 | struct tty_struct *tty; | 1934 | struct tty_struct *tty; |
2038 | int status; | 1935 | int status; |
2039 | struct usb_serial *serial; | 1936 | struct usb_serial *serial; |
2040 | __u16 UartNumber; | 1937 | __u16 UartNumber; |
2041 | __u16 tmp, tmp2; | 1938 | __u16 tmp, tmp2; |
2042 | 1939 | ||
2043 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | 1940 | mydbg("%s - port %d\n", __FUNCTION__, port->number); |
2044 | 1941 | ||
2045 | tmp = port->tty->index; | 1942 | tmp = port->tty->index; |
2046 | mydbg("%s - MINOR(port->tty->index) = %d\n", __FUNCTION__, tmp); | 1943 | mydbg("%s - MINOR(port->tty->index) = %d\n", __FUNCTION__, tmp); |
2047 | 1944 | ||
2048 | 1945 | serial = port->serial; | |
2049 | serial = port->serial; | 1946 | tmp2 = serial->minor; |
2050 | tmp2 = serial->minor; | 1947 | mydbg("%s - serial->minor = %d\n", __FUNCTION__, tmp2); |
2051 | mydbg("%s - serial->minor = %d\n", __FUNCTION__, tmp2); | 1948 | |
2052 | 1949 | UartNumber = port->tty->index - serial->minor; | |
2053 | 1950 | ||
2054 | 1951 | tty = port->tty; | |
2055 | UartNumber = port->tty->index - serial->minor; | 1952 | |
2056 | 1953 | cflag = tty->termios->c_cflag; | |
2057 | tty = port->tty; | 1954 | |
2058 | 1955 | if (old_termios) { | |
2059 | cflag = tty->termios->c_cflag; | 1956 | if ((cflag == old_termios->c_cflag) |
2060 | 1957 | && (RELEVANT_IFLAG(tty->termios->c_iflag) == | |
2061 | if (old_termios) | 1958 | RELEVANT_IFLAG(old_termios->c_iflag))) { |
2062 | { | 1959 | mydbg("%s - Nothing to change\n", __FUNCTION__); |
2063 | if((cflag == old_termios->c_cflag) && (RELEVANT_IFLAG(tty->termios->c_iflag) == | 1960 | return; |
2064 | RELEVANT_IFLAG(old_termios->c_iflag))) | 1961 | } |
2065 | { | 1962 | |
2066 | mydbg("%s - Nothing to change\n", __FUNCTION__); | 1963 | } |
2067 | return; | 1964 | |
2068 | } | 1965 | mydbg("%s - 3\n", __FUNCTION__); |
2069 | 1966 | ||
2070 | 1967 | switch (cflag) { | |
2071 | } | 1968 | case CS5: |
2072 | 1969 | LCR_change_to |= SERIAL_5_DATA; | |
2073 | mydbg("%s - 3\n", __FUNCTION__); | 1970 | break; |
2074 | 1971 | case CS6: | |
2075 | switch(cflag) | 1972 | LCR_change_to |= SERIAL_6_DATA; |
2076 | { | 1973 | break; |
2077 | case CS5: | 1974 | case CS7: |
2078 | LCR_change_to |= SERIAL_5_DATA; | 1975 | LCR_change_to |= SERIAL_7_DATA; |
2079 | break; | 1976 | break; |
2080 | case CS6: | 1977 | default: |
2081 | LCR_change_to |= SERIAL_6_DATA; | 1978 | case CS8: |
2082 | break; | 1979 | LCR_change_to |= SERIAL_8_DATA; |
2083 | case CS7: | 1980 | break; |
2084 | LCR_change_to |= SERIAL_7_DATA; | 1981 | } |
2085 | break; | 1982 | |
2086 | default: | 1983 | //Parity stuff |
2087 | case CS8: | 1984 | if (cflag & PARENB) { |
2088 | LCR_change_to |= SERIAL_8_DATA; | 1985 | if (cflag & PARODD) |
2089 | break; | 1986 | LCR_change_to |= SERIAL_ODD_PARITY; |
2090 | } | 1987 | else |
2091 | 1988 | LCR_change_to |= SERIAL_EVEN_PARITY; | |
2092 | //Parity stuff | 1989 | } |
2093 | if(cflag & PARENB) | 1990 | if (cflag & CSTOPB) |
2094 | { | 1991 | LCR_change_to |= SERIAL_TWO_STOPB; |
2095 | if(cflag & PARODD) | 1992 | else |
2096 | LCR_change_to |= SERIAL_ODD_PARITY; | 1993 | LCR_change_to |= SERIAL_TWO_STOPB; |
2097 | else | 1994 | |
2098 | LCR_change_to |= SERIAL_EVEN_PARITY; | 1995 | mydbg("%s - 4\n", __FUNCTION__); |
2099 | } | 1996 | //Thats the LCR stuff, go ahead and set it |
2100 | if(cflag & CSTOPB) | 1997 | baud = tty_get_baud_rate(tty); |
2101 | LCR_change_to |= SERIAL_TWO_STOPB; | 1998 | if (!baud) { |
2102 | else | 1999 | /* pick a default, any default... */ |
2103 | LCR_change_to |= SERIAL_TWO_STOPB; | 2000 | baud = 9600; |
2104 | 2001 | } | |
2105 | mydbg("%s - 4\n", __FUNCTION__); | 2002 | |
2106 | //Thats the LCR stuff, go ahead and set it | 2003 | mydbg("%s - got baud = %d\n", __FUNCTION__, baud); |
2107 | baud = tty_get_baud_rate(tty); | 2004 | |
2108 | if (!baud) { | 2005 | divisor = MAX_BAUD_RATE / baud; |
2109 | /* pick a default, any default... */ | 2006 | remainder = MAX_BAUD_RATE % baud; |
2110 | baud = 9600; | 2007 | //Round to nearest divisor |
2111 | } | 2008 | if (((remainder * 2) >= baud) && (baud != 110)) |
2112 | 2009 | divisor++; | |
2113 | mydbg("%s - got baud = %d\n", __FUNCTION__, baud); | 2010 | |
2114 | 2011 | //Set Baud rate to default and turn off (default)flow control here | |
2115 | 2012 | status = | |
2116 | divisor = MAX_BAUD_RATE / baud; | 2013 | BoxSetUart(serial, UartNumber, (unsigned short)divisor, |
2117 | remainder = MAX_BAUD_RATE % baud; | 2014 | LCR_change_to); |
2118 | //Round to nearest divisor | 2015 | if (status < 0) { |
2119 | if(((remainder * 2) >= baud) && (baud != 110)) | 2016 | mydbg(__FILE__ "BoxSetUart failed\n"); |
2120 | divisor++; | 2017 | return; |
2121 | 2018 | } | |
2122 | //Set Baud rate to default and turn off (default)flow control here | 2019 | //************************Now determine flow control |
2123 | status = BoxSetUart(serial, UartNumber, (unsigned short) divisor, LCR_change_to); | ||
2124 | if (status < 0) | ||
2125 | { | ||
2126 | mydbg(__FILE__"BoxSetUart failed\n"); | ||
2127 | return; | ||
2128 | } | ||
2129 | //************************Now determine flow control | ||
2130 | |||
2131 | if(cflag & CRTSCTS) | ||
2132 | { | ||
2133 | mydbg("%s - Enabling HW flow control port %d\n", __FUNCTION__, port->number); | ||
2134 | |||
2135 | //Enable RTS/CTS flow control | ||
2136 | status = BoxSetHW_FlowCtrl(serial, UartNumber, 1); | ||
2137 | |||
2138 | if (status < 0) | ||
2139 | { | ||
2140 | mydbg(__FILE__"BoxSetHW_FlowCtrl failed\n"); | ||
2141 | return; | ||
2142 | } | ||
2143 | } | ||
2144 | else | ||
2145 | { | ||
2146 | //Disable RTS/CTS flow control | ||
2147 | mydbg("%s - disabling HW flow control port %d\n", __FUNCTION__, port->number); | ||
2148 | |||
2149 | status = BoxSetHW_FlowCtrl(serial, UartNumber, 0); | ||
2150 | if (status < 0) | ||
2151 | { | ||
2152 | mydbg(__FILE__"BoxSetHW_FlowCtrl failed\n"); | ||
2153 | return; | ||
2154 | } | ||
2155 | |||
2156 | |||
2157 | } | ||
2158 | |||
2159 | //************************************************* | ||
2160 | /* if we are implementing XON/XOFF, set the start and stop character in the device */ | ||
2161 | if (I_IXOFF(tty) || I_IXON(tty)) | ||
2162 | { | ||
2163 | unsigned char stop_char = STOP_CHAR(tty); | ||
2164 | unsigned char start_char = START_CHAR(tty); | ||
2165 | status = BoxSetSW_FlowCtrl(serial, UartNumber, stop_char, start_char); | ||
2166 | if(status < 0) | ||
2167 | mydbg(__FILE__"BoxSetSW_FlowCtrl (enabled) failed\n"); | ||
2168 | 2020 | ||
2169 | } | 2021 | if (cflag & CRTSCTS) { |
2170 | else | 2022 | mydbg("%s - Enabling HW flow control port %d\n", __FUNCTION__, |
2171 | { | 2023 | port->number); |
2172 | //disable SW flow control | ||
2173 | status = BoxDisable_SW_FlowCtrl(serial, UartNumber); | ||
2174 | if(status < 0) | ||
2175 | mydbg(__FILE__"BoxSetSW_FlowCtrl (diabling) failed\n"); | ||
2176 | 2024 | ||
2177 | } | 2025 | //Enable RTS/CTS flow control |
2026 | status = BoxSetHW_FlowCtrl(serial, UartNumber, 1); | ||
2178 | 2027 | ||
2028 | if (status < 0) { | ||
2029 | mydbg(__FILE__ "BoxSetHW_FlowCtrl failed\n"); | ||
2030 | return; | ||
2031 | } | ||
2032 | } else { | ||
2033 | //Disable RTS/CTS flow control | ||
2034 | mydbg("%s - disabling HW flow control port %d\n", __FUNCTION__, | ||
2035 | port->number); | ||
2036 | |||
2037 | status = BoxSetHW_FlowCtrl(serial, UartNumber, 0); | ||
2038 | if (status < 0) { | ||
2039 | mydbg(__FILE__ "BoxSetHW_FlowCtrl failed\n"); | ||
2040 | return; | ||
2041 | } | ||
2042 | |||
2043 | } | ||
2179 | 2044 | ||
2045 | //************************************************* | ||
2046 | /* if we are implementing XON/XOFF, set the start and stop character in the device */ | ||
2047 | if (I_IXOFF(tty) || I_IXON(tty)) { | ||
2048 | unsigned char stop_char = STOP_CHAR(tty); | ||
2049 | unsigned char start_char = START_CHAR(tty); | ||
2050 | status = | ||
2051 | BoxSetSW_FlowCtrl(serial, UartNumber, stop_char, | ||
2052 | start_char); | ||
2053 | if (status < 0) | ||
2054 | mydbg(__FILE__ "BoxSetSW_FlowCtrl (enabled) failed\n"); | ||
2055 | |||
2056 | } else { | ||
2057 | //disable SW flow control | ||
2058 | status = BoxDisable_SW_FlowCtrl(serial, UartNumber); | ||
2059 | if (status < 0) | ||
2060 | mydbg(__FILE__ "BoxSetSW_FlowCtrl (diabling) failed\n"); | ||
2061 | |||
2062 | } | ||
2180 | 2063 | ||
2181 | } | 2064 | } |
2065 | |||
2182 | /**************************************************************************** | 2066 | /**************************************************************************** |
2183 | * BoxGetRegister | 2067 | * BoxGetRegister |
2184 | * issuse a GET_REGISTER vendor-spcific request on the default control pipe | 2068 | * issuse a GET_REGISTER vendor-spcific request on the default control pipe |
2185 | * If successful, fills in the pValue with the register value asked for | 2069 | * If successful, fills in the pValue with the register value asked for |
2186 | ****************************************************************************/ | 2070 | ****************************************************************************/ |
2187 | static int BoxGetRegister(struct usb_serial *serial, unsigned short Uart_Number, | 2071 | static int BoxGetRegister(struct usb_serial *serial, unsigned short Uart_Number, |
2188 | unsigned short Register_Num, __u8 *pValue ) | 2072 | unsigned short Register_Num, __u8 * pValue) |
2189 | { | 2073 | { |
2190 | int result; | 2074 | int result; |
2191 | __u16 current_length; | 2075 | __u16 current_length; |
2192 | |||
2193 | 2076 | ||
2194 | current_length = sizeof(struct qt_get_device_data); | 2077 | current_length = sizeof(struct qt_get_device_data); |
2195 | 2078 | ||
2196 | result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), QT_GET_SET_REGISTER, | 2079 | result = |
2197 | 0xC0, Register_Num, Uart_Number, (void *)pValue, sizeof(*pValue), 300); | 2080 | usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), |
2081 | QT_GET_SET_REGISTER, 0xC0, Register_Num, | ||
2082 | Uart_Number, (void *)pValue, sizeof(*pValue), 300); | ||
2198 | 2083 | ||
2199 | return result; | 2084 | return result; |
2200 | } | 2085 | } |
2086 | |||
2201 | /**************************************************************************** | 2087 | /**************************************************************************** |
2202 | * BoxSetRegister | 2088 | * BoxSetRegister |
2203 | * issuse a GET_REGISTER vendor-spcific request on the default control pipe | 2089 | * issuse a GET_REGISTER vendor-spcific request on the default control pipe |
2204 | * If successful, fills in the pValue with the register value asked for | 2090 | * If successful, fills in the pValue with the register value asked for |
2205 | ****************************************************************************/ | 2091 | ****************************************************************************/ |
2206 | static int BoxSetRegister(struct usb_serial *serial, unsigned short Uart_Number, | 2092 | static int BoxSetRegister(struct usb_serial *serial, unsigned short Uart_Number, |
2207 | unsigned short Register_Num, unsigned short Value ) | 2093 | unsigned short Register_Num, unsigned short Value) |
2208 | { | 2094 | { |
2209 | int result; | 2095 | int result; |
2210 | unsigned short RegAndByte; | 2096 | unsigned short RegAndByte; |
2211 | |||
2212 | 2097 | ||
2213 | RegAndByte = Value; | 2098 | RegAndByte = Value; |
2214 | RegAndByte = RegAndByte << 8; | 2099 | RegAndByte = RegAndByte << 8; |
2215 | RegAndByte = RegAndByte + Register_Num; | 2100 | RegAndByte = RegAndByte + Register_Num; |
2216 | 2101 | ||
2217 | // result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_GET_SET_REGISTER, | 2102 | // result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_GET_SET_REGISTER, |
2218 | // 0xC0, Register_Num, Uart_Number, NULL, 0, 300); | 2103 | // 0xC0, Register_Num, Uart_Number, NULL, 0, 300); |
2219 | 2104 | ||
2105 | result = | ||
2106 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | ||
2107 | QT_GET_SET_REGISTER, 0x40, RegAndByte, Uart_Number, | ||
2108 | NULL, 0, 300); | ||
2220 | 2109 | ||
2221 | result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_GET_SET_REGISTER, | 2110 | return result; |
2222 | 0x40, RegAndByte, Uart_Number, NULL,0, 300); | ||
2223 | |||
2224 | |||
2225 | return result; | ||
2226 | } | 2111 | } |
2227 | 2112 | ||
2228 | |||
2229 | |||
2230 | /** | 2113 | /** |
2231 | * box_get_device | 2114 | * box_get_device |
2232 | * Issue a GET_DEVICE vendor-specific request on the default control pipe If | 2115 | * Issue a GET_DEVICE vendor-specific request on the default control pipe If |
@@ -2261,15 +2144,16 @@ static int box_get_device(struct usb_serial *serial, | |||
2261 | * successful returns the number of bytes written, otherwise it returns a | 2144 | * successful returns the number of bytes written, otherwise it returns a |
2262 | * negative error number of the problem. | 2145 | * negative error number of the problem. |
2263 | */ | 2146 | */ |
2264 | static int box_set_device(struct usb_serial *serial, struct qt_get_device_data *device_data) | 2147 | static int box_set_device(struct usb_serial *serial, |
2148 | struct qt_get_device_data *device_data) | ||
2265 | { | 2149 | { |
2266 | int result; | 2150 | int result; |
2267 | __u16 length; | 2151 | __u16 length; |
2268 | __u16 PortSettings; | 2152 | __u16 PortSettings; |
2269 | 2153 | ||
2270 | PortSettings = ((__u16)(device_data->portb)); | 2154 | PortSettings = ((__u16) (device_data->portb)); |
2271 | PortSettings = (PortSettings << 8); | 2155 | PortSettings = (PortSettings << 8); |
2272 | PortSettings += ((__u16)(device_data->porta)); | 2156 | PortSettings += ((__u16) (device_data->porta)); |
2273 | 2157 | ||
2274 | length = sizeof(struct qt_get_device_data); | 2158 | length = sizeof(struct qt_get_device_data); |
2275 | mydbg("%s - PortSettings = 0x%x\n", __FUNCTION__, PortSettings); | 2159 | mydbg("%s - PortSettings = 0x%x\n", __FUNCTION__, PortSettings); |
@@ -2286,35 +2170,36 @@ static int box_set_device(struct usb_serial *serial, struct qt_get_device_data * | |||
2286 | * purpose is to allow the device driver and the device to synchronize state information. | 2170 | * purpose is to allow the device driver and the device to synchronize state information. |
2287 | * OpenClose = 1 for open , 0 for close | 2171 | * OpenClose = 1 for open , 0 for close |
2288 | ****************************************************************************/ | 2172 | ****************************************************************************/ |
2289 | static int BoxOPenCloseChannel(struct usb_serial *serial, __u16 Uart_Number, __u16 OpenClose, struct qt_open_channel_data *pDeviceData) | 2173 | static int BoxOPenCloseChannel(struct usb_serial *serial, __u16 Uart_Number, |
2174 | __u16 OpenClose, | ||
2175 | struct qt_open_channel_data *pDeviceData) | ||
2290 | { | 2176 | { |
2291 | int result; | 2177 | int result; |
2292 | __u16 length; | 2178 | __u16 length; |
2293 | __u8 Direcion; | 2179 | __u8 Direcion; |
2294 | unsigned int pipe; | 2180 | unsigned int pipe; |
2295 | length = sizeof(struct qt_open_channel_data); | 2181 | length = sizeof(struct qt_open_channel_data); |
2296 | |||
2297 | if (OpenClose == 1) //IF OPENING | ||
2298 | { | ||
2299 | Direcion = USBD_TRANSFER_DIRECTION_IN; | ||
2300 | pipe = usb_rcvctrlpipe(serial->dev, 0); | ||
2301 | result = usb_control_msg (serial->dev, pipe, QT_OPEN_CLOSE_CHANNEL, | ||
2302 | Direcion, OpenClose, Uart_Number, pDeviceData, length, 300); | ||
2303 | |||
2304 | |||
2305 | } | ||
2306 | else | ||
2307 | { | ||
2308 | Direcion = USBD_TRANSFER_DIRECTION_OUT; | ||
2309 | pipe = usb_sndctrlpipe(serial->dev, 0); | ||
2310 | result = usb_control_msg (serial->dev, pipe, QT_OPEN_CLOSE_CHANNEL, | ||
2311 | Direcion, OpenClose, Uart_Number, NULL, 0, 300); | ||
2312 | |||
2313 | } | ||
2314 | 2182 | ||
2183 | if (OpenClose == 1) //IF OPENING | ||
2184 | { | ||
2185 | Direcion = USBD_TRANSFER_DIRECTION_IN; | ||
2186 | pipe = usb_rcvctrlpipe(serial->dev, 0); | ||
2187 | result = | ||
2188 | usb_control_msg(serial->dev, pipe, QT_OPEN_CLOSE_CHANNEL, | ||
2189 | Direcion, OpenClose, Uart_Number, | ||
2190 | pDeviceData, length, 300); | ||
2191 | |||
2192 | } else { | ||
2193 | Direcion = USBD_TRANSFER_DIRECTION_OUT; | ||
2194 | pipe = usb_sndctrlpipe(serial->dev, 0); | ||
2195 | result = | ||
2196 | usb_control_msg(serial->dev, pipe, QT_OPEN_CLOSE_CHANNEL, | ||
2197 | Direcion, OpenClose, Uart_Number, NULL, 0, | ||
2198 | 300); | ||
2315 | 2199 | ||
2200 | } | ||
2316 | 2201 | ||
2317 | return result; | 2202 | return result; |
2318 | } | 2203 | } |
2319 | 2204 | ||
2320 | /**************************************************************************** | 2205 | /**************************************************************************** |
@@ -2333,24 +2218,22 @@ static int BoxSetPrebufferLevel(struct usb_serial *serial) | |||
2333 | return result; | 2218 | return result; |
2334 | } | 2219 | } |
2335 | 2220 | ||
2336 | |||
2337 | |||
2338 | /**************************************************************************** | 2221 | /**************************************************************************** |
2339 | * BoxSetATC | 2222 | * BoxSetATC |
2340 | TELLS BOX WHEN TO ASSERT automatic transmitter control | 2223 | TELLS BOX WHEN TO ASSERT automatic transmitter control |
2341 | ****************************************************************************/ | 2224 | ****************************************************************************/ |
2342 | static int BoxSetATC(struct usb_serial *serial, __u16 n_Mode) | 2225 | static int BoxSetATC(struct usb_serial *serial, __u16 n_Mode) |
2343 | { | 2226 | { |
2344 | int result; | 2227 | int result; |
2345 | __u16 buffer_length; | 2228 | __u16 buffer_length; |
2346 | |||
2347 | 2229 | ||
2348 | buffer_length = PREFUFF_LEVEL_CONSERVATIVE; | 2230 | buffer_length = PREFUFF_LEVEL_CONSERVATIVE; |
2349 | 2231 | ||
2350 | result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_SET_ATF, | 2232 | result = |
2351 | 0x40, n_Mode, 0, NULL, 0, 300); | 2233 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
2234 | QT_SET_ATF, 0x40, n_Mode, 0, NULL, 0, 300); | ||
2352 | 2235 | ||
2353 | return result; | 2236 | return result; |
2354 | } | 2237 | } |
2355 | 2238 | ||
2356 | /**************************************************************************** | 2239 | /**************************************************************************** |
@@ -2358,184 +2241,182 @@ static int BoxSetATC(struct usb_serial *serial, __u16 n_Mode) | |||
2358 | * issuse a SET_UART vendor-spcific request on the default control pipe | 2241 | * issuse a SET_UART vendor-spcific request on the default control pipe |
2359 | * If successful sets baud rate divisor and LCR value | 2242 | * If successful sets baud rate divisor and LCR value |
2360 | ****************************************************************************/ | 2243 | ****************************************************************************/ |
2361 | static int BoxSetUart(struct usb_serial *serial, unsigned short Uart_Number, | 2244 | static int BoxSetUart(struct usb_serial *serial, unsigned short Uart_Number, |
2362 | unsigned short default_divisor, unsigned char default_LCR ) | 2245 | unsigned short default_divisor, unsigned char default_LCR) |
2363 | { | 2246 | { |
2364 | int result; | 2247 | int result; |
2365 | unsigned short UartNumandLCR; | 2248 | unsigned short UartNumandLCR; |
2366 | 2249 | ||
2367 | UartNumandLCR = (default_LCR << 8) + Uart_Number; | 2250 | UartNumandLCR = (default_LCR << 8) + Uart_Number; |
2368 | 2251 | ||
2369 | result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_GET_SET_UART, | 2252 | result = |
2370 | 0x40, default_divisor, UartNumandLCR, NULL, 0, 300); | 2253 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
2254 | QT_GET_SET_UART, 0x40, default_divisor, | ||
2255 | UartNumandLCR, NULL, 0, 300); | ||
2371 | 2256 | ||
2372 | return result; | 2257 | return result; |
2373 | } | 2258 | } |
2374 | 2259 | ||
2375 | 2260 | static int BoxSetHW_FlowCtrl(struct usb_serial *serial, unsigned int UartNumber, | |
2376 | static int BoxSetHW_FlowCtrl(struct usb_serial *serial, unsigned int UartNumber, int bSet) | 2261 | int bSet) |
2377 | { | 2262 | { |
2378 | __u8 MCR_Value = 0; | 2263 | __u8 MCR_Value = 0; |
2379 | __u8 MSR_Value = 0, MOUT_Value = 0; | 2264 | __u8 MSR_Value = 0, MOUT_Value = 0; |
2380 | struct usb_serial_port *port; | 2265 | struct usb_serial_port *port; |
2381 | unsigned int status; | 2266 | unsigned int status; |
2382 | 2267 | ||
2383 | port = serial->port; | 2268 | port = serial->port; |
2384 | 2269 | ||
2385 | if (bSet == 1) | 2270 | if (bSet == 1) { |
2386 | { | 2271 | MCR_Value = SERIAL_MCR_RTS; //flow control, box will clear RTS line to prevent remote |
2387 | MCR_Value = SERIAL_MCR_RTS; //flow control, box will clear RTS line to prevent remote | 2272 | } //device from xmitting more chars |
2388 | } //device from xmitting more chars | 2273 | else { //no flow control to remote device |
2389 | else | 2274 | MCR_Value = 0; |
2390 | { //no flow control to remote device | ||
2391 | MCR_Value = 0; | ||
2392 | 2275 | ||
2393 | } | 2276 | } |
2394 | MOUT_Value = MCR_Value << 8; | 2277 | MOUT_Value = MCR_Value << 8; |
2395 | |||
2396 | |||
2397 | if(bSet == 1) | ||
2398 | { | ||
2399 | MSR_Value = SERIAL_MSR_CTS; //flow control, box will inhibit xmit data if CTS line is asserted | ||
2400 | } | ||
2401 | else | ||
2402 | { | ||
2403 | MSR_Value = 0; //Box will not inhimbe xmit data due to CTS line | ||
2404 | } | ||
2405 | MOUT_Value |= MSR_Value; | ||
2406 | 2278 | ||
2279 | if (bSet == 1) { | ||
2280 | MSR_Value = SERIAL_MSR_CTS; //flow control, box will inhibit xmit data if CTS line is asserted | ||
2281 | } else { | ||
2282 | MSR_Value = 0; //Box will not inhimbe xmit data due to CTS line | ||
2283 | } | ||
2284 | MOUT_Value |= MSR_Value; | ||
2407 | 2285 | ||
2408 | status = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_HW_FLOW_CONTROL_MASK, | 2286 | status = |
2409 | 0x40, MOUT_Value, UartNumber, NULL, 0, 300); | 2287 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
2410 | return status; | 2288 | QT_HW_FLOW_CONTROL_MASK, 0x40, MOUT_Value, |
2289 | UartNumber, NULL, 0, 300); | ||
2290 | return status; | ||
2411 | 2291 | ||
2412 | } | 2292 | } |
2413 | 2293 | ||
2414 | static int BoxSetSW_FlowCtrl(struct usb_serial *serial, __u16 UartNumber, unsigned char stop_char, unsigned char start_char) | 2294 | static int BoxSetSW_FlowCtrl(struct usb_serial *serial, __u16 UartNumber, |
2295 | unsigned char stop_char, unsigned char start_char) | ||
2415 | { | 2296 | { |
2416 | __u16 nSWflowout; | 2297 | __u16 nSWflowout; |
2417 | int result; | 2298 | int result; |
2418 | 2299 | ||
2419 | nSWflowout = start_char << 8; | 2300 | nSWflowout = start_char << 8; |
2420 | nSWflowout = (unsigned short)stop_char; | 2301 | nSWflowout = (unsigned short)stop_char; |
2421 | 2302 | ||
2422 | result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_SW_FLOW_CONTROL_MASK, | 2303 | result = |
2423 | 0x40, nSWflowout, UartNumber, NULL, 0, 300); | 2304 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
2424 | return result; | 2305 | QT_SW_FLOW_CONTROL_MASK, 0x40, nSWflowout, |
2306 | UartNumber, NULL, 0, 300); | ||
2307 | return result; | ||
2425 | 2308 | ||
2426 | } | 2309 | } |
2427 | static int BoxDisable_SW_FlowCtrl(struct usb_serial *serial, __u16 UartNumber) | 2310 | static int BoxDisable_SW_FlowCtrl(struct usb_serial *serial, __u16 UartNumber) |
2428 | { | 2311 | { |
2429 | int result; | 2312 | int result; |
2430 | |||
2431 | 2313 | ||
2432 | result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_SW_FLOW_CONTROL_DISABLE, | 2314 | result = |
2433 | 0x40, 0, UartNumber, NULL, 0, 300); | 2315 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
2434 | return result; | 2316 | QT_SW_FLOW_CONTROL_DISABLE, 0x40, 0, UartNumber, |
2317 | NULL, 0, 300); | ||
2318 | return result; | ||
2435 | 2319 | ||
2436 | } | 2320 | } |
2437 | 2321 | ||
2438 | |||
2439 | /***************************************************************************** | 2322 | /***************************************************************************** |
2440 | * SerialThrottle | 2323 | * SerialThrottle |
2441 | * this function is called by the tty driver when it wants to stop the data | 2324 | * this function is called by the tty driver when it wants to stop the data |
2442 | * being read from the port. | 2325 | * being read from the port. |
2443 | *****************************************************************************/ | 2326 | *****************************************************************************/ |
2444 | 2327 | ||
2445 | 2328 | static void serial_throttle(struct tty_struct *tty) | |
2446 | static void serial_throttle (struct tty_struct * tty) | ||
2447 | { | 2329 | { |
2448 | struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; | 2330 | struct usb_serial_port *port = |
2449 | struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); | 2331 | (struct usb_serial_port *)tty->driver_data; |
2450 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | 2332 | struct usb_serial *serial = get_usb_serial(port, __FUNCTION__); |
2333 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | ||
2451 | 2334 | ||
2452 | if (!serial) | 2335 | if (!serial) |
2453 | return; | 2336 | return; |
2454 | 2337 | ||
2455 | down (&port->sem); | 2338 | down(&port->sem); |
2456 | |||
2457 | 2339 | ||
2458 | if (!port->open_count) { | 2340 | if (!port->open_count) { |
2459 | mydbg ("%s - port not open\n", __FUNCTION__); | 2341 | mydbg("%s - port not open\n", __FUNCTION__); |
2460 | goto exit; | 2342 | goto exit; |
2461 | } | 2343 | } |
2462 | //shut down any bulk reads that may be going on | 2344 | //shut down any bulk reads that may be going on |
2463 | // usb_unlink_urb (port->read_urb); | 2345 | // usb_unlink_urb (port->read_urb); |
2464 | /* pass on to the driver specific version of this function */ | 2346 | /* pass on to the driver specific version of this function */ |
2465 | port->RxHolding = 1; | 2347 | port->RxHolding = 1; |
2466 | mydbg("%s - port->RxHolding = 1\n", __FUNCTION__); | 2348 | mydbg("%s - port->RxHolding = 1\n", __FUNCTION__); |
2467 | |||
2468 | 2349 | ||
2469 | exit: | 2350 | exit: |
2470 | up (&port->sem); | 2351 | up(&port->sem); |
2471 | return; | 2352 | return; |
2472 | } | 2353 | } |
2473 | 2354 | ||
2474 | static void serial_unthrottle (struct tty_struct * tty) | 2355 | static void serial_unthrottle(struct tty_struct *tty) |
2475 | { | 2356 | { |
2476 | struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; | 2357 | struct usb_serial_port *port = |
2477 | struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); | 2358 | (struct usb_serial_port *)tty->driver_data; |
2478 | unsigned int result; | 2359 | struct usb_serial *serial = get_usb_serial(port, __FUNCTION__); |
2360 | unsigned int result; | ||
2479 | 2361 | ||
2480 | if (!serial) | 2362 | if (!serial) |
2481 | return; | 2363 | return; |
2482 | down (&port->sem); | 2364 | down(&port->sem); |
2483 | 2365 | ||
2484 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | 2366 | mydbg("%s - port %d\n", __FUNCTION__, port->number); |
2485 | 2367 | ||
2486 | if (!port->open_count) { | 2368 | if (!port->open_count) { |
2487 | mydbg ("%s - port not open\n", __FUNCTION__); | 2369 | mydbg("%s - port not open\n", __FUNCTION__); |
2488 | goto exit; | 2370 | goto exit; |
2489 | } | 2371 | } |
2490 | 2372 | ||
2491 | if(port->RxHolding == 1) | 2373 | if (port->RxHolding == 1) { |
2492 | { | 2374 | mydbg("%s -port->RxHolding == 1\n", __FUNCTION__); |
2493 | mydbg ("%s -port->RxHolding == 1\n", __FUNCTION__); | 2375 | |
2494 | 2376 | port->RxHolding = 0; | |
2495 | port->RxHolding = 0; | 2377 | mydbg("%s - port->RxHolding = 0\n", __FUNCTION__); |
2496 | mydbg ("%s - port->RxHolding = 0\n", __FUNCTION__); | 2378 | |
2497 | 2379 | /* if we have a bulk endpoint, start it up */ | |
2498 | /* if we have a bulk endpoint, start it up */ | 2380 | if ((serial->num_bulk_in) && (port->ReadBulkStopped == 1)) { |
2499 | if ((serial->num_bulk_in) && (port->ReadBulkStopped == 1)) | 2381 | /* Start reading from the device */ |
2500 | { | 2382 | usb_fill_bulk_urb(port->read_urb, serial->dev, |
2501 | /* Start reading from the device */ | 2383 | usb_rcvbulkpipe(serial->dev, |
2502 | usb_fill_bulk_urb (port->read_urb, serial->dev, | 2384 | port-> |
2503 | usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), | 2385 | bulk_in_endpointAddress), |
2504 | port->read_urb->transfer_buffer, | 2386 | port->read_urb->transfer_buffer, |
2505 | port->read_urb->transfer_buffer_length, | 2387 | port->read_urb-> |
2506 | qt_read_bulk_callback, | 2388 | transfer_buffer_length, |
2507 | port); | 2389 | qt_read_bulk_callback, port); |
2508 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); | 2390 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); |
2509 | if (result) | 2391 | if (result) |
2510 | err("%s - failed restarting read urb, error %d", __FUNCTION__, result); | 2392 | err("%s - failed restarting read urb, error %d", |
2511 | } | 2393 | __FUNCTION__, result); |
2512 | } | 2394 | } |
2513 | exit: | 2395 | } |
2514 | up (&port->sem); | 2396 | exit: |
2515 | return; | 2397 | up(&port->sem); |
2516 | 2398 | return; | |
2517 | |||
2518 | 2399 | ||
2519 | } | 2400 | } |
2520 | 2401 | ||
2521 | 2402 | static int serial_break(struct tty_struct *tty, int break_state) | |
2522 | static int serial_break (struct tty_struct *tty, int break_state) | ||
2523 | { | 2403 | { |
2524 | struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; | 2404 | struct usb_serial_port *port = |
2525 | struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); | 2405 | (struct usb_serial_port *)tty->driver_data; |
2526 | __u16 UartNumber, Break_Value; | 2406 | struct usb_serial *serial = get_usb_serial(port, __FUNCTION__); |
2527 | unsigned int result; | 2407 | __u16 UartNumber, Break_Value; |
2408 | unsigned int result; | ||
2528 | 2409 | ||
2529 | UartNumber = port->tty->index - serial->minor; | 2410 | UartNumber = port->tty->index - serial->minor; |
2530 | if (!serial) | 2411 | if (!serial) |
2531 | return -ENODEV; | 2412 | return -ENODEV; |
2532 | 2413 | ||
2533 | if(break_state == -1) | 2414 | if (break_state == -1) |
2534 | Break_Value = 1; | 2415 | Break_Value = 1; |
2535 | else | 2416 | else |
2536 | Break_Value = 0; | 2417 | Break_Value = 0; |
2537 | 2418 | ||
2538 | down (&port->sem); | 2419 | down(&port->sem); |
2539 | 2420 | ||
2540 | mydbg("%s - port %d\n", __FUNCTION__, port->number); | 2421 | mydbg("%s - port %d\n", __FUNCTION__, port->number); |
2541 | 2422 | ||
@@ -2544,18 +2425,18 @@ static int serial_break (struct tty_struct *tty, int break_state) | |||
2544 | goto exit; | 2425 | goto exit; |
2545 | } | 2426 | } |
2546 | 2427 | ||
2547 | result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_BREAK_CONTROL, | 2428 | result = |
2548 | 0x40, Break_Value, UartNumber, NULL, 0, 300); | 2429 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
2430 | QT_BREAK_CONTROL, 0x40, Break_Value, UartNumber, | ||
2431 | NULL, 0, 300); | ||
2549 | 2432 | ||
2550 | exit: | 2433 | exit: |
2551 | up (&port->sem); | 2434 | up(&port->sem); |
2552 | return 0; | 2435 | return 0; |
2553 | } | 2436 | } |
2554 | 2437 | ||
2555 | 2438 | static int serial_read_proc(char *page, char **start, off_t off, int count, | |
2556 | 2439 | int *eof, void *data) | |
2557 | |||
2558 | static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
2559 | { | 2440 | { |
2560 | struct usb_serial *serial; | 2441 | struct usb_serial *serial; |
2561 | int length = 0; | 2442 | int length = 0; |
@@ -2563,21 +2444,26 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int | |||
2563 | off_t begin = 0; | 2444 | off_t begin = 0; |
2564 | 2445 | ||
2565 | mydbg("%s\n", __FUNCTION__); | 2446 | mydbg("%s\n", __FUNCTION__); |
2566 | length += sprintf (page, "usbserinfo:1.0 driver:%s\n", DRIVER_VERSION); | 2447 | length += sprintf(page, "usbserinfo:1.0 driver:%s\n", DRIVER_VERSION); |
2567 | for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) { | 2448 | for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) { |
2568 | serial = get_serial_by_minor(i); | 2449 | serial = get_serial_by_minor(i); |
2569 | if (serial == NULL) | 2450 | if (serial == NULL) |
2570 | continue; | 2451 | continue; |
2571 | 2452 | ||
2572 | length += sprintf (page+length, "%d:\n", i); | 2453 | length += sprintf(page + length, "%d:\n", i); |
2573 | length += sprintf (page+length, " vendor:%04x product:%04x\n", serial->vendor, serial->product); | 2454 | length += |
2574 | length += sprintf (page+length, " num_ports:%d\n", serial->num_ports); | 2455 | sprintf(page + length, " vendor:%04x product:%04x\n", |
2575 | length += sprintf (page+length, " port:%d\n", i - serial->minor + 1); | 2456 | serial->vendor, serial->product); |
2457 | length += | ||
2458 | sprintf(page + length, " num_ports:%d\n", | ||
2459 | serial->num_ports); | ||
2460 | length += | ||
2461 | sprintf(page + length, " port:%d\n", i - serial->minor + 1); | ||
2576 | 2462 | ||
2577 | // usb_make_path(serial->dev, tmp, sizeof(tmp)); | 2463 | // usb_make_path(serial->dev, tmp, sizeof(tmp)); |
2578 | // length += sprintf (page+length, " path:%s", tmp); | 2464 | // length += sprintf (page+length, " path:%s", tmp); |
2579 | 2465 | ||
2580 | length += sprintf (page+length, "\n"); | 2466 | length += sprintf(page + length, "\n"); |
2581 | if ((length + begin) > (off + count)) | 2467 | if ((length + begin) > (off + count)) |
2582 | goto done; | 2468 | goto done; |
2583 | if ((length + begin) < off) { | 2469 | if ((length + begin) < off) { |
@@ -2589,348 +2475,323 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int | |||
2589 | done: | 2475 | done: |
2590 | if (off >= (length + begin)) | 2476 | if (off >= (length + begin)) |
2591 | return 0; | 2477 | return 0; |
2592 | *start = page + (off-begin); | 2478 | *start = page + (off - begin); |
2593 | return ((count < begin+length-off) ? count : begin+length-off); | 2479 | return ((count < begin + length - off) ? count : begin + length - off); |
2594 | } | 2480 | } |
2595 | 2481 | ||
2596 | 2482 | int ioctl_serial_usb(struct inode *innod, struct file *filp, unsigned int cmd, | |
2597 | 2483 | unsigned long arg) | |
2598 | int ioctl_serial_usb (struct inode *innod, struct file *filp, unsigned int cmd, | ||
2599 | unsigned long arg) | ||
2600 | { | 2484 | { |
2601 | 2485 | ||
2602 | unsigned err; | 2486 | unsigned err; |
2603 | unsigned ucOPR_NewValue, uc_Value; | 2487 | unsigned ucOPR_NewValue, uc_Value; |
2604 | int *p_Num_of_adapters, counts, index, *p_QMCR_Value; | 2488 | int *p_Num_of_adapters, counts, index, *p_QMCR_Value; |
2605 | struct identity *p_Identity_of; | 2489 | struct identity *p_Identity_of; |
2606 | struct identity Identity_of; | 2490 | struct identity Identity_of; |
2607 | struct usb_serial *lastserial, *serial; | 2491 | struct usb_serial *lastserial, *serial; |
2608 | 2492 | ||
2609 | mydbg(KERN_DEBUG"ioctl_serial_usb cmd =\n"); | 2493 | mydbg(KERN_DEBUG "ioctl_serial_usb cmd =\n"); |
2610 | if (_IOC_TYPE(cmd) != SERIALQT_PCI_IOC_MAGIC) | 2494 | if (_IOC_TYPE(cmd) != SERIALQT_PCI_IOC_MAGIC) |
2611 | return -ENOTTY; | 2495 | return -ENOTTY; |
2612 | if (_IOC_NR(cmd) > SERIALQT_IOC_MAXNR) | 2496 | if (_IOC_NR(cmd) > SERIALQT_IOC_MAXNR) |
2613 | return -ENOTTY; | 2497 | return -ENOTTY; |
2614 | mydbg(KERN_DEBUG"ioctl_serial_usb cmd = 0x%x\n", cmd); | 2498 | mydbg(KERN_DEBUG "ioctl_serial_usb cmd = 0x%x\n", cmd); |
2615 | err = 0; | 2499 | err = 0; |
2616 | switch (cmd) | 2500 | switch (cmd) { |
2617 | { | 2501 | |
2618 | 2502 | case SERIALQT_WRITE_QMCR: | |
2619 | 2503 | err = -ENOTTY; //initialize as error so if we don't find this one we give//an error. | |
2620 | case SERIALQT_WRITE_QMCR: | 2504 | index = arg >> 16; |
2621 | err = -ENOTTY; //initialize as error so if we don't find this one we give//an error. | 2505 | counts = 0; |
2622 | index = arg >> 16; | 2506 | |
2623 | counts = 0; | 2507 | ucOPR_NewValue = arg; |
2624 | 2508 | ||
2625 | ucOPR_NewValue = arg; | 2509 | err = EmulateWriteQMCR_Reg(index, ucOPR_NewValue); |
2626 | 2510 | break; | |
2627 | 2511 | ||
2628 | err = EmulateWriteQMCR_Reg(index, ucOPR_NewValue); | 2512 | case SERIALQT_READ_QMCR: |
2629 | break; | 2513 | err = -ENOTTY; //initialize as error so if we don't find this one we give |
2630 | 2514 | //an error. | |
2631 | case SERIALQT_READ_QMCR: | 2515 | p_QMCR_Value = (int *)arg; |
2632 | err = -ENOTTY; //initialize as error so if we don't find this one we give | 2516 | index = arg >> 16; |
2633 | //an error. | 2517 | counts = 0; |
2634 | p_QMCR_Value = (int *)arg; | 2518 | |
2635 | index = arg >> 16; | 2519 | err = EmulateReadQMCR_Reg(index, &uc_Value); |
2636 | counts = 0; | 2520 | if (err == 0) { |
2637 | 2521 | err = put_user(uc_Value, p_QMCR_Value); | |
2638 | 2522 | } | |
2639 | 2523 | break; | |
2640 | err = EmulateReadQMCR_Reg(index, &uc_Value); | 2524 | |
2641 | if (err == 0) | 2525 | case SERIALQT_GET_NUMOF_UNITS: |
2642 | { | 2526 | p_Num_of_adapters = (int *)arg; |
2643 | err = put_user(uc_Value, p_QMCR_Value); | 2527 | counts = 0; //Initialize counts to zero |
2644 | } | 2528 | //struct usb_serial *lastserial = serial_table[0], *serial; |
2645 | break; | 2529 | lastserial = serial_table[0]; |
2646 | 2530 | ||
2647 | case SERIALQT_GET_NUMOF_UNITS: | 2531 | mydbg(KERN_DEBUG "SERIALQT_GET_NUMOF_UNITS \n"); |
2648 | p_Num_of_adapters = (int *)arg; | 2532 | //if first pointer is nonull, we at least have one box |
2649 | counts = 0; //Initialize counts to zero | 2533 | if (lastserial) |
2650 | //struct usb_serial *lastserial = serial_table[0], *serial; | 2534 | counts = 1; //we at least have one box |
2651 | lastserial = serial_table[0]; | 2535 | |
2652 | 2536 | for (index = 1; index < SERIAL_TTY_MINORS; index++) { | |
2653 | mydbg(KERN_DEBUG"SERIALQT_GET_NUMOF_UNITS \n"); | 2537 | serial = serial_table[index]; |
2654 | //if first pointer is nonull, we at least have one box | 2538 | if (serial) { |
2655 | if(lastserial) | 2539 | if (serial != lastserial) { |
2656 | counts = 1; //we at least have one box | 2540 | //we had a change in the array, hence another box is there |
2657 | 2541 | lastserial = serial; | |
2658 | for (index = 1; index < SERIAL_TTY_MINORS ; index++) | 2542 | counts++; |
2659 | { | 2543 | } |
2660 | serial = serial_table[index]; | 2544 | } else |
2661 | if(serial) | 2545 | break; |
2662 | { | 2546 | } |
2663 | if(serial != lastserial) | ||
2664 | { | ||
2665 | //we had a change in the array, hence another box is there | ||
2666 | lastserial = serial; | ||
2667 | counts++; | ||
2668 | } | ||
2669 | } | ||
2670 | else | ||
2671 | break; | ||
2672 | } | ||
2673 | |||
2674 | mydbg(KERN_DEBUG"ioctl_serial_usb writting counts = %d", counts); | ||
2675 | |||
2676 | err = put_user(counts, p_Num_of_adapters); | ||
2677 | |||
2678 | |||
2679 | break; | ||
2680 | case SERIALQT_GET_THIS_UNIT: | ||
2681 | counts = 0; | ||
2682 | p_Identity_of = (struct identity *)arg; | ||
2683 | //copy user structure to local variable | ||
2684 | get_user(Identity_of.index, &p_Identity_of->index); | ||
2685 | mydbg(KERN_DEBUG"SERIALQT_GET_THIS_UNIT Identity_of.index\n"); | ||
2686 | mydbg(KERN_DEBUG"SERIALQT_GET_THIS_UNIT Identity_of.index= 0x%x\n", Identity_of.index); | ||
2687 | |||
2688 | err = -ENOTTY; //initialize as error so if we don't find this one we give | ||
2689 | //an error. | ||
2690 | serial = find_the_box(Identity_of.index); | ||
2691 | if(serial) | ||
2692 | { | ||
2693 | err = put_user(serial->product, &p_Identity_of->n_identity); | ||
2694 | 2547 | ||
2695 | } | 2548 | mydbg(KERN_DEBUG "ioctl_serial_usb writting counts = %d", |
2696 | break; | 2549 | counts); |
2550 | |||
2551 | err = put_user(counts, p_Num_of_adapters); | ||
2552 | |||
2553 | break; | ||
2554 | case SERIALQT_GET_THIS_UNIT: | ||
2555 | counts = 0; | ||
2556 | p_Identity_of = (struct identity *)arg; | ||
2557 | //copy user structure to local variable | ||
2558 | get_user(Identity_of.index, &p_Identity_of->index); | ||
2559 | mydbg(KERN_DEBUG "SERIALQT_GET_THIS_UNIT Identity_of.index\n"); | ||
2560 | mydbg(KERN_DEBUG | ||
2561 | "SERIALQT_GET_THIS_UNIT Identity_of.index= 0x%x\n", | ||
2562 | Identity_of.index); | ||
2563 | |||
2564 | err = -ENOTTY; //initialize as error so if we don't find this one we give | ||
2565 | //an error. | ||
2566 | serial = find_the_box(Identity_of.index); | ||
2567 | if (serial) { | ||
2568 | err = | ||
2569 | put_user(serial->product, | ||
2570 | &p_Identity_of->n_identity); | ||
2697 | 2571 | ||
2698 | case SERIALQT_IS422_EXTENDED: | 2572 | } |
2699 | err = -ENOTTY; //initialize as error so if we don't find this one we give | 2573 | break; |
2700 | mydbg(KERN_DEBUG"SERIALQT_IS422_EXTENDED \n"); | 2574 | |
2701 | //an error. | 2575 | case SERIALQT_IS422_EXTENDED: |
2702 | index = arg >> 16; | 2576 | err = -ENOTTY; //initialize as error so if we don't find this one we give |
2577 | mydbg(KERN_DEBUG "SERIALQT_IS422_EXTENDED \n"); | ||
2578 | //an error. | ||
2579 | index = arg >> 16; | ||
2580 | |||
2581 | counts = 0; | ||
2582 | |||
2583 | mydbg(KERN_DEBUG | ||
2584 | "SERIALQT_IS422_EXTENDED, looking Identity_of.indext = 0x%x\n", | ||
2585 | index); | ||
2586 | serial = find_the_box(index); | ||
2587 | if (serial) { | ||
2588 | mydbg("%s index = 0x%x, serial = 0x%p\n", __FUNCTION__, | ||
2589 | index, serial); | ||
2590 | for (counts = 0; serqt_422_table[counts] != 0; counts++) { | ||
2591 | |||
2592 | mydbg | ||
2593 | ("%s serial->product = = 0x%x, serqt_422_table[counts] = 0x%x\n", | ||
2594 | __FUNCTION__, serial->product, | ||
2595 | serqt_422_table[counts]); | ||
2596 | if (serial->product == serqt_422_table[counts]) { | ||
2597 | err = 0; | ||
2598 | |||
2599 | mydbg | ||
2600 | ("%s found match for 422extended\n", | ||
2601 | __FUNCTION__); | ||
2602 | break; | ||
2603 | } | ||
2604 | } | ||
2605 | } | ||
2606 | break; | ||
2703 | 2607 | ||
2608 | default: | ||
2609 | err = -ENOTTY; | ||
2704 | 2610 | ||
2705 | counts = 0; | 2611 | } //End switch |
2706 | 2612 | ||
2707 | mydbg(KERN_DEBUG"SERIALQT_IS422_EXTENDED, looking Identity_of.indext = 0x%x\n",index); | 2613 | mydbg("%s returning err = 0x%x\n", __FUNCTION__, err); |
2708 | serial = find_the_box(index); | 2614 | return err; |
2709 | if(serial) | 2615 | } |
2710 | { | ||
2711 | mydbg("%s index = 0x%x, serial = 0x%p\n", __FUNCTION__, index, serial); | ||
2712 | for (counts = 0; serqt_422_table[counts] != 0; counts++) | ||
2713 | { | ||
2714 | 2616 | ||
2715 | mydbg("%s serial->product = = 0x%x, serqt_422_table[counts] = 0x%x\n", __FUNCTION__, serial->product, serqt_422_table[counts]); | 2617 | static struct usb_serial *find_the_box(unsigned int index) |
2716 | if(serial->product == serqt_422_table[counts]) | 2618 | { |
2717 | { | 2619 | struct usb_serial *lastserial, *foundserial, *serial; |
2718 | err = 0; | 2620 | int counts = 0, index2; |
2621 | lastserial = serial_table[0]; | ||
2622 | foundserial = NULL; | ||
2623 | for (index2 = 0; index2 < SERIAL_TTY_MINORS; index2++) { | ||
2624 | serial = serial_table[index2]; | ||
2625 | |||
2626 | mydbg("%s index = 0x%x, index2 = 0x%x, serial = 0x%p\n", | ||
2627 | __FUNCTION__, index, index2, serial); | ||
2628 | |||
2629 | if (serial) { | ||
2630 | //first see if this is the unit we'er looking for | ||
2631 | mydbg | ||
2632 | ("%s inside if(serial) counts = 0x%x , index = 0x%x\n", | ||
2633 | __FUNCTION__, counts, index); | ||
2634 | if (counts == index) { | ||
2635 | //we found the one we're looking for, copythe product Id to user | ||
2636 | |||
2637 | mydbg | ||
2638 | ("%s we found the one we're looking for serial = 0x%p\n", | ||
2639 | __FUNCTION__, serial); | ||
2640 | foundserial = serial; | ||
2641 | break; | ||
2642 | } | ||
2643 | |||
2644 | if (serial != lastserial) { | ||
2645 | //when we have a change in the pointer | ||
2646 | lastserial = serial; | ||
2647 | counts++; | ||
2648 | } | ||
2649 | } else | ||
2650 | break; // no matches | ||
2651 | } | ||
2719 | 2652 | ||
2720 | mydbg("%s found match for 422extended\n", __FUNCTION__); | 2653 | mydbg("%s returning foundserial = 0x%p\n", __FUNCTION__, foundserial); |
2721 | break; | 2654 | return foundserial; |
2722 | } | 2655 | } |
2723 | } | ||
2724 | } | ||
2725 | break; | ||
2726 | 2656 | ||
2657 | static int EmulateWriteQMCR_Reg(int index, unsigned uc_value) | ||
2658 | { | ||
2727 | 2659 | ||
2660 | __u16 ATC_Mode = 0; | ||
2661 | struct usb_serial *serial; | ||
2662 | int status; | ||
2663 | struct qt_get_device_data DeviceData; | ||
2664 | unsigned uc_temp = 0; | ||
2665 | mydbg("Inside %s, uc_value = 0x%x\n", __FUNCTION__, uc_value); | ||
2666 | |||
2667 | DeviceData.porta = 0; | ||
2668 | DeviceData.portb = 0; | ||
2669 | serial = find_the_box(index); | ||
2670 | //Determine Duplex mode | ||
2671 | if (!(serial)) | ||
2672 | return -ENOTTY; | ||
2673 | status = box_get_device(serial, &DeviceData); | ||
2674 | if (status < 0) { | ||
2675 | mydbg(__FILE__ "box_set_device failed\n"); | ||
2676 | return status; | ||
2677 | } | ||
2728 | 2678 | ||
2679 | uc_temp = uc_value & QMCR_HALF_DUPLEX_MASK; | ||
2680 | switch (uc_temp) { | ||
2681 | case QMCR_FULL_DUPLEX: | ||
2682 | DeviceData.porta &= ~DUPMODE_BITS; | ||
2683 | DeviceData.porta |= FULL_DUPLEX; | ||
2684 | ATC_Mode = ATC_DISABLED; | ||
2685 | break; | ||
2686 | case QMCR_HALF_DUPLEX_RTS: | ||
2687 | DeviceData.porta &= ~DUPMODE_BITS; | ||
2688 | DeviceData.porta |= HALF_DUPLEX_RTS; | ||
2689 | ATC_Mode = ATC_RTS_ENABLED; | ||
2690 | break; | ||
2691 | case QMCR_HALF_DUPLEX_DTR: | ||
2692 | DeviceData.porta &= ~DUPMODE_BITS; | ||
2693 | DeviceData.porta |= HALF_DUPLEX_DTR; | ||
2694 | ATC_Mode = ATC_DTR_ENABLED; | ||
2695 | break; | ||
2696 | default: | ||
2697 | break; | ||
2698 | } | ||
2729 | 2699 | ||
2730 | default: | 2700 | uc_temp = uc_value & QMCR_CONNECTOR_MASK; |
2731 | err = -ENOTTY; | 2701 | switch (uc_temp) { |
2702 | case QMCR_MODEM_CONTROL: | ||
2703 | DeviceData.portb &= ~LOOPMODE_BITS; //reset connection bits | ||
2704 | DeviceData.portb |= MODEM_CTRL; | ||
2705 | break; | ||
2706 | case QMCR_ALL_LOOPBACK: | ||
2707 | DeviceData.portb &= ~LOOPMODE_BITS; //reset connection bits | ||
2708 | DeviceData.portb |= ALL_LOOPBACK; | ||
2709 | break; | ||
2710 | } | ||
2732 | 2711 | ||
2712 | mydbg(__FILE__ "Calling box_set_device with failed\n"); | ||
2713 | status = box_set_device(serial, &DeviceData); | ||
2714 | if (status < 0) { | ||
2715 | mydbg(__FILE__ "box_set_device failed\n"); | ||
2716 | return status; | ||
2717 | } | ||
2733 | 2718 | ||
2719 | if (uc_value & QMCR_RX_EN_MASK) //This bit (otherwise unused) i'll used to detect whether ATC is selected | ||
2720 | { | ||
2734 | 2721 | ||
2722 | mydbg(__FILE__ | ||
2723 | "calling BoxsetATC with DeviceData.porta = 0x%x and DeviceData.portb = 0x%x\n", | ||
2724 | DeviceData.porta, DeviceData.portb); | ||
2725 | status = BoxSetATC(serial, ATC_Mode); | ||
2726 | if (status < 0) { | ||
2727 | mydbg(__FILE__ "BoxSetATC failed\n"); | ||
2728 | return status; | ||
2729 | } | ||
2730 | } else { | ||
2731 | |||
2732 | mydbg(__FILE__ | ||
2733 | "calling BoxsetATC with DeviceData.porta = 0x%x and DeviceData.portb = 0x%x\n", | ||
2734 | DeviceData.porta, DeviceData.portb); | ||
2735 | status = BoxSetATC(serial, ATC_DISABLED); | ||
2736 | if (status < 0) { | ||
2737 | mydbg(__FILE__ "BoxSetATC failed\n"); | ||
2738 | return status; | ||
2739 | } | ||
2740 | } | ||
2735 | 2741 | ||
2736 | } //End switch | 2742 | return 0; |
2737 | 2743 | ||
2738 | mydbg("%s returning err = 0x%x\n", __FUNCTION__, err); | ||
2739 | return err; | ||
2740 | } | 2744 | } |
2741 | 2745 | ||
2746 | static int EmulateReadQMCR_Reg(int index, unsigned *uc_value) | ||
2747 | { | ||
2748 | struct usb_serial *serial; | ||
2749 | int status; | ||
2750 | struct qt_get_device_data DeviceData; | ||
2751 | __u8 uc_temp; | ||
2742 | 2752 | ||
2753 | *uc_value = 0; | ||
2743 | 2754 | ||
2744 | static struct usb_serial *find_the_box(unsigned int index) | 2755 | serial = find_the_box(index); |
2745 | { | 2756 | if (!(serial)) |
2746 | struct usb_serial *lastserial, *foundserial, *serial; | 2757 | return -ENOTTY; |
2747 | int counts = 0, index2; | ||
2748 | lastserial = serial_table[0]; | ||
2749 | foundserial = NULL; | ||
2750 | for (index2 = 0; index2 < SERIAL_TTY_MINORS ; index2++) | ||
2751 | { | ||
2752 | serial = serial_table[index2]; | ||
2753 | |||
2754 | mydbg("%s index = 0x%x, index2 = 0x%x, serial = 0x%p\n", __FUNCTION__, index, index2, serial); | ||
2755 | |||
2756 | if(serial) | ||
2757 | { | ||
2758 | //first see if this is the unit we'er looking for | ||
2759 | mydbg("%s inside if(serial) counts = 0x%x , index = 0x%x\n", __FUNCTION__, counts, index); | ||
2760 | if(counts == index) | ||
2761 | { | ||
2762 | //we found the one we're looking for, copythe product Id to user | ||
2763 | |||
2764 | mydbg("%s we found the one we're looking for serial = 0x%p\n", __FUNCTION__, serial); | ||
2765 | foundserial = serial; | ||
2766 | break; | ||
2767 | } | ||
2768 | |||
2769 | if(serial != lastserial) | ||
2770 | { | ||
2771 | //when we have a change in the pointer | ||
2772 | lastserial = serial; | ||
2773 | counts++; | ||
2774 | } | ||
2775 | } | ||
2776 | else | ||
2777 | break; // no matches | ||
2778 | } | ||
2779 | |||
2780 | mydbg("%s returning foundserial = 0x%p\n", __FUNCTION__, foundserial); | ||
2781 | return foundserial; | ||
2782 | } | ||
2783 | 2758 | ||
2759 | status = box_get_device(serial, &DeviceData); | ||
2760 | if (status < 0) { | ||
2761 | mydbg(__FILE__ "box_get_device failed\n"); | ||
2762 | return status; | ||
2763 | } | ||
2764 | uc_temp = DeviceData.porta & DUPMODE_BITS; | ||
2765 | switch (uc_temp) { | ||
2766 | case FULL_DUPLEX: | ||
2767 | *uc_value |= QMCR_FULL_DUPLEX; | ||
2768 | break; | ||
2769 | case HALF_DUPLEX_RTS: | ||
2770 | *uc_value |= QMCR_HALF_DUPLEX_RTS; | ||
2771 | break; | ||
2772 | case HALF_DUPLEX_DTR: | ||
2773 | *uc_value |= QMCR_HALF_DUPLEX_DTR; | ||
2774 | break; | ||
2775 | default: | ||
2776 | break; | ||
2777 | } | ||
2784 | 2778 | ||
2779 | uc_temp = DeviceData.portb & LOOPMODE_BITS; //I use this for ATC control se | ||
2785 | 2780 | ||
2786 | static int EmulateWriteQMCR_Reg(int index, unsigned uc_value) | 2781 | switch (uc_temp) { |
2787 | { | 2782 | case ALL_LOOPBACK: |
2788 | 2783 | *uc_value |= QMCR_ALL_LOOPBACK; | |
2789 | __u16 ATC_Mode = 0; | 2784 | break; |
2790 | struct usb_serial *serial; | 2785 | case MODEM_CTRL: |
2791 | int status; | 2786 | *uc_value |= QMCR_MODEM_CONTROL; |
2792 | struct qt_get_device_data DeviceData; | 2787 | break; |
2793 | unsigned uc_temp = 0; | 2788 | default: |
2794 | mydbg("Inside %s, uc_value = 0x%x\n", __FUNCTION__, uc_value); | 2789 | break; |
2795 | |||
2796 | DeviceData.porta = 0; | ||
2797 | DeviceData.portb = 0; | ||
2798 | serial = find_the_box(index); | ||
2799 | //Determine Duplex mode | ||
2800 | if(!(serial)) | ||
2801 | return -ENOTTY; | ||
2802 | status = box_get_device(serial, &DeviceData); | ||
2803 | if (status < 0) | ||
2804 | { | ||
2805 | mydbg(__FILE__"box_set_device failed\n"); | ||
2806 | return status; | ||
2807 | } | ||
2808 | |||
2809 | uc_temp = uc_value & QMCR_HALF_DUPLEX_MASK; | ||
2810 | switch (uc_temp) | ||
2811 | { | ||
2812 | case QMCR_FULL_DUPLEX: | ||
2813 | DeviceData.porta &= ~DUPMODE_BITS; | ||
2814 | DeviceData.porta |= FULL_DUPLEX; | ||
2815 | ATC_Mode = ATC_DISABLED; | ||
2816 | break; | ||
2817 | case QMCR_HALF_DUPLEX_RTS: | ||
2818 | DeviceData.porta &= ~DUPMODE_BITS; | ||
2819 | DeviceData.porta |= HALF_DUPLEX_RTS; | ||
2820 | ATC_Mode = ATC_RTS_ENABLED; | ||
2821 | break; | ||
2822 | case QMCR_HALF_DUPLEX_DTR: | ||
2823 | DeviceData.porta &= ~DUPMODE_BITS; | ||
2824 | DeviceData.porta |= HALF_DUPLEX_DTR; | ||
2825 | ATC_Mode = ATC_DTR_ENABLED; | ||
2826 | break; | ||
2827 | default: | ||
2828 | break; | ||
2829 | } | ||
2830 | |||
2831 | uc_temp = uc_value & QMCR_CONNECTOR_MASK; | ||
2832 | switch (uc_temp) | ||
2833 | { | ||
2834 | case QMCR_MODEM_CONTROL: | ||
2835 | DeviceData.portb &= ~LOOPMODE_BITS; //reset connection bits | ||
2836 | DeviceData.portb |= MODEM_CTRL; | ||
2837 | break; | ||
2838 | case QMCR_ALL_LOOPBACK: | ||
2839 | DeviceData.portb &= ~LOOPMODE_BITS; //reset connection bits | ||
2840 | DeviceData.portb |= ALL_LOOPBACK; | ||
2841 | break; | ||
2842 | } | ||
2843 | |||
2844 | mydbg(__FILE__"Calling box_set_device with failed\n"); | ||
2845 | status = box_set_device(serial, &DeviceData); | ||
2846 | if (status < 0) | ||
2847 | { | ||
2848 | mydbg(__FILE__"box_set_device failed\n"); | ||
2849 | return status; | ||
2850 | } | ||
2851 | |||
2852 | if(uc_value & QMCR_RX_EN_MASK) //This bit (otherwise unused) i'll used to detect whether ATC is selected | ||
2853 | { | ||
2854 | |||
2855 | mydbg(__FILE__"calling BoxsetATC with DeviceData.porta = 0x%x and DeviceData.portb = 0x%x\n", DeviceData.porta, DeviceData.portb); | ||
2856 | status = BoxSetATC(serial, ATC_Mode); | ||
2857 | if (status < 0) | ||
2858 | { | ||
2859 | mydbg(__FILE__"BoxSetATC failed\n"); | ||
2860 | return status; | ||
2861 | } | ||
2862 | } | ||
2863 | else | ||
2864 | { | ||
2865 | |||
2866 | mydbg(__FILE__"calling BoxsetATC with DeviceData.porta = 0x%x and DeviceData.portb = 0x%x\n", DeviceData.porta, DeviceData.portb); | ||
2867 | status = BoxSetATC(serial, ATC_DISABLED); | ||
2868 | if (status < 0) | ||
2869 | { | ||
2870 | mydbg(__FILE__"BoxSetATC failed\n"); | ||
2871 | return status; | ||
2872 | } | ||
2873 | } | ||
2874 | |||
2875 | |||
2876 | return 0; | ||
2877 | |||
2878 | } | ||
2879 | 2790 | ||
2791 | } | ||
2792 | return 0; | ||
2880 | 2793 | ||
2881 | static int EmulateReadQMCR_Reg(int index, unsigned *uc_value) | 2794 | } |
2882 | { | ||
2883 | struct usb_serial *serial; | ||
2884 | int status; | ||
2885 | struct qt_get_device_data DeviceData; | ||
2886 | __u8 uc_temp; | ||
2887 | |||
2888 | *uc_value = 0; | ||
2889 | |||
2890 | serial = find_the_box(index); | ||
2891 | if(!(serial)) | ||
2892 | return -ENOTTY; | ||
2893 | |||
2894 | status = box_get_device(serial, &DeviceData); | ||
2895 | if (status < 0) | ||
2896 | { | ||
2897 | mydbg(__FILE__"box_get_device failed\n"); | ||
2898 | return status; | ||
2899 | } | ||
2900 | uc_temp = DeviceData.porta & DUPMODE_BITS; | ||
2901 | switch (uc_temp) | ||
2902 | { | ||
2903 | case FULL_DUPLEX: | ||
2904 | *uc_value |= QMCR_FULL_DUPLEX; | ||
2905 | break; | ||
2906 | case HALF_DUPLEX_RTS: | ||
2907 | *uc_value |= QMCR_HALF_DUPLEX_RTS; | ||
2908 | break; | ||
2909 | case HALF_DUPLEX_DTR: | ||
2910 | *uc_value |= QMCR_HALF_DUPLEX_DTR; | ||
2911 | break; | ||
2912 | default: | ||
2913 | break; | ||
2914 | } | ||
2915 | |||
2916 | uc_temp = DeviceData.portb & LOOPMODE_BITS; //I use this for ATC control se | ||
2917 | |||
2918 | switch (uc_temp) | ||
2919 | { | ||
2920 | case ALL_LOOPBACK: | ||
2921 | *uc_value |= QMCR_ALL_LOOPBACK; | ||
2922 | break; | ||
2923 | case MODEM_CTRL: | ||
2924 | *uc_value |= QMCR_MODEM_CONTROL; | ||
2925 | break; | ||
2926 | default: | ||
2927 | break; | ||
2928 | |||
2929 | } | ||
2930 | return 0; | ||
2931 | |||
2932 | |||
2933 | } | ||
2934 | 2795 | ||
2935 | static int __init serqt_usb_init(void) | 2796 | static int __init serqt_usb_init(void) |
2936 | { | 2797 | { |
@@ -2952,16 +2813,19 @@ static int __init serqt_usb_init(void) | |||
2952 | /* register this driver with the USB subsystem */ | 2813 | /* register this driver with the USB subsystem */ |
2953 | result = usb_register(&serqt_usb_driver); | 2814 | result = usb_register(&serqt_usb_driver); |
2954 | if (result < 0) { | 2815 | if (result < 0) { |
2955 | err("usb_register failed for the "__FILE__" driver. Error number %d", result); | 2816 | err("usb_register failed for the " __FILE__ |
2817 | " driver. Error number %d", result); | ||
2956 | return result; | 2818 | return result; |
2957 | } | 2819 | } |
2958 | status = 0; // Dynamic assignment of major number | 2820 | status = 0; // Dynamic assignment of major number |
2959 | major_number = register_chrdev(status, "SerialQT_USB", &serialqt_usb_fops); | 2821 | major_number = |
2822 | register_chrdev(status, "SerialQT_USB", &serialqt_usb_fops); | ||
2960 | if (major_number < 0) { | 2823 | if (major_number < 0) { |
2961 | mydbg(KERN_DEBUG"No devices found \n\n"); | 2824 | mydbg(KERN_DEBUG "No devices found \n\n"); |
2962 | return -EBUSY; | 2825 | return -EBUSY; |
2963 | } else | 2826 | } else |
2964 | mydbg(KERN_DEBUG"SerQT_USB major number assignment = %d \n\n", major_number); | 2827 | mydbg(KERN_DEBUG "SerQT_USB major number assignment = %d \n\n", |
2828 | major_number); | ||
2965 | 2829 | ||
2966 | printk(KERN_INFO DRIVER_DESC " " DRIVER_VERSION); | 2830 | printk(KERN_INFO DRIVER_DESC " " DRIVER_VERSION); |
2967 | return 0; | 2831 | return 0; |
@@ -2969,10 +2833,10 @@ static int __init serqt_usb_init(void) | |||
2969 | 2833 | ||
2970 | static void __exit serqt_usb_exit(void) | 2834 | static void __exit serqt_usb_exit(void) |
2971 | { | 2835 | { |
2972 | /* deregister this driver with the USB subsystem */ | 2836 | /* deregister this driver with the USB subsystem */ |
2973 | usb_deregister(&serqt_usb_driver); | 2837 | usb_deregister(&serqt_usb_driver); |
2974 | tty_unregister_driver(&serial_tty_driver); | 2838 | tty_unregister_driver(&serial_tty_driver); |
2975 | unregister_chrdev(major_number, "SerialQT_USB"); | 2839 | unregister_chrdev(major_number, "SerialQT_USB"); |
2976 | } | 2840 | } |
2977 | 2841 | ||
2978 | module_init(serqt_usb_init); | 2842 | module_init(serqt_usb_init); |