2 Keyspan USB to Serial Converter driver
4 (C) Copyright (C) 2000-2001 Hugh Blemings <hugh@blemings.org>
5 (C) Copyright (C) 2002 Greg Kroah-Hartman <greg@kroah.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 See http://blemings.org/hugh/keyspan.html for more information.
14 Code in this driver inspired by and in a number of places taken
15 from Brian Warner's original Keyspan-PDA driver.
17 This driver has been put together with the support of Innosys, Inc.
18 and Keyspan, Inc the manufacturers of the Keyspan USB-serial products.
21 Thanks to Paulus for miscellaneous tidy ups, some largish chunks
22 of much nicer and/or completely new code and (perhaps most uniquely)
23 having the patience to sit down and explain why and where he'd changed
26 Tip 'o the hat to IBM (and previously Linuxcare :) for supporting
27 staff in their work on open source projects.
31 #include <linux/kernel.h>
32 #include <linux/jiffies.h>
33 #include <linux/errno.h>
34 #include <linux/slab.h>
35 #include <linux/tty.h>
36 #include <linux/tty_driver.h>
37 #include <linux/tty_flip.h>
38 #include <linux/module.h>
39 #include <linux/spinlock.h>
40 #include <linux/uaccess.h>
41 #include <linux/usb.h>
42 #include <linux/usb/serial.h>
43 #include <linux/usb/ezusb.h>
45 #define DRIVER_AUTHOR "Hugh Blemings <hugh@misc.nu"
46 #define DRIVER_DESC "Keyspan USB to Serial Converter Driver"
48 /* Function prototypes for Keyspan serial converter */
49 static int keyspan_open(struct tty_struct *tty, struct usb_serial_port *port);
50 static void keyspan_close(struct usb_serial_port *port);
51 static void keyspan_dtr_rts(struct usb_serial_port *port, int on);
52 static int keyspan_startup(struct usb_serial *serial);
53 static void keyspan_disconnect(struct usb_serial *serial);
54 static void keyspan_release(struct usb_serial *serial);
55 static int keyspan_port_probe(struct usb_serial_port *port);
56 static int keyspan_port_remove(struct usb_serial_port *port);
57 static int keyspan_write_room(struct tty_struct *tty);
58 static int keyspan_write(struct tty_struct *tty, struct usb_serial_port *port,
59 const unsigned char *buf, int count);
60 static void keyspan_send_setup(struct usb_serial_port *port, int reset_port);
61 static void keyspan_set_termios(struct tty_struct *tty,
62 struct usb_serial_port *port,
63 struct ktermios *old);
64 static void keyspan_break_ctl(struct tty_struct *tty, int break_state);
65 static int keyspan_tiocmget(struct tty_struct *tty);
66 static int keyspan_tiocmset(struct tty_struct *tty, unsigned int set,
68 static int keyspan_fake_startup(struct usb_serial *serial);
70 static int keyspan_usa19_calc_baud(struct usb_serial_port *port,
71 u32 baud_rate, u32 baudclk,
72 u8 *rate_hi, u8 *rate_low,
73 u8 *prescaler, int portnum);
74 static int keyspan_usa19w_calc_baud(struct usb_serial_port *port,
75 u32 baud_rate, u32 baudclk,
76 u8 *rate_hi, u8 *rate_low,
77 u8 *prescaler, int portnum);
78 static int keyspan_usa28_calc_baud(struct usb_serial_port *port,
79 u32 baud_rate, u32 baudclk,
80 u8 *rate_hi, u8 *rate_low,
81 u8 *prescaler, int portnum);
82 static int keyspan_usa19hs_calc_baud(struct usb_serial_port *port,
83 u32 baud_rate, u32 baudclk,
84 u8 *rate_hi, u8 *rate_low,
85 u8 *prescaler, int portnum);
87 static int keyspan_usa28_send_setup(struct usb_serial *serial,
88 struct usb_serial_port *port,
90 static int keyspan_usa26_send_setup(struct usb_serial *serial,
91 struct usb_serial_port *port,
93 static int keyspan_usa49_send_setup(struct usb_serial *serial,
94 struct usb_serial_port *port,
96 static int keyspan_usa90_send_setup(struct usb_serial *serial,
97 struct usb_serial_port *port,
99 static int keyspan_usa67_send_setup(struct usb_serial *serial,
100 struct usb_serial_port *port,
103 /* Values used for baud rate calculation - device specific */
104 #define KEYSPAN_INVALID_BAUD_RATE (-1)
105 #define KEYSPAN_BAUD_RATE_OK (0)
106 #define KEYSPAN_USA18X_BAUDCLK (12000000L) /* a guess */
107 #define KEYSPAN_USA19_BAUDCLK (12000000L)
108 #define KEYSPAN_USA19W_BAUDCLK (24000000L)
109 #define KEYSPAN_USA19HS_BAUDCLK (14769231L)
110 #define KEYSPAN_USA28_BAUDCLK (1843200L)
111 #define KEYSPAN_USA28X_BAUDCLK (12000000L)
112 #define KEYSPAN_USA49W_BAUDCLK (48000000L)
114 /* Some constants used to characterise each device. */
115 #define KEYSPAN_MAX_NUM_PORTS (4)
116 #define KEYSPAN_MAX_FLIPS (2)
119 * Device info for the Keyspan serial converter, used by the overall
120 * usb-serial probe function.
122 #define KEYSPAN_VENDOR_ID (0x06cd)
124 /* Product IDs for the products supported, pre-renumeration */
125 #define keyspan_usa18x_pre_product_id 0x0105
126 #define keyspan_usa19_pre_product_id 0x0103
127 #define keyspan_usa19qi_pre_product_id 0x010b
128 #define keyspan_mpr_pre_product_id 0x011b
129 #define keyspan_usa19qw_pre_product_id 0x0118
130 #define keyspan_usa19w_pre_product_id 0x0106
131 #define keyspan_usa28_pre_product_id 0x0101
132 #define keyspan_usa28x_pre_product_id 0x0102
133 #define keyspan_usa28xa_pre_product_id 0x0114
134 #define keyspan_usa28xb_pre_product_id 0x0113
135 #define keyspan_usa49w_pre_product_id 0x0109
136 #define keyspan_usa49wlc_pre_product_id 0x011a
139 * Product IDs post-renumeration. Note that the 28x and 28xb have the same
140 * id's post-renumeration but behave identically so it's not an issue. As
141 * such, the 28xb is not listed in any of the device tables.
143 #define keyspan_usa18x_product_id 0x0112
144 #define keyspan_usa19_product_id 0x0107
145 #define keyspan_usa19qi_product_id 0x010c
146 #define keyspan_usa19hs_product_id 0x0121
147 #define keyspan_mpr_product_id 0x011c
148 #define keyspan_usa19qw_product_id 0x0119
149 #define keyspan_usa19w_product_id 0x0108
150 #define keyspan_usa28_product_id 0x010f
151 #define keyspan_usa28x_product_id 0x0110
152 #define keyspan_usa28xa_product_id 0x0115
153 #define keyspan_usa28xb_product_id 0x0110
154 #define keyspan_usa28xg_product_id 0x0135
155 #define keyspan_usa49w_product_id 0x010a
156 #define keyspan_usa49wlc_product_id 0x012a
157 #define keyspan_usa49wg_product_id 0x0131
159 struct keyspan_device_details {
160 /* product ID value */
163 enum {msg_usa26, msg_usa28, msg_usa49, msg_usa90, msg_usa67} msg_format;
165 /* Number of physical ports */
168 /* 1 if endpoint flipping used on input, 0 if not */
171 /* 1 if endpoint flipping used on output, 0 if not */
172 int outdat_endp_flip;
175 * Table mapping input data endpoint IDs to physical port
176 * number and flip if used
178 int indat_endpoints[KEYSPAN_MAX_NUM_PORTS];
180 /* Same for output endpoints */
181 int outdat_endpoints[KEYSPAN_MAX_NUM_PORTS];
183 /* Input acknowledge endpoints */
184 int inack_endpoints[KEYSPAN_MAX_NUM_PORTS];
186 /* Output control endpoints */
187 int outcont_endpoints[KEYSPAN_MAX_NUM_PORTS];
189 /* Endpoint used for input status */
192 /* Endpoint used for input data 49WG only */
195 /* Endpoint used for global control functions */
196 int glocont_endpoint;
198 int (*calculate_baud_rate)(struct usb_serial_port *port,
199 u32 baud_rate, u32 baudclk,
200 u8 *rate_hi, u8 *rate_low, u8 *prescaler,
206 * Now for each device type we setup the device detail structure with the
207 * appropriate information (provided in Keyspan's documentation)
210 static const struct keyspan_device_details usa18x_device_details = {
211 .product_id = keyspan_usa18x_product_id,
212 .msg_format = msg_usa26,
214 .indat_endp_flip = 0,
215 .outdat_endp_flip = 1,
216 .indat_endpoints = {0x81},
217 .outdat_endpoints = {0x01},
218 .inack_endpoints = {0x85},
219 .outcont_endpoints = {0x05},
220 .instat_endpoint = 0x87,
221 .indat_endpoint = -1,
222 .glocont_endpoint = 0x07,
223 .calculate_baud_rate = keyspan_usa19w_calc_baud,
224 .baudclk = KEYSPAN_USA18X_BAUDCLK,
227 static const struct keyspan_device_details usa19_device_details = {
228 .product_id = keyspan_usa19_product_id,
229 .msg_format = msg_usa28,
231 .indat_endp_flip = 1,
232 .outdat_endp_flip = 1,
233 .indat_endpoints = {0x81},
234 .outdat_endpoints = {0x01},
235 .inack_endpoints = {0x83},
236 .outcont_endpoints = {0x03},
237 .instat_endpoint = 0x84,
238 .indat_endpoint = -1,
239 .glocont_endpoint = -1,
240 .calculate_baud_rate = keyspan_usa19_calc_baud,
241 .baudclk = KEYSPAN_USA19_BAUDCLK,
244 static const struct keyspan_device_details usa19qi_device_details = {
245 .product_id = keyspan_usa19qi_product_id,
246 .msg_format = msg_usa28,
248 .indat_endp_flip = 1,
249 .outdat_endp_flip = 1,
250 .indat_endpoints = {0x81},
251 .outdat_endpoints = {0x01},
252 .inack_endpoints = {0x83},
253 .outcont_endpoints = {0x03},
254 .instat_endpoint = 0x84,
255 .indat_endpoint = -1,
256 .glocont_endpoint = -1,
257 .calculate_baud_rate = keyspan_usa28_calc_baud,
258 .baudclk = KEYSPAN_USA19_BAUDCLK,
261 static const struct keyspan_device_details mpr_device_details = {
262 .product_id = keyspan_mpr_product_id,
263 .msg_format = msg_usa28,
265 .indat_endp_flip = 1,
266 .outdat_endp_flip = 1,
267 .indat_endpoints = {0x81},
268 .outdat_endpoints = {0x01},
269 .inack_endpoints = {0x83},
270 .outcont_endpoints = {0x03},
271 .instat_endpoint = 0x84,
272 .indat_endpoint = -1,
273 .glocont_endpoint = -1,
274 .calculate_baud_rate = keyspan_usa28_calc_baud,
275 .baudclk = KEYSPAN_USA19_BAUDCLK,
278 static const struct keyspan_device_details usa19qw_device_details = {
279 .product_id = keyspan_usa19qw_product_id,
280 .msg_format = msg_usa26,
282 .indat_endp_flip = 0,
283 .outdat_endp_flip = 1,
284 .indat_endpoints = {0x81},
285 .outdat_endpoints = {0x01},
286 .inack_endpoints = {0x85},
287 .outcont_endpoints = {0x05},
288 .instat_endpoint = 0x87,
289 .indat_endpoint = -1,
290 .glocont_endpoint = 0x07,
291 .calculate_baud_rate = keyspan_usa19w_calc_baud,
292 .baudclk = KEYSPAN_USA19W_BAUDCLK,
295 static const struct keyspan_device_details usa19w_device_details = {
296 .product_id = keyspan_usa19w_product_id,
297 .msg_format = msg_usa26,
299 .indat_endp_flip = 0,
300 .outdat_endp_flip = 1,
301 .indat_endpoints = {0x81},
302 .outdat_endpoints = {0x01},
303 .inack_endpoints = {0x85},
304 .outcont_endpoints = {0x05},
305 .instat_endpoint = 0x87,
306 .indat_endpoint = -1,
307 .glocont_endpoint = 0x07,
308 .calculate_baud_rate = keyspan_usa19w_calc_baud,
309 .baudclk = KEYSPAN_USA19W_BAUDCLK,
312 static const struct keyspan_device_details usa19hs_device_details = {
313 .product_id = keyspan_usa19hs_product_id,
314 .msg_format = msg_usa90,
316 .indat_endp_flip = 0,
317 .outdat_endp_flip = 0,
318 .indat_endpoints = {0x81},
319 .outdat_endpoints = {0x01},
320 .inack_endpoints = {-1},
321 .outcont_endpoints = {0x02},
322 .instat_endpoint = 0x82,
323 .indat_endpoint = -1,
324 .glocont_endpoint = -1,
325 .calculate_baud_rate = keyspan_usa19hs_calc_baud,
326 .baudclk = KEYSPAN_USA19HS_BAUDCLK,
329 static const struct keyspan_device_details usa28_device_details = {
330 .product_id = keyspan_usa28_product_id,
331 .msg_format = msg_usa28,
333 .indat_endp_flip = 1,
334 .outdat_endp_flip = 1,
335 .indat_endpoints = {0x81, 0x83},
336 .outdat_endpoints = {0x01, 0x03},
337 .inack_endpoints = {0x85, 0x86},
338 .outcont_endpoints = {0x05, 0x06},
339 .instat_endpoint = 0x87,
340 .indat_endpoint = -1,
341 .glocont_endpoint = 0x07,
342 .calculate_baud_rate = keyspan_usa28_calc_baud,
343 .baudclk = KEYSPAN_USA28_BAUDCLK,
346 static const struct keyspan_device_details usa28x_device_details = {
347 .product_id = keyspan_usa28x_product_id,
348 .msg_format = msg_usa26,
350 .indat_endp_flip = 0,
351 .outdat_endp_flip = 1,
352 .indat_endpoints = {0x81, 0x83},
353 .outdat_endpoints = {0x01, 0x03},
354 .inack_endpoints = {0x85, 0x86},
355 .outcont_endpoints = {0x05, 0x06},
356 .instat_endpoint = 0x87,
357 .indat_endpoint = -1,
358 .glocont_endpoint = 0x07,
359 .calculate_baud_rate = keyspan_usa19w_calc_baud,
360 .baudclk = KEYSPAN_USA28X_BAUDCLK,
363 static const struct keyspan_device_details usa28xa_device_details = {
364 .product_id = keyspan_usa28xa_product_id,
365 .msg_format = msg_usa26,
367 .indat_endp_flip = 0,
368 .outdat_endp_flip = 1,
369 .indat_endpoints = {0x81, 0x83},
370 .outdat_endpoints = {0x01, 0x03},
371 .inack_endpoints = {0x85, 0x86},
372 .outcont_endpoints = {0x05, 0x06},
373 .instat_endpoint = 0x87,
374 .indat_endpoint = -1,
375 .glocont_endpoint = 0x07,
376 .calculate_baud_rate = keyspan_usa19w_calc_baud,
377 .baudclk = KEYSPAN_USA28X_BAUDCLK,
380 static const struct keyspan_device_details usa28xg_device_details = {
381 .product_id = keyspan_usa28xg_product_id,
382 .msg_format = msg_usa67,
384 .indat_endp_flip = 0,
385 .outdat_endp_flip = 0,
386 .indat_endpoints = {0x84, 0x88},
387 .outdat_endpoints = {0x02, 0x06},
388 .inack_endpoints = {-1, -1},
389 .outcont_endpoints = {-1, -1},
390 .instat_endpoint = 0x81,
391 .indat_endpoint = -1,
392 .glocont_endpoint = 0x01,
393 .calculate_baud_rate = keyspan_usa19w_calc_baud,
394 .baudclk = KEYSPAN_USA28X_BAUDCLK,
397 * We don't need a separate entry for the usa28xb as it appears as a 28x
401 static const struct keyspan_device_details usa49w_device_details = {
402 .product_id = keyspan_usa49w_product_id,
403 .msg_format = msg_usa49,
405 .indat_endp_flip = 0,
406 .outdat_endp_flip = 0,
407 .indat_endpoints = {0x81, 0x82, 0x83, 0x84},
408 .outdat_endpoints = {0x01, 0x02, 0x03, 0x04},
409 .inack_endpoints = {-1, -1, -1, -1},
410 .outcont_endpoints = {-1, -1, -1, -1},
411 .instat_endpoint = 0x87,
412 .indat_endpoint = -1,
413 .glocont_endpoint = 0x07,
414 .calculate_baud_rate = keyspan_usa19w_calc_baud,
415 .baudclk = KEYSPAN_USA49W_BAUDCLK,
418 static const struct keyspan_device_details usa49wlc_device_details = {
419 .product_id = keyspan_usa49wlc_product_id,
420 .msg_format = msg_usa49,
422 .indat_endp_flip = 0,
423 .outdat_endp_flip = 0,
424 .indat_endpoints = {0x81, 0x82, 0x83, 0x84},
425 .outdat_endpoints = {0x01, 0x02, 0x03, 0x04},
426 .inack_endpoints = {-1, -1, -1, -1},
427 .outcont_endpoints = {-1, -1, -1, -1},
428 .instat_endpoint = 0x87,
429 .indat_endpoint = -1,
430 .glocont_endpoint = 0x07,
431 .calculate_baud_rate = keyspan_usa19w_calc_baud,
432 .baudclk = KEYSPAN_USA19W_BAUDCLK,
435 static const struct keyspan_device_details usa49wg_device_details = {
436 .product_id = keyspan_usa49wg_product_id,
437 .msg_format = msg_usa49,
439 .indat_endp_flip = 0,
440 .outdat_endp_flip = 0,
441 .indat_endpoints = {-1, -1, -1, -1}, /* single 'global' data in EP */
442 .outdat_endpoints = {0x01, 0x02, 0x04, 0x06},
443 .inack_endpoints = {-1, -1, -1, -1},
444 .outcont_endpoints = {-1, -1, -1, -1},
445 .instat_endpoint = 0x81,
446 .indat_endpoint = 0x88,
447 .glocont_endpoint = 0x00, /* uses control EP */
448 .calculate_baud_rate = keyspan_usa19w_calc_baud,
449 .baudclk = KEYSPAN_USA19W_BAUDCLK,
452 static const struct keyspan_device_details *keyspan_devices[] = {
453 &usa18x_device_details,
454 &usa19_device_details,
455 &usa19qi_device_details,
457 &usa19qw_device_details,
458 &usa19w_device_details,
459 &usa19hs_device_details,
460 &usa28_device_details,
461 &usa28x_device_details,
462 &usa28xa_device_details,
463 &usa28xg_device_details,
464 /* 28xb not required as it renumerates as a 28x */
465 &usa49w_device_details,
466 &usa49wlc_device_details,
467 &usa49wg_device_details,
471 static const struct usb_device_id keyspan_ids_combined[] = {
472 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa18x_pre_product_id) },
473 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19_pre_product_id) },
474 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19w_pre_product_id) },
475 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qi_pre_product_id) },
476 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qw_pre_product_id) },
477 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_mpr_pre_product_id) },
478 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28_pre_product_id) },
479 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28x_pre_product_id) },
480 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xa_pre_product_id) },
481 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xb_pre_product_id) },
482 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49w_pre_product_id) },
483 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wlc_pre_product_id) },
484 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa18x_product_id) },
485 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19_product_id) },
486 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19w_product_id) },
487 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qi_product_id) },
488 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qw_product_id) },
489 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19hs_product_id) },
490 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_mpr_product_id) },
491 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28_product_id) },
492 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28x_product_id) },
493 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xa_product_id) },
494 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xg_product_id) },
495 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49w_product_id)},
496 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wlc_product_id)},
497 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wg_product_id)},
498 { } /* Terminating entry */
501 MODULE_DEVICE_TABLE(usb, keyspan_ids_combined);
503 /* usb_device_id table for the pre-firmware download keyspan devices */
504 static const struct usb_device_id keyspan_pre_ids[] = {
505 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa18x_pre_product_id) },
506 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19_pre_product_id) },
507 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qi_pre_product_id) },
508 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qw_pre_product_id) },
509 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19w_pre_product_id) },
510 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_mpr_pre_product_id) },
511 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28_pre_product_id) },
512 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28x_pre_product_id) },
513 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xa_pre_product_id) },
514 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xb_pre_product_id) },
515 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49w_pre_product_id) },
516 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wlc_pre_product_id) },
517 { } /* Terminating entry */
520 static const struct usb_device_id keyspan_1port_ids[] = {
521 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa18x_product_id) },
522 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19_product_id) },
523 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qi_product_id) },
524 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qw_product_id) },
525 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19w_product_id) },
526 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19hs_product_id) },
527 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_mpr_product_id) },
528 { } /* Terminating entry */
531 static const struct usb_device_id keyspan_2port_ids[] = {
532 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28_product_id) },
533 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28x_product_id) },
534 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xa_product_id) },
535 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xg_product_id) },
536 { } /* Terminating entry */
539 static const struct usb_device_id keyspan_4port_ids[] = {
540 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49w_product_id) },
541 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wlc_product_id)},
542 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wg_product_id)},
543 { } /* Terminating entry */
546 #define INSTAT_BUFLEN 32
547 #define GLOCONT_BUFLEN 64
548 #define INDAT49W_BUFLEN 512
550 #define OUT_BUFLEN 64
551 #define INACK_BUFLEN 1
552 #define OUTCONT_BUFLEN 64
554 /* Per device and per port private data */
555 struct keyspan_serial_private {
556 const struct keyspan_device_details *device_details;
558 struct urb *instat_urb;
561 /* added to support 49wg, where data from all 4 ports comes in
562 on 1 EP and high-speed supported */
563 struct urb *indat_urb;
566 /* XXX this one probably will need a lock */
567 struct urb *glocont_urb;
569 char *ctrl_buf; /* for EP0 control message */
572 struct keyspan_port_private {
573 /* Keep track of which input & output endpoints to use */
577 /* Keep duplicate of device details in each port
578 structure as well - simplifies some of the
579 callback functions etc. */
580 const struct keyspan_device_details *device_details;
582 /* Input endpoints and buffer for this port */
583 struct urb *in_urbs[2];
585 /* Output endpoints and buffer for this port */
586 struct urb *out_urbs[2];
589 /* Input ack endpoint */
590 struct urb *inack_urb;
593 /* Output control endpoint */
594 struct urb *outcont_urb;
595 char *outcont_buffer;
597 /* Settings for the port */
601 unsigned int old_cflag;
602 enum {flow_none, flow_cts, flow_xon} flow_control;
603 int rts_state; /* Handshaking pins (outputs) */
605 int cts_state; /* Handshaking pins (inputs) */
611 unsigned long tx_start_time[2];
612 int resend_cont; /* need to resend control packet */
615 /* Include Keyspan message headers. All current Keyspan Adapters
616 make use of one of five message formats which are referred
617 to as USA-26, USA-28, USA-49, USA-90, USA-67 by Keyspan and
618 within this driver. */
619 #include "keyspan_usa26msg.h"
620 #include "keyspan_usa28msg.h"
621 #include "keyspan_usa49msg.h"
622 #include "keyspan_usa90msg.h"
623 #include "keyspan_usa67msg.h"
626 static void keyspan_break_ctl(struct tty_struct *tty, int break_state)
628 struct usb_serial_port *port = tty->driver_data;
629 struct keyspan_port_private *p_priv;
631 p_priv = usb_get_serial_port_data(port);
633 if (break_state == -1)
634 p_priv->break_on = 1;
636 p_priv->break_on = 0;
638 keyspan_send_setup(port, 0);
642 static void keyspan_set_termios(struct tty_struct *tty,
643 struct usb_serial_port *port, struct ktermios *old_termios)
645 int baud_rate, device_port;
646 struct keyspan_port_private *p_priv;
647 const struct keyspan_device_details *d_details;
650 p_priv = usb_get_serial_port_data(port);
651 d_details = p_priv->device_details;
652 cflag = tty->termios.c_cflag;
653 device_port = port->port_number;
655 /* Baud rate calculation takes baud rate as an integer
656 so other rates can be generated if desired. */
657 baud_rate = tty_get_baud_rate(tty);
658 /* If no match or invalid, don't change */
659 if (d_details->calculate_baud_rate(port, baud_rate, d_details->baudclk,
660 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
661 /* FIXME - more to do here to ensure rate changes cleanly */
662 /* FIXME - calculate exact rate from divisor ? */
663 p_priv->baud = baud_rate;
665 baud_rate = tty_termios_baud_rate(old_termios);
667 tty_encode_baud_rate(tty, baud_rate, baud_rate);
668 /* set CTS/RTS handshake etc. */
669 p_priv->cflag = cflag;
670 p_priv->flow_control = (cflag & CRTSCTS) ? flow_cts : flow_none;
672 /* Mark/Space not supported */
673 tty->termios.c_cflag &= ~CMSPAR;
675 keyspan_send_setup(port, 0);
678 static int keyspan_tiocmget(struct tty_struct *tty)
680 struct usb_serial_port *port = tty->driver_data;
681 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
684 value = ((p_priv->rts_state) ? TIOCM_RTS : 0) |
685 ((p_priv->dtr_state) ? TIOCM_DTR : 0) |
686 ((p_priv->cts_state) ? TIOCM_CTS : 0) |
687 ((p_priv->dsr_state) ? TIOCM_DSR : 0) |
688 ((p_priv->dcd_state) ? TIOCM_CAR : 0) |
689 ((p_priv->ri_state) ? TIOCM_RNG : 0);
694 static int keyspan_tiocmset(struct tty_struct *tty,
695 unsigned int set, unsigned int clear)
697 struct usb_serial_port *port = tty->driver_data;
698 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
701 p_priv->rts_state = 1;
703 p_priv->dtr_state = 1;
704 if (clear & TIOCM_RTS)
705 p_priv->rts_state = 0;
706 if (clear & TIOCM_DTR)
707 p_priv->dtr_state = 0;
708 keyspan_send_setup(port, 0);
712 /* Write function is similar for the four protocols used
713 with only a minor change for usa90 (usa19hs) required */
714 static int keyspan_write(struct tty_struct *tty,
715 struct usb_serial_port *port, const unsigned char *buf, int count)
717 struct keyspan_port_private *p_priv;
718 const struct keyspan_device_details *d_details;
721 struct urb *this_urb;
722 int err, maxDataLen, dataOffset;
724 p_priv = usb_get_serial_port_data(port);
725 d_details = p_priv->device_details;
727 if (d_details->msg_format == msg_usa90) {
735 dev_dbg(&port->dev, "%s - %d chars, flip=%d\n", __func__, count,
738 for (left = count; left > 0; left -= todo) {
740 if (todo > maxDataLen)
743 flip = p_priv->out_flip;
745 /* Check we have a valid urb/endpoint before we use it... */
746 this_urb = p_priv->out_urbs[flip];
747 if (this_urb == NULL) {
748 /* no bulk out, so return 0 bytes written */
749 dev_dbg(&port->dev, "%s - no output urb :(\n", __func__);
753 dev_dbg(&port->dev, "%s - endpoint %x flip %d\n",
754 __func__, usb_pipeendpoint(this_urb->pipe), flip);
756 if (this_urb->status == -EINPROGRESS) {
757 if (time_before(jiffies,
758 p_priv->tx_start_time[flip] + 10 * HZ))
760 usb_unlink_urb(this_urb);
764 /* First byte in buffer is "last flag" (except for usa19hx)
765 - unused so for now so set to zero */
766 ((char *)this_urb->transfer_buffer)[0] = 0;
768 memcpy(this_urb->transfer_buffer + dataOffset, buf, todo);
771 /* send the data out the bulk port */
772 this_urb->transfer_buffer_length = todo + dataOffset;
774 err = usb_submit_urb(this_urb, GFP_ATOMIC);
776 dev_dbg(&port->dev, "usb_submit_urb(write bulk) failed (%d)\n", err);
777 p_priv->tx_start_time[flip] = jiffies;
779 /* Flip for next time if usa26 or usa28 interface
780 (not used on usa49) */
781 p_priv->out_flip = (flip + 1) & d_details->outdat_endp_flip;
787 static void usa26_indat_callback(struct urb *urb)
791 struct usb_serial_port *port;
792 unsigned char *data = urb->transfer_buffer;
793 int status = urb->status;
795 endpoint = usb_pipeendpoint(urb->pipe);
798 dev_dbg(&urb->dev->dev, "%s - nonzero status %d on endpoint %x\n",
799 __func__, status, endpoint);
804 if (urb->actual_length) {
805 /* 0x80 bit is error flag */
806 if ((data[0] & 0x80) == 0) {
807 /* no errors on individual bytes, only
808 possible overrun err */
809 if (data[0] & RXERROR_OVERRUN) {
810 tty_insert_flip_char(&port->port, 0,
813 for (i = 1; i < urb->actual_length ; ++i)
814 tty_insert_flip_char(&port->port, data[i],
817 /* some bytes had errors, every byte has status */
818 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
819 for (i = 0; i + 1 < urb->actual_length; i += 2) {
821 int flag = TTY_NORMAL;
823 if (stat & RXERROR_OVERRUN) {
824 tty_insert_flip_char(&port->port, 0,
827 /* XXX should handle break (0x10) */
828 if (stat & RXERROR_PARITY)
830 else if (stat & RXERROR_FRAMING)
833 tty_insert_flip_char(&port->port, data[i+1],
837 tty_flip_buffer_push(&port->port);
840 /* Resubmit urb so we continue receiving */
841 err = usb_submit_urb(urb, GFP_ATOMIC);
843 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
846 /* Outdat handling is common for all devices */
847 static void usa2x_outdat_callback(struct urb *urb)
849 struct usb_serial_port *port;
850 struct keyspan_port_private *p_priv;
853 p_priv = usb_get_serial_port_data(port);
854 dev_dbg(&port->dev, "%s - urb %d\n", __func__, urb == p_priv->out_urbs[1]);
856 usb_serial_port_softint(port);
859 static void usa26_inack_callback(struct urb *urb)
863 static void usa26_outcont_callback(struct urb *urb)
865 struct usb_serial_port *port;
866 struct keyspan_port_private *p_priv;
869 p_priv = usb_get_serial_port_data(port);
871 if (p_priv->resend_cont) {
872 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
873 keyspan_usa26_send_setup(port->serial, port,
874 p_priv->resend_cont - 1);
878 static void usa26_instat_callback(struct urb *urb)
880 unsigned char *data = urb->transfer_buffer;
881 struct keyspan_usa26_portStatusMessage *msg;
882 struct usb_serial *serial;
883 struct usb_serial_port *port;
884 struct keyspan_port_private *p_priv;
885 int old_dcd_state, err;
886 int status = urb->status;
888 serial = urb->context;
891 dev_dbg(&urb->dev->dev, "%s - nonzero status: %d\n",
895 if (urb->actual_length != 9) {
896 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
900 msg = (struct keyspan_usa26_portStatusMessage *)data;
902 /* Check port number from message and retrieve private data */
903 if (msg->port >= serial->num_ports) {
904 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
907 port = serial->port[msg->port];
908 p_priv = usb_get_serial_port_data(port);
912 /* Update handshaking pin state information */
913 old_dcd_state = p_priv->dcd_state;
914 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
915 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
916 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
917 p_priv->ri_state = ((msg->ri) ? 1 : 0);
919 if (old_dcd_state != p_priv->dcd_state)
920 tty_port_tty_hangup(&port->port, true);
922 /* Resubmit urb so we continue receiving */
923 err = usb_submit_urb(urb, GFP_ATOMIC);
925 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
929 static void usa26_glocont_callback(struct urb *urb)
934 static void usa28_indat_callback(struct urb *urb)
937 struct usb_serial_port *port;
939 struct keyspan_port_private *p_priv;
940 int status = urb->status;
943 p_priv = usb_get_serial_port_data(port);
944 data = urb->transfer_buffer;
946 if (urb != p_priv->in_urbs[p_priv->in_flip])
951 dev_dbg(&urb->dev->dev, "%s - nonzero status %d on endpoint %x\n",
952 __func__, status, usb_pipeendpoint(urb->pipe));
957 p_priv = usb_get_serial_port_data(port);
958 data = urb->transfer_buffer;
960 if (urb->actual_length) {
961 tty_insert_flip_string(&port->port, data,
963 tty_flip_buffer_push(&port->port);
966 /* Resubmit urb so we continue receiving */
967 err = usb_submit_urb(urb, GFP_ATOMIC);
969 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n",
971 p_priv->in_flip ^= 1;
973 urb = p_priv->in_urbs[p_priv->in_flip];
974 } while (urb->status != -EINPROGRESS);
977 static void usa28_inack_callback(struct urb *urb)
981 static void usa28_outcont_callback(struct urb *urb)
983 struct usb_serial_port *port;
984 struct keyspan_port_private *p_priv;
987 p_priv = usb_get_serial_port_data(port);
989 if (p_priv->resend_cont) {
990 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
991 keyspan_usa28_send_setup(port->serial, port,
992 p_priv->resend_cont - 1);
996 static void usa28_instat_callback(struct urb *urb)
999 unsigned char *data = urb->transfer_buffer;
1000 struct keyspan_usa28_portStatusMessage *msg;
1001 struct usb_serial *serial;
1002 struct usb_serial_port *port;
1003 struct keyspan_port_private *p_priv;
1005 int status = urb->status;
1007 serial = urb->context;
1010 dev_dbg(&urb->dev->dev, "%s - nonzero status: %d\n",
1015 if (urb->actual_length != sizeof(struct keyspan_usa28_portStatusMessage)) {
1016 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
1020 msg = (struct keyspan_usa28_portStatusMessage *)data;
1022 /* Check port number from message and retrieve private data */
1023 if (msg->port >= serial->num_ports) {
1024 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
1027 port = serial->port[msg->port];
1028 p_priv = usb_get_serial_port_data(port);
1032 /* Update handshaking pin state information */
1033 old_dcd_state = p_priv->dcd_state;
1034 p_priv->cts_state = ((msg->cts) ? 1 : 0);
1035 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
1036 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
1037 p_priv->ri_state = ((msg->ri) ? 1 : 0);
1039 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
1040 tty_port_tty_hangup(&port->port, true);
1042 /* Resubmit urb so we continue receiving */
1043 err = usb_submit_urb(urb, GFP_ATOMIC);
1045 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
1049 static void usa28_glocont_callback(struct urb *urb)
1054 static void usa49_glocont_callback(struct urb *urb)
1056 struct usb_serial *serial;
1057 struct usb_serial_port *port;
1058 struct keyspan_port_private *p_priv;
1061 serial = urb->context;
1062 for (i = 0; i < serial->num_ports; ++i) {
1063 port = serial->port[i];
1064 p_priv = usb_get_serial_port_data(port);
1068 if (p_priv->resend_cont) {
1069 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
1070 keyspan_usa49_send_setup(serial, port,
1071 p_priv->resend_cont - 1);
1077 /* This is actually called glostat in the Keyspan
1079 static void usa49_instat_callback(struct urb *urb)
1082 unsigned char *data = urb->transfer_buffer;
1083 struct keyspan_usa49_portStatusMessage *msg;
1084 struct usb_serial *serial;
1085 struct usb_serial_port *port;
1086 struct keyspan_port_private *p_priv;
1088 int status = urb->status;
1090 serial = urb->context;
1093 dev_dbg(&urb->dev->dev, "%s - nonzero status: %d\n",
1098 if (urb->actual_length !=
1099 sizeof(struct keyspan_usa49_portStatusMessage)) {
1100 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
1104 msg = (struct keyspan_usa49_portStatusMessage *)data;
1106 /* Check port number from message and retrieve private data */
1107 if (msg->portNumber >= serial->num_ports) {
1108 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
1109 __func__, msg->portNumber);
1112 port = serial->port[msg->portNumber];
1113 p_priv = usb_get_serial_port_data(port);
1117 /* Update handshaking pin state information */
1118 old_dcd_state = p_priv->dcd_state;
1119 p_priv->cts_state = ((msg->cts) ? 1 : 0);
1120 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
1121 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
1122 p_priv->ri_state = ((msg->ri) ? 1 : 0);
1124 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
1125 tty_port_tty_hangup(&port->port, true);
1127 /* Resubmit urb so we continue receiving */
1128 err = usb_submit_urb(urb, GFP_ATOMIC);
1130 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
1134 static void usa49_inack_callback(struct urb *urb)
1138 static void usa49_indat_callback(struct urb *urb)
1142 struct usb_serial_port *port;
1143 unsigned char *data = urb->transfer_buffer;
1144 int status = urb->status;
1146 endpoint = usb_pipeendpoint(urb->pipe);
1149 dev_dbg(&urb->dev->dev, "%s - nonzero status %d on endpoint %x\n",
1150 __func__, status, endpoint);
1154 port = urb->context;
1155 if (urb->actual_length) {
1156 /* 0x80 bit is error flag */
1157 if ((data[0] & 0x80) == 0) {
1158 /* no error on any byte */
1159 tty_insert_flip_string(&port->port, data + 1,
1160 urb->actual_length - 1);
1162 /* some bytes had errors, every byte has status */
1163 for (i = 0; i + 1 < urb->actual_length; i += 2) {
1165 int flag = TTY_NORMAL;
1167 if (stat & RXERROR_OVERRUN) {
1168 tty_insert_flip_char(&port->port, 0,
1171 /* XXX should handle break (0x10) */
1172 if (stat & RXERROR_PARITY)
1174 else if (stat & RXERROR_FRAMING)
1177 tty_insert_flip_char(&port->port, data[i+1],
1181 tty_flip_buffer_push(&port->port);
1184 /* Resubmit urb so we continue receiving */
1185 err = usb_submit_urb(urb, GFP_ATOMIC);
1187 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
1190 static void usa49wg_indat_callback(struct urb *urb)
1193 struct usb_serial *serial;
1194 struct usb_serial_port *port;
1195 unsigned char *data = urb->transfer_buffer;
1196 int status = urb->status;
1198 serial = urb->context;
1201 dev_dbg(&urb->dev->dev, "%s - nonzero status: %d\n",
1206 /* inbound data is in the form P#, len, status, data */
1210 while (i < urb->actual_length) {
1212 /* Check port number from message */
1213 if (data[i] >= serial->num_ports) {
1214 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
1218 port = serial->port[data[i++]];
1221 /* 0x80 bit is error flag */
1222 if ((data[i] & 0x80) == 0) {
1223 /* no error on any byte */
1225 for (x = 1; x < len && i < urb->actual_length; ++x)
1226 tty_insert_flip_char(&port->port,
1230 * some bytes had errors, every byte has status
1232 for (x = 0; x + 1 < len &&
1233 i + 1 < urb->actual_length; x += 2) {
1235 int flag = TTY_NORMAL;
1237 if (stat & RXERROR_OVERRUN) {
1238 tty_insert_flip_char(&port->port, 0,
1241 /* XXX should handle break (0x10) */
1242 if (stat & RXERROR_PARITY)
1244 else if (stat & RXERROR_FRAMING)
1247 tty_insert_flip_char(&port->port, data[i+1],
1252 tty_flip_buffer_push(&port->port);
1255 /* Resubmit urb so we continue receiving */
1256 err = usb_submit_urb(urb, GFP_ATOMIC);
1258 dev_dbg(&urb->dev->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
1261 /* not used, usa-49 doesn't have per-port control endpoints */
1262 static void usa49_outcont_callback(struct urb *urb)
1266 static void usa90_indat_callback(struct urb *urb)
1270 struct usb_serial_port *port;
1271 struct keyspan_port_private *p_priv;
1272 unsigned char *data = urb->transfer_buffer;
1273 int status = urb->status;
1275 endpoint = usb_pipeendpoint(urb->pipe);
1278 dev_dbg(&urb->dev->dev, "%s - nonzero status %d on endpoint %x\n",
1279 __func__, status, endpoint);
1283 port = urb->context;
1284 p_priv = usb_get_serial_port_data(port);
1286 if (urb->actual_length) {
1287 /* if current mode is DMA, looks like usa28 format
1288 otherwise looks like usa26 data format */
1290 if (p_priv->baud > 57600)
1291 tty_insert_flip_string(&port->port, data,
1292 urb->actual_length);
1294 /* 0x80 bit is error flag */
1295 if ((data[0] & 0x80) == 0) {
1296 /* no errors on individual bytes, only
1297 possible overrun err*/
1298 if (data[0] & RXERROR_OVERRUN) {
1299 tty_insert_flip_char(&port->port, 0,
1302 for (i = 1; i < urb->actual_length ; ++i)
1303 tty_insert_flip_char(&port->port,
1304 data[i], TTY_NORMAL);
1306 /* some bytes had errors, every byte has status */
1307 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
1308 for (i = 0; i + 1 < urb->actual_length; i += 2) {
1310 int flag = TTY_NORMAL;
1312 if (stat & RXERROR_OVERRUN) {
1313 tty_insert_flip_char(
1317 /* XXX should handle break (0x10) */
1318 if (stat & RXERROR_PARITY)
1320 else if (stat & RXERROR_FRAMING)
1323 tty_insert_flip_char(&port->port,
1328 tty_flip_buffer_push(&port->port);
1331 /* Resubmit urb so we continue receiving */
1332 err = usb_submit_urb(urb, GFP_ATOMIC);
1334 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
1338 static void usa90_instat_callback(struct urb *urb)
1340 unsigned char *data = urb->transfer_buffer;
1341 struct keyspan_usa90_portStatusMessage *msg;
1342 struct usb_serial *serial;
1343 struct usb_serial_port *port;
1344 struct keyspan_port_private *p_priv;
1345 int old_dcd_state, err;
1346 int status = urb->status;
1348 serial = urb->context;
1351 dev_dbg(&urb->dev->dev, "%s - nonzero status: %d\n",
1355 if (urb->actual_length < 14) {
1356 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
1360 msg = (struct keyspan_usa90_portStatusMessage *)data;
1362 /* Now do something useful with the data */
1364 port = serial->port[0];
1365 p_priv = usb_get_serial_port_data(port);
1369 /* Update handshaking pin state information */
1370 old_dcd_state = p_priv->dcd_state;
1371 p_priv->cts_state = ((msg->cts) ? 1 : 0);
1372 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
1373 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
1374 p_priv->ri_state = ((msg->ri) ? 1 : 0);
1376 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
1377 tty_port_tty_hangup(&port->port, true);
1379 /* Resubmit urb so we continue receiving */
1380 err = usb_submit_urb(urb, GFP_ATOMIC);
1382 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
1387 static void usa90_outcont_callback(struct urb *urb)
1389 struct usb_serial_port *port;
1390 struct keyspan_port_private *p_priv;
1392 port = urb->context;
1393 p_priv = usb_get_serial_port_data(port);
1395 if (p_priv->resend_cont) {
1396 dev_dbg(&urb->dev->dev, "%s - sending setup\n", __func__);
1397 keyspan_usa90_send_setup(port->serial, port,
1398 p_priv->resend_cont - 1);
1402 /* Status messages from the 28xg */
1403 static void usa67_instat_callback(struct urb *urb)
1406 unsigned char *data = urb->transfer_buffer;
1407 struct keyspan_usa67_portStatusMessage *msg;
1408 struct usb_serial *serial;
1409 struct usb_serial_port *port;
1410 struct keyspan_port_private *p_priv;
1412 int status = urb->status;
1414 serial = urb->context;
1417 dev_dbg(&urb->dev->dev, "%s - nonzero status: %d\n",
1422 if (urb->actual_length !=
1423 sizeof(struct keyspan_usa67_portStatusMessage)) {
1424 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
1429 /* Now do something useful with the data */
1430 msg = (struct keyspan_usa67_portStatusMessage *)data;
1432 /* Check port number from message and retrieve private data */
1433 if (msg->port >= serial->num_ports) {
1434 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
1438 port = serial->port[msg->port];
1439 p_priv = usb_get_serial_port_data(port);
1443 /* Update handshaking pin state information */
1444 old_dcd_state = p_priv->dcd_state;
1445 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
1446 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
1448 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
1449 tty_port_tty_hangup(&port->port, true);
1451 /* Resubmit urb so we continue receiving */
1452 err = usb_submit_urb(urb, GFP_ATOMIC);
1454 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
1457 static void usa67_glocont_callback(struct urb *urb)
1459 struct usb_serial *serial;
1460 struct usb_serial_port *port;
1461 struct keyspan_port_private *p_priv;
1464 serial = urb->context;
1465 for (i = 0; i < serial->num_ports; ++i) {
1466 port = serial->port[i];
1467 p_priv = usb_get_serial_port_data(port);
1471 if (p_priv->resend_cont) {
1472 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
1473 keyspan_usa67_send_setup(serial, port,
1474 p_priv->resend_cont - 1);
1480 static int keyspan_write_room(struct tty_struct *tty)
1482 struct usb_serial_port *port = tty->driver_data;
1483 struct keyspan_port_private *p_priv;
1484 const struct keyspan_device_details *d_details;
1487 struct urb *this_urb;
1489 p_priv = usb_get_serial_port_data(port);
1490 d_details = p_priv->device_details;
1492 /* FIXME: locking */
1493 if (d_details->msg_format == msg_usa90)
1498 flip = p_priv->out_flip;
1500 /* Check both endpoints to see if any are available. */
1501 this_urb = p_priv->out_urbs[flip];
1502 if (this_urb != NULL) {
1503 if (this_urb->status != -EINPROGRESS)
1505 flip = (flip + 1) & d_details->outdat_endp_flip;
1506 this_urb = p_priv->out_urbs[flip];
1507 if (this_urb != NULL) {
1508 if (this_urb->status != -EINPROGRESS)
1516 static int keyspan_open(struct tty_struct *tty, struct usb_serial_port *port)
1518 struct keyspan_port_private *p_priv;
1519 const struct keyspan_device_details *d_details;
1521 int baud_rate, device_port;
1523 unsigned int cflag = 0;
1525 p_priv = usb_get_serial_port_data(port);
1526 d_details = p_priv->device_details;
1528 /* Set some sane defaults */
1529 p_priv->rts_state = 1;
1530 p_priv->dtr_state = 1;
1531 p_priv->baud = 9600;
1533 /* force baud and lcr to be set on open */
1534 p_priv->old_baud = 0;
1535 p_priv->old_cflag = 0;
1537 p_priv->out_flip = 0;
1538 p_priv->in_flip = 0;
1540 /* Reset low level data toggle and start reading from endpoints */
1541 for (i = 0; i < 2; i++) {
1542 urb = p_priv->in_urbs[i];
1546 /* make sure endpoint data toggle is synchronized
1548 usb_clear_halt(urb->dev, urb->pipe);
1549 err = usb_submit_urb(urb, GFP_KERNEL);
1551 dev_dbg(&port->dev, "%s - submit urb %d failed (%d)\n", __func__, i, err);
1554 /* Reset low level data toggle on out endpoints */
1555 for (i = 0; i < 2; i++) {
1556 urb = p_priv->out_urbs[i];
1559 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
1560 usb_pipeout(urb->pipe), 0); */
1563 /* get the terminal config for the setup message now so we don't
1564 * need to send 2 of them */
1566 device_port = port->port_number;
1568 cflag = tty->termios.c_cflag;
1569 /* Baud rate calculation takes baud rate as an integer
1570 so other rates can be generated if desired. */
1571 baud_rate = tty_get_baud_rate(tty);
1572 /* If no match or invalid, leave as default */
1574 && d_details->calculate_baud_rate(port, baud_rate, d_details->baudclk,
1575 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
1576 p_priv->baud = baud_rate;
1579 /* set CTS/RTS handshake etc. */
1580 p_priv->cflag = cflag;
1581 p_priv->flow_control = (cflag & CRTSCTS) ? flow_cts : flow_none;
1583 keyspan_send_setup(port, 1);
1585 /* keyspan_set_termios(port, NULL); */
1590 static void keyspan_dtr_rts(struct usb_serial_port *port, int on)
1592 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
1594 p_priv->rts_state = on;
1595 p_priv->dtr_state = on;
1596 keyspan_send_setup(port, 0);
1599 static void keyspan_close(struct usb_serial_port *port)
1602 struct keyspan_port_private *p_priv;
1604 p_priv = usb_get_serial_port_data(port);
1606 p_priv->rts_state = 0;
1607 p_priv->dtr_state = 0;
1609 keyspan_send_setup(port, 2);
1610 /* pilot-xfer seems to work best with this delay */
1613 p_priv->out_flip = 0;
1614 p_priv->in_flip = 0;
1616 usb_kill_urb(p_priv->inack_urb);
1617 for (i = 0; i < 2; i++) {
1618 usb_kill_urb(p_priv->in_urbs[i]);
1619 usb_kill_urb(p_priv->out_urbs[i]);
1623 /* download the firmware to a pre-renumeration device */
1624 static int keyspan_fake_startup(struct usb_serial *serial)
1628 dev_dbg(&serial->dev->dev, "Keyspan startup version %04x product %04x\n",
1629 le16_to_cpu(serial->dev->descriptor.bcdDevice),
1630 le16_to_cpu(serial->dev->descriptor.idProduct));
1632 if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000)
1634 dev_dbg(&serial->dev->dev, "Firmware already loaded. Quitting.\n");
1638 /* Select firmware image on the basis of idProduct */
1639 switch (le16_to_cpu(serial->dev->descriptor.idProduct)) {
1640 case keyspan_usa28_pre_product_id:
1641 fw_name = "/*(DEBLOBBED)*/";
1644 case keyspan_usa28x_pre_product_id:
1645 fw_name = "/*(DEBLOBBED)*/";
1648 case keyspan_usa28xa_pre_product_id:
1649 fw_name = "/*(DEBLOBBED)*/";
1652 case keyspan_usa28xb_pre_product_id:
1653 fw_name = "/*(DEBLOBBED)*/";
1656 case keyspan_usa19_pre_product_id:
1657 fw_name = "/*(DEBLOBBED)*/";
1660 case keyspan_usa19qi_pre_product_id:
1661 fw_name = "/*(DEBLOBBED)*/";
1664 case keyspan_mpr_pre_product_id:
1665 fw_name = "/*(DEBLOBBED)*/";
1668 case keyspan_usa19qw_pre_product_id:
1669 fw_name = "/*(DEBLOBBED)*/";
1672 case keyspan_usa18x_pre_product_id:
1673 fw_name = "/*(DEBLOBBED)*/";
1676 case keyspan_usa19w_pre_product_id:
1677 fw_name = "/*(DEBLOBBED)*/";
1680 case keyspan_usa49w_pre_product_id:
1681 fw_name = "/*(DEBLOBBED)*/";
1684 case keyspan_usa49wlc_pre_product_id:
1685 fw_name = "/*(DEBLOBBED)*/";
1689 dev_err(&serial->dev->dev, "Unknown product ID (%04x)\n",
1690 le16_to_cpu(serial->dev->descriptor.idProduct));
1694 dev_dbg(&serial->dev->dev, "Uploading Keyspan %s firmware.\n", fw_name);
1696 if (ezusb_fx1_ihex_firmware_download(serial->dev, fw_name) < 0) {
1697 dev_err(&serial->dev->dev, "failed to load firmware \"%s\"\n",
1702 /* after downloading firmware Renumeration will occur in a
1703 moment and the new device will bind to the real driver */
1705 /* we don't want this device to have a driver assigned to it. */
1709 /* Helper functions used by keyspan_setup_urbs */
1710 static struct usb_endpoint_descriptor const *find_ep(struct usb_serial const *serial,
1713 struct usb_host_interface *iface_desc;
1714 struct usb_endpoint_descriptor *ep;
1717 iface_desc = serial->interface->cur_altsetting;
1718 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
1719 ep = &iface_desc->endpoint[i].desc;
1720 if (ep->bEndpointAddress == endpoint)
1723 dev_warn(&serial->interface->dev, "found no endpoint descriptor for endpoint %x\n",
1728 static struct urb *keyspan_setup_urb(struct usb_serial *serial, int endpoint,
1729 int dir, void *ctx, char *buf, int len,
1730 void (*callback)(struct urb *))
1733 struct usb_endpoint_descriptor const *ep_desc;
1734 char const *ep_type_name;
1737 return NULL; /* endpoint not needed */
1739 dev_dbg(&serial->interface->dev, "%s - alloc for endpoint %x\n",
1740 __func__, endpoint);
1741 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
1745 if (endpoint == 0) {
1746 /* control EP filled in when used */
1750 ep_desc = find_ep(serial, endpoint);
1755 if (usb_endpoint_xfer_int(ep_desc)) {
1756 ep_type_name = "INT";
1757 usb_fill_int_urb(urb, serial->dev,
1758 usb_sndintpipe(serial->dev, endpoint) | dir,
1759 buf, len, callback, ctx,
1760 ep_desc->bInterval);
1761 } else if (usb_endpoint_xfer_bulk(ep_desc)) {
1762 ep_type_name = "BULK";
1763 usb_fill_bulk_urb(urb, serial->dev,
1764 usb_sndbulkpipe(serial->dev, endpoint) | dir,
1765 buf, len, callback, ctx);
1767 dev_warn(&serial->interface->dev,
1768 "unsupported endpoint type %x\n",
1769 usb_endpoint_type(ep_desc));
1774 dev_dbg(&serial->interface->dev, "%s - using urb %p for %s endpoint %x\n",
1775 __func__, urb, ep_type_name, endpoint);
1779 static struct callbacks {
1780 void (*instat_callback)(struct urb *);
1781 void (*glocont_callback)(struct urb *);
1782 void (*indat_callback)(struct urb *);
1783 void (*outdat_callback)(struct urb *);
1784 void (*inack_callback)(struct urb *);
1785 void (*outcont_callback)(struct urb *);
1786 } keyspan_callbacks[] = {
1788 /* msg_usa26 callbacks */
1789 .instat_callback = usa26_instat_callback,
1790 .glocont_callback = usa26_glocont_callback,
1791 .indat_callback = usa26_indat_callback,
1792 .outdat_callback = usa2x_outdat_callback,
1793 .inack_callback = usa26_inack_callback,
1794 .outcont_callback = usa26_outcont_callback,
1796 /* msg_usa28 callbacks */
1797 .instat_callback = usa28_instat_callback,
1798 .glocont_callback = usa28_glocont_callback,
1799 .indat_callback = usa28_indat_callback,
1800 .outdat_callback = usa2x_outdat_callback,
1801 .inack_callback = usa28_inack_callback,
1802 .outcont_callback = usa28_outcont_callback,
1804 /* msg_usa49 callbacks */
1805 .instat_callback = usa49_instat_callback,
1806 .glocont_callback = usa49_glocont_callback,
1807 .indat_callback = usa49_indat_callback,
1808 .outdat_callback = usa2x_outdat_callback,
1809 .inack_callback = usa49_inack_callback,
1810 .outcont_callback = usa49_outcont_callback,
1812 /* msg_usa90 callbacks */
1813 .instat_callback = usa90_instat_callback,
1814 .glocont_callback = usa28_glocont_callback,
1815 .indat_callback = usa90_indat_callback,
1816 .outdat_callback = usa2x_outdat_callback,
1817 .inack_callback = usa28_inack_callback,
1818 .outcont_callback = usa90_outcont_callback,
1820 /* msg_usa67 callbacks */
1821 .instat_callback = usa67_instat_callback,
1822 .glocont_callback = usa67_glocont_callback,
1823 .indat_callback = usa26_indat_callback,
1824 .outdat_callback = usa2x_outdat_callback,
1825 .inack_callback = usa26_inack_callback,
1826 .outcont_callback = usa26_outcont_callback,
1830 /* Generic setup urbs function that uses
1831 data in device_details */
1832 static void keyspan_setup_urbs(struct usb_serial *serial)
1834 struct keyspan_serial_private *s_priv;
1835 const struct keyspan_device_details *d_details;
1836 struct callbacks *cback;
1838 s_priv = usb_get_serial_data(serial);
1839 d_details = s_priv->device_details;
1841 /* Setup values for the various callback routines */
1842 cback = &keyspan_callbacks[d_details->msg_format];
1844 /* Allocate and set up urbs for each one that is in use,
1845 starting with instat endpoints */
1846 s_priv->instat_urb = keyspan_setup_urb
1847 (serial, d_details->instat_endpoint, USB_DIR_IN,
1848 serial, s_priv->instat_buf, INSTAT_BUFLEN,
1849 cback->instat_callback);
1851 s_priv->indat_urb = keyspan_setup_urb
1852 (serial, d_details->indat_endpoint, USB_DIR_IN,
1853 serial, s_priv->indat_buf, INDAT49W_BUFLEN,
1854 usa49wg_indat_callback);
1856 s_priv->glocont_urb = keyspan_setup_urb
1857 (serial, d_details->glocont_endpoint, USB_DIR_OUT,
1858 serial, s_priv->glocont_buf, GLOCONT_BUFLEN,
1859 cback->glocont_callback);
1862 /* usa19 function doesn't require prescaler */
1863 static int keyspan_usa19_calc_baud(struct usb_serial_port *port,
1864 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1865 u8 *rate_low, u8 *prescaler, int portnum)
1867 u32 b16, /* baud rate times 16 (actual rate used internally) */
1869 cnt; /* inverse of divisor (programmed into 8051) */
1871 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1873 /* prevent divide by zero... */
1874 b16 = baud_rate * 16L;
1876 return KEYSPAN_INVALID_BAUD_RATE;
1877 /* Any "standard" rate over 57k6 is marginal on the USA-19
1878 as we run out of divisor resolution. */
1879 if (baud_rate > 57600)
1880 return KEYSPAN_INVALID_BAUD_RATE;
1882 /* calculate the divisor and the counter (its inverse) */
1883 div = baudclk / b16;
1885 return KEYSPAN_INVALID_BAUD_RATE;
1890 return KEYSPAN_INVALID_BAUD_RATE;
1892 /* return the counter values if non-null */
1894 *rate_low = (u8) (cnt & 0xff);
1896 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1897 if (rate_low && rate_hi)
1898 dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
1899 __func__, baud_rate, *rate_hi, *rate_low);
1900 return KEYSPAN_BAUD_RATE_OK;
1903 /* usa19hs function doesn't require prescaler */
1904 static int keyspan_usa19hs_calc_baud(struct usb_serial_port *port,
1905 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1906 u8 *rate_low, u8 *prescaler, int portnum)
1908 u32 b16, /* baud rate times 16 (actual rate used internally) */
1911 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1913 /* prevent divide by zero... */
1914 b16 = baud_rate * 16L;
1916 return KEYSPAN_INVALID_BAUD_RATE;
1918 /* calculate the divisor */
1919 div = baudclk / b16;
1921 return KEYSPAN_INVALID_BAUD_RATE;
1924 return KEYSPAN_INVALID_BAUD_RATE;
1926 /* return the counter values if non-null */
1928 *rate_low = (u8) (div & 0xff);
1931 *rate_hi = (u8) ((div >> 8) & 0xff);
1933 if (rate_low && rate_hi)
1934 dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
1935 __func__, baud_rate, *rate_hi, *rate_low);
1937 return KEYSPAN_BAUD_RATE_OK;
1940 static int keyspan_usa19w_calc_baud(struct usb_serial_port *port,
1941 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1942 u8 *rate_low, u8 *prescaler, int portnum)
1944 u32 b16, /* baud rate times 16 (actual rate used internally) */
1945 clk, /* clock with 13/8 prescaler */
1946 div, /* divisor using 13/8 prescaler */
1947 res, /* resulting baud rate using 13/8 prescaler */
1948 diff, /* error using 13/8 prescaler */
1953 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1955 /* prevent divide by zero */
1956 b16 = baud_rate * 16L;
1958 return KEYSPAN_INVALID_BAUD_RATE;
1960 /* Calculate prescaler by trying them all and looking
1963 /* start with largest possible difference */
1964 smallest_diff = 0xffffffff;
1966 /* 0 is an invalid prescaler, used as a flag */
1969 for (i = 8; i <= 0xff; ++i) {
1970 clk = (baudclk * 8) / (u32) i;
1977 diff = (res > b16) ? (res-b16) : (b16-res);
1979 if (diff < smallest_diff) {
1981 smallest_diff = diff;
1985 if (best_prescaler == 0)
1986 return KEYSPAN_INVALID_BAUD_RATE;
1988 clk = (baudclk * 8) / (u32) best_prescaler;
1991 /* return the divisor and prescaler if non-null */
1993 *rate_low = (u8) (div & 0xff);
1995 *rate_hi = (u8) ((div >> 8) & 0xff);
1997 *prescaler = best_prescaler;
1998 /* dev_dbg(&port->dev, "%s - %d %d\n", __func__, *prescaler, div); */
2000 return KEYSPAN_BAUD_RATE_OK;
2003 /* USA-28 supports different maximum baud rates on each port */
2004 static int keyspan_usa28_calc_baud(struct usb_serial_port *port,
2005 u32 baud_rate, u32 baudclk, u8 *rate_hi,
2006 u8 *rate_low, u8 *prescaler, int portnum)
2008 u32 b16, /* baud rate times 16 (actual rate used internally) */
2010 cnt; /* inverse of divisor (programmed into 8051) */
2012 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
2014 /* prevent divide by zero */
2015 b16 = baud_rate * 16L;
2017 return KEYSPAN_INVALID_BAUD_RATE;
2019 /* calculate the divisor and the counter (its inverse) */
2020 div = KEYSPAN_USA28_BAUDCLK / b16;
2022 return KEYSPAN_INVALID_BAUD_RATE;
2026 /* check for out of range, based on portnum,
2027 and return result */
2030 return KEYSPAN_INVALID_BAUD_RATE;
2034 return KEYSPAN_INVALID_BAUD_RATE;
2036 return KEYSPAN_INVALID_BAUD_RATE;
2039 /* return the counter values if not NULL
2040 (port 1 will ignore retHi) */
2042 *rate_low = (u8) (cnt & 0xff);
2044 *rate_hi = (u8) ((cnt >> 8) & 0xff);
2045 dev_dbg(&port->dev, "%s - %d OK.\n", __func__, baud_rate);
2046 return KEYSPAN_BAUD_RATE_OK;
2049 static int keyspan_usa26_send_setup(struct usb_serial *serial,
2050 struct usb_serial_port *port,
2053 struct keyspan_usa26_portControlMessage msg;
2054 struct keyspan_serial_private *s_priv;
2055 struct keyspan_port_private *p_priv;
2056 const struct keyspan_device_details *d_details;
2057 struct urb *this_urb;
2058 int device_port, err;
2060 dev_dbg(&port->dev, "%s reset=%d\n", __func__, reset_port);
2062 s_priv = usb_get_serial_data(serial);
2063 p_priv = usb_get_serial_port_data(port);
2064 d_details = s_priv->device_details;
2065 device_port = port->port_number;
2067 this_urb = p_priv->outcont_urb;
2069 /* Make sure we have an urb then send the message */
2070 if (this_urb == NULL) {
2071 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
2075 dev_dbg(&port->dev, "%s - endpoint %x\n",
2076 __func__, usb_pipeendpoint(this_urb->pipe));
2078 /* Save reset port val for resend.
2079 Don't overwrite resend for open/close condition. */
2080 if ((reset_port + 1) > p_priv->resend_cont)
2081 p_priv->resend_cont = reset_port + 1;
2082 if (this_urb->status == -EINPROGRESS) {
2083 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
2088 memset(&msg, 0, sizeof(struct keyspan_usa26_portControlMessage));
2090 /* Only set baud rate if it's changed */
2091 if (p_priv->old_baud != p_priv->baud) {
2092 p_priv->old_baud = p_priv->baud;
2093 msg.setClocking = 0xff;
2094 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2095 &msg.baudHi, &msg.baudLo, &msg.prescaler,
2096 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2097 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2098 __func__, p_priv->baud);
2100 msg.baudHi = 125; /* Values for 9600 baud */
2103 msg.setPrescaler = 0xff;
2106 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2107 switch (p_priv->cflag & CSIZE) {
2109 msg.lcr |= USA_DATABITS_5;
2112 msg.lcr |= USA_DATABITS_6;
2115 msg.lcr |= USA_DATABITS_7;
2118 msg.lcr |= USA_DATABITS_8;
2121 if (p_priv->cflag & PARENB) {
2122 /* note USA_PARITY_NONE == 0 */
2123 msg.lcr |= (p_priv->cflag & PARODD) ?
2124 USA_PARITY_ODD : USA_PARITY_EVEN;
2128 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2129 msg.xonFlowControl = 0;
2130 msg.setFlowControl = 0xff;
2131 msg.forwardingLength = 16;
2136 if (reset_port == 1) {
2145 msg.returnStatus = 0;
2146 msg.resetDataToggle = 0xff;
2150 else if (reset_port == 2) {
2159 msg.returnStatus = 0;
2160 msg.resetDataToggle = 0;
2163 /* Sending intermediate configs */
2165 msg._txOn = (!p_priv->break_on);
2168 msg.txBreak = (p_priv->break_on);
2173 msg.returnStatus = 0;
2174 msg.resetDataToggle = 0x0;
2177 /* Do handshaking outputs */
2178 msg.setTxTriState_setRts = 0xff;
2179 msg.txTriState_rts = p_priv->rts_state;
2181 msg.setHskoa_setDtr = 0xff;
2182 msg.hskoa_dtr = p_priv->dtr_state;
2184 p_priv->resend_cont = 0;
2185 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2187 /* send the data out the device on control endpoint */
2188 this_urb->transfer_buffer_length = sizeof(msg);
2190 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2192 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2196 static int keyspan_usa28_send_setup(struct usb_serial *serial,
2197 struct usb_serial_port *port,
2200 struct keyspan_usa28_portControlMessage msg;
2201 struct keyspan_serial_private *s_priv;
2202 struct keyspan_port_private *p_priv;
2203 const struct keyspan_device_details *d_details;
2204 struct urb *this_urb;
2205 int device_port, err;
2207 s_priv = usb_get_serial_data(serial);
2208 p_priv = usb_get_serial_port_data(port);
2209 d_details = s_priv->device_details;
2210 device_port = port->port_number;
2212 /* only do something if we have a bulk out endpoint */
2213 this_urb = p_priv->outcont_urb;
2214 if (this_urb == NULL) {
2215 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
2219 /* Save reset port val for resend.
2220 Don't overwrite resend for open/close condition. */
2221 if ((reset_port + 1) > p_priv->resend_cont)
2222 p_priv->resend_cont = reset_port + 1;
2223 if (this_urb->status == -EINPROGRESS) {
2224 dev_dbg(&port->dev, "%s already writing\n", __func__);
2229 memset(&msg, 0, sizeof(struct keyspan_usa28_portControlMessage));
2231 msg.setBaudRate = 1;
2232 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2233 &msg.baudHi, &msg.baudLo, NULL,
2234 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2235 dev_dbg(&port->dev, "%s - Invalid baud rate requested %d.\n",
2236 __func__, p_priv->baud);
2238 msg.baudHi = 0xb2; /* Values for 9600 baud */
2241 /* If parity is enabled, we must calculate it ourselves. */
2242 msg.parity = 0; /* XXX for now */
2244 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2245 msg.xonFlowControl = 0;
2247 /* Do handshaking outputs, DTR is inverted relative to RTS */
2248 msg.rts = p_priv->rts_state;
2249 msg.dtr = p_priv->dtr_state;
2251 msg.forwardingLength = 16;
2253 msg.breakThreshold = 45;
2257 /*msg.returnStatus = 1;
2258 msg.resetDataToggle = 0xff;*/
2260 if (reset_port == 1) {
2264 msg.txForceXoff = 0;
2270 msg.returnStatus = 0;
2271 msg.resetDataToggle = 0xff;
2274 else if (reset_port == 2) {
2278 msg.txForceXoff = 0;
2284 msg.returnStatus = 0;
2285 msg.resetDataToggle = 0;
2287 /* Sending intermediate configs */
2289 msg._txOn = (!p_priv->break_on);
2292 msg.txForceXoff = 0;
2293 msg.txBreak = (p_priv->break_on);
2298 msg.returnStatus = 0;
2299 msg.resetDataToggle = 0x0;
2302 p_priv->resend_cont = 0;
2303 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2305 /* send the data out the device on control endpoint */
2306 this_urb->transfer_buffer_length = sizeof(msg);
2308 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2310 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed\n", __func__);
2315 static int keyspan_usa49_send_setup(struct usb_serial *serial,
2316 struct usb_serial_port *port,
2319 struct keyspan_usa49_portControlMessage msg;
2320 struct usb_ctrlrequest *dr = NULL;
2321 struct keyspan_serial_private *s_priv;
2322 struct keyspan_port_private *p_priv;
2323 const struct keyspan_device_details *d_details;
2324 struct urb *this_urb;
2325 int err, device_port;
2327 s_priv = usb_get_serial_data(serial);
2328 p_priv = usb_get_serial_port_data(port);
2329 d_details = s_priv->device_details;
2331 this_urb = s_priv->glocont_urb;
2333 /* Work out which port within the device is being setup */
2334 device_port = port->port_number;
2336 /* Make sure we have an urb then send the message */
2337 if (this_urb == NULL) {
2338 dev_dbg(&port->dev, "%s - oops no urb for port.\n", __func__);
2342 dev_dbg(&port->dev, "%s - endpoint %x (%d)\n",
2343 __func__, usb_pipeendpoint(this_urb->pipe), device_port);
2345 /* Save reset port val for resend.
2346 Don't overwrite resend for open/close condition. */
2347 if ((reset_port + 1) > p_priv->resend_cont)
2348 p_priv->resend_cont = reset_port + 1;
2350 if (this_urb->status == -EINPROGRESS) {
2351 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
2356 memset(&msg, 0, sizeof(struct keyspan_usa49_portControlMessage));
2358 msg.portNumber = device_port;
2360 /* Only set baud rate if it's changed */
2361 if (p_priv->old_baud != p_priv->baud) {
2362 p_priv->old_baud = p_priv->baud;
2363 msg.setClocking = 0xff;
2364 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2365 &msg.baudHi, &msg.baudLo, &msg.prescaler,
2366 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2367 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2368 __func__, p_priv->baud);
2370 msg.baudHi = 125; /* Values for 9600 baud */
2373 /* msg.setPrescaler = 0xff; */
2376 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2377 switch (p_priv->cflag & CSIZE) {
2379 msg.lcr |= USA_DATABITS_5;
2382 msg.lcr |= USA_DATABITS_6;
2385 msg.lcr |= USA_DATABITS_7;
2388 msg.lcr |= USA_DATABITS_8;
2391 if (p_priv->cflag & PARENB) {
2392 /* note USA_PARITY_NONE == 0 */
2393 msg.lcr |= (p_priv->cflag & PARODD) ?
2394 USA_PARITY_ODD : USA_PARITY_EVEN;
2398 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2399 msg.xonFlowControl = 0;
2400 msg.setFlowControl = 0xff;
2402 msg.forwardingLength = 16;
2407 if (reset_port == 1) {
2416 msg.returnStatus = 0;
2417 msg.resetDataToggle = 0xff;
2419 msg.disablePort = 0;
2422 else if (reset_port == 2) {
2431 msg.returnStatus = 0;
2432 msg.resetDataToggle = 0;
2434 msg.disablePort = 1;
2436 /* Sending intermediate configs */
2438 msg._txOn = (!p_priv->break_on);
2441 msg.txBreak = (p_priv->break_on);
2446 msg.returnStatus = 0;
2447 msg.resetDataToggle = 0x0;
2449 msg.disablePort = 0;
2452 /* Do handshaking outputs */
2454 msg.rts = p_priv->rts_state;
2457 msg.dtr = p_priv->dtr_state;
2459 p_priv->resend_cont = 0;
2461 /* if the device is a 49wg, we send control message on usb
2464 if (d_details->product_id == keyspan_usa49wg_product_id) {
2465 dr = (void *)(s_priv->ctrl_buf);
2466 dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_OUT;
2467 dr->bRequest = 0xB0; /* 49wg control message */
2470 dr->wLength = cpu_to_le16(sizeof(msg));
2472 memcpy(s_priv->glocont_buf, &msg, sizeof(msg));
2474 usb_fill_control_urb(this_urb, serial->dev,
2475 usb_sndctrlpipe(serial->dev, 0),
2476 (unsigned char *)dr, s_priv->glocont_buf,
2477 sizeof(msg), usa49_glocont_callback, serial);
2480 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2482 /* send the data out the device on control endpoint */
2483 this_urb->transfer_buffer_length = sizeof(msg);
2485 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2487 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2492 static int keyspan_usa90_send_setup(struct usb_serial *serial,
2493 struct usb_serial_port *port,
2496 struct keyspan_usa90_portControlMessage msg;
2497 struct keyspan_serial_private *s_priv;
2498 struct keyspan_port_private *p_priv;
2499 const struct keyspan_device_details *d_details;
2500 struct urb *this_urb;
2504 s_priv = usb_get_serial_data(serial);
2505 p_priv = usb_get_serial_port_data(port);
2506 d_details = s_priv->device_details;
2508 /* only do something if we have a bulk out endpoint */
2509 this_urb = p_priv->outcont_urb;
2510 if (this_urb == NULL) {
2511 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
2515 /* Save reset port val for resend.
2516 Don't overwrite resend for open/close condition. */
2517 if ((reset_port + 1) > p_priv->resend_cont)
2518 p_priv->resend_cont = reset_port + 1;
2519 if (this_urb->status == -EINPROGRESS) {
2520 dev_dbg(&port->dev, "%s already writing\n", __func__);
2525 memset(&msg, 0, sizeof(struct keyspan_usa90_portControlMessage));
2527 /* Only set baud rate if it's changed */
2528 if (p_priv->old_baud != p_priv->baud) {
2529 p_priv->old_baud = p_priv->baud;
2530 msg.setClocking = 0x01;
2531 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2532 &msg.baudHi, &msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE) {
2533 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2534 __func__, p_priv->baud);
2535 p_priv->baud = 9600;
2536 d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2537 &msg.baudHi, &msg.baudLo, &prescaler, 0);
2543 /* modes must always be correctly specified */
2544 if (p_priv->baud > 57600) {
2545 msg.rxMode = RXMODE_DMA;
2546 msg.txMode = TXMODE_DMA;
2548 msg.rxMode = RXMODE_BYHAND;
2549 msg.txMode = TXMODE_BYHAND;
2552 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2553 switch (p_priv->cflag & CSIZE) {
2555 msg.lcr |= USA_DATABITS_5;
2558 msg.lcr |= USA_DATABITS_6;
2561 msg.lcr |= USA_DATABITS_7;
2564 msg.lcr |= USA_DATABITS_8;
2567 if (p_priv->cflag & PARENB) {
2568 /* note USA_PARITY_NONE == 0 */
2569 msg.lcr |= (p_priv->cflag & PARODD) ?
2570 USA_PARITY_ODD : USA_PARITY_EVEN;
2572 if (p_priv->old_cflag != p_priv->cflag) {
2573 p_priv->old_cflag = p_priv->cflag;
2577 if (p_priv->flow_control == flow_cts)
2578 msg.txFlowControl = TXFLOW_CTS;
2579 msg.setTxFlowControl = 0x01;
2580 msg.setRxFlowControl = 0x01;
2582 msg.rxForwardingLength = 16;
2583 msg.rxForwardingTimeout = 16;
2584 msg.txAckSetting = 0;
2589 if (reset_port == 1) {
2590 msg.portEnabled = 1;
2592 msg.txBreak = (p_priv->break_on);
2595 else if (reset_port == 2)
2596 msg.portEnabled = 0;
2597 /* Sending intermediate configs */
2599 msg.portEnabled = 1;
2600 msg.txBreak = (p_priv->break_on);
2603 /* Do handshaking outputs */
2605 msg.rts = p_priv->rts_state;
2608 msg.dtr = p_priv->dtr_state;
2610 p_priv->resend_cont = 0;
2611 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2613 /* send the data out the device on control endpoint */
2614 this_urb->transfer_buffer_length = sizeof(msg);
2616 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2618 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2622 static int keyspan_usa67_send_setup(struct usb_serial *serial,
2623 struct usb_serial_port *port,
2626 struct keyspan_usa67_portControlMessage msg;
2627 struct keyspan_serial_private *s_priv;
2628 struct keyspan_port_private *p_priv;
2629 const struct keyspan_device_details *d_details;
2630 struct urb *this_urb;
2631 int err, device_port;
2633 s_priv = usb_get_serial_data(serial);
2634 p_priv = usb_get_serial_port_data(port);
2635 d_details = s_priv->device_details;
2637 this_urb = s_priv->glocont_urb;
2639 /* Work out which port within the device is being setup */
2640 device_port = port->port_number;
2642 /* Make sure we have an urb then send the message */
2643 if (this_urb == NULL) {
2644 dev_dbg(&port->dev, "%s - oops no urb for port.\n", __func__);
2648 /* Save reset port val for resend.
2649 Don't overwrite resend for open/close condition. */
2650 if ((reset_port + 1) > p_priv->resend_cont)
2651 p_priv->resend_cont = reset_port + 1;
2652 if (this_urb->status == -EINPROGRESS) {
2653 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
2658 memset(&msg, 0, sizeof(struct keyspan_usa67_portControlMessage));
2660 msg.port = device_port;
2662 /* Only set baud rate if it's changed */
2663 if (p_priv->old_baud != p_priv->baud) {
2664 p_priv->old_baud = p_priv->baud;
2665 msg.setClocking = 0xff;
2666 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2667 &msg.baudHi, &msg.baudLo, &msg.prescaler,
2668 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2669 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2670 __func__, p_priv->baud);
2672 msg.baudHi = 125; /* Values for 9600 baud */
2675 msg.setPrescaler = 0xff;
2678 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2679 switch (p_priv->cflag & CSIZE) {
2681 msg.lcr |= USA_DATABITS_5;
2684 msg.lcr |= USA_DATABITS_6;
2687 msg.lcr |= USA_DATABITS_7;
2690 msg.lcr |= USA_DATABITS_8;
2693 if (p_priv->cflag & PARENB) {
2694 /* note USA_PARITY_NONE == 0 */
2695 msg.lcr |= (p_priv->cflag & PARODD) ?
2696 USA_PARITY_ODD : USA_PARITY_EVEN;
2700 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2701 msg.xonFlowControl = 0;
2702 msg.setFlowControl = 0xff;
2703 msg.forwardingLength = 16;
2707 if (reset_port == 1) {
2717 msg.returnStatus = 0;
2718 msg.resetDataToggle = 0xff;
2719 } else if (reset_port == 2) {
2729 msg.returnStatus = 0;
2730 msg.resetDataToggle = 0;
2732 /* Sending intermediate configs */
2733 msg._txOn = (!p_priv->break_on);
2736 msg.txBreak = (p_priv->break_on);
2741 msg.returnStatus = 0;
2742 msg.resetDataToggle = 0x0;
2745 /* Do handshaking outputs */
2746 msg.setTxTriState_setRts = 0xff;
2747 msg.txTriState_rts = p_priv->rts_state;
2749 msg.setHskoa_setDtr = 0xff;
2750 msg.hskoa_dtr = p_priv->dtr_state;
2752 p_priv->resend_cont = 0;
2754 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2756 /* send the data out the device on control endpoint */
2757 this_urb->transfer_buffer_length = sizeof(msg);
2759 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2761 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2765 static void keyspan_send_setup(struct usb_serial_port *port, int reset_port)
2767 struct usb_serial *serial = port->serial;
2768 struct keyspan_serial_private *s_priv;
2769 const struct keyspan_device_details *d_details;
2771 s_priv = usb_get_serial_data(serial);
2772 d_details = s_priv->device_details;
2774 switch (d_details->msg_format) {
2776 keyspan_usa26_send_setup(serial, port, reset_port);
2779 keyspan_usa28_send_setup(serial, port, reset_port);
2782 keyspan_usa49_send_setup(serial, port, reset_port);
2785 keyspan_usa90_send_setup(serial, port, reset_port);
2788 keyspan_usa67_send_setup(serial, port, reset_port);
2794 /* Gets called by the "real" driver (ie once firmware is loaded
2795 and renumeration has taken place. */
2796 static int keyspan_startup(struct usb_serial *serial)
2799 struct keyspan_serial_private *s_priv;
2800 const struct keyspan_device_details *d_details;
2802 for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i)
2803 if (d_details->product_id ==
2804 le16_to_cpu(serial->dev->descriptor.idProduct))
2806 if (d_details == NULL) {
2807 dev_err(&serial->dev->dev, "%s - unknown product id %x\n",
2808 __func__, le16_to_cpu(serial->dev->descriptor.idProduct));
2812 /* Setup private data for serial driver */
2813 s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
2817 s_priv->instat_buf = kzalloc(INSTAT_BUFLEN, GFP_KERNEL);
2818 if (!s_priv->instat_buf)
2819 goto err_instat_buf;
2821 s_priv->indat_buf = kzalloc(INDAT49W_BUFLEN, GFP_KERNEL);
2822 if (!s_priv->indat_buf)
2825 s_priv->glocont_buf = kzalloc(GLOCONT_BUFLEN, GFP_KERNEL);
2826 if (!s_priv->glocont_buf)
2827 goto err_glocont_buf;
2829 s_priv->ctrl_buf = kzalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);
2830 if (!s_priv->ctrl_buf)
2833 s_priv->device_details = d_details;
2834 usb_set_serial_data(serial, s_priv);
2836 keyspan_setup_urbs(serial);
2838 if (s_priv->instat_urb != NULL) {
2839 err = usb_submit_urb(s_priv->instat_urb, GFP_KERNEL);
2841 dev_dbg(&serial->dev->dev, "%s - submit instat urb failed %d\n", __func__, err);
2843 if (s_priv->indat_urb != NULL) {
2844 err = usb_submit_urb(s_priv->indat_urb, GFP_KERNEL);
2846 dev_dbg(&serial->dev->dev, "%s - submit indat urb failed %d\n", __func__, err);
2852 kfree(s_priv->glocont_buf);
2854 kfree(s_priv->indat_buf);
2856 kfree(s_priv->instat_buf);
2863 static void keyspan_disconnect(struct usb_serial *serial)
2865 struct keyspan_serial_private *s_priv;
2867 s_priv = usb_get_serial_data(serial);
2869 usb_kill_urb(s_priv->instat_urb);
2870 usb_kill_urb(s_priv->glocont_urb);
2871 usb_kill_urb(s_priv->indat_urb);
2874 static void keyspan_release(struct usb_serial *serial)
2876 struct keyspan_serial_private *s_priv;
2878 s_priv = usb_get_serial_data(serial);
2880 /* Make sure to unlink the URBs submitted in attach. */
2881 usb_kill_urb(s_priv->instat_urb);
2882 usb_kill_urb(s_priv->indat_urb);
2884 usb_free_urb(s_priv->instat_urb);
2885 usb_free_urb(s_priv->indat_urb);
2886 usb_free_urb(s_priv->glocont_urb);
2888 kfree(s_priv->ctrl_buf);
2889 kfree(s_priv->glocont_buf);
2890 kfree(s_priv->indat_buf);
2891 kfree(s_priv->instat_buf);
2896 static int keyspan_port_probe(struct usb_serial_port *port)
2898 struct usb_serial *serial = port->serial;
2899 struct keyspan_serial_private *s_priv;
2900 struct keyspan_port_private *p_priv;
2901 const struct keyspan_device_details *d_details;
2902 struct callbacks *cback;
2907 s_priv = usb_get_serial_data(serial);
2908 d_details = s_priv->device_details;
2910 p_priv = kzalloc(sizeof(*p_priv), GFP_KERNEL);
2914 for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i) {
2915 p_priv->in_buffer[i] = kzalloc(IN_BUFLEN, GFP_KERNEL);
2916 if (!p_priv->in_buffer[i])
2920 for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i) {
2921 p_priv->out_buffer[i] = kzalloc(OUT_BUFLEN, GFP_KERNEL);
2922 if (!p_priv->out_buffer[i])
2923 goto err_out_buffer;
2926 p_priv->inack_buffer = kzalloc(INACK_BUFLEN, GFP_KERNEL);
2927 if (!p_priv->inack_buffer)
2928 goto err_inack_buffer;
2930 p_priv->outcont_buffer = kzalloc(OUTCONT_BUFLEN, GFP_KERNEL);
2931 if (!p_priv->outcont_buffer)
2932 goto err_outcont_buffer;
2934 p_priv->device_details = d_details;
2936 /* Setup values for the various callback routines */
2937 cback = &keyspan_callbacks[d_details->msg_format];
2939 port_num = port->port_number;
2941 /* Do indat endpoints first, once for each flip */
2942 endp = d_details->indat_endpoints[port_num];
2943 for (i = 0; i <= d_details->indat_endp_flip; ++i, ++endp) {
2944 p_priv->in_urbs[i] = keyspan_setup_urb(serial, endp,
2946 p_priv->in_buffer[i],
2948 cback->indat_callback);
2950 /* outdat endpoints also have flip */
2951 endp = d_details->outdat_endpoints[port_num];
2952 for (i = 0; i <= d_details->outdat_endp_flip; ++i, ++endp) {
2953 p_priv->out_urbs[i] = keyspan_setup_urb(serial, endp,
2955 p_priv->out_buffer[i],
2957 cback->outdat_callback);
2959 /* inack endpoint */
2960 p_priv->inack_urb = keyspan_setup_urb(serial,
2961 d_details->inack_endpoints[port_num],
2963 p_priv->inack_buffer,
2965 cback->inack_callback);
2966 /* outcont endpoint */
2967 p_priv->outcont_urb = keyspan_setup_urb(serial,
2968 d_details->outcont_endpoints[port_num],
2970 p_priv->outcont_buffer,
2972 cback->outcont_callback);
2974 usb_set_serial_port_data(port, p_priv);
2979 kfree(p_priv->inack_buffer);
2981 for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i)
2982 kfree(p_priv->out_buffer[i]);
2984 for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i)
2985 kfree(p_priv->in_buffer[i]);
2992 static int keyspan_port_remove(struct usb_serial_port *port)
2994 struct keyspan_port_private *p_priv;
2997 p_priv = usb_get_serial_port_data(port);
2999 usb_kill_urb(p_priv->inack_urb);
3000 usb_kill_urb(p_priv->outcont_urb);
3001 for (i = 0; i < 2; i++) {
3002 usb_kill_urb(p_priv->in_urbs[i]);
3003 usb_kill_urb(p_priv->out_urbs[i]);
3006 usb_free_urb(p_priv->inack_urb);
3007 usb_free_urb(p_priv->outcont_urb);
3008 for (i = 0; i < 2; i++) {
3009 usb_free_urb(p_priv->in_urbs[i]);
3010 usb_free_urb(p_priv->out_urbs[i]);
3013 kfree(p_priv->outcont_buffer);
3014 kfree(p_priv->inack_buffer);
3015 for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i)
3016 kfree(p_priv->out_buffer[i]);
3017 for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i)
3018 kfree(p_priv->in_buffer[i]);
3025 /* Structs for the devices, pre and post renumeration. */
3026 static struct usb_serial_driver keyspan_pre_device = {
3028 .owner = THIS_MODULE,
3029 .name = "keyspan_no_firm",
3031 .description = "Keyspan - (without firmware)",
3032 .id_table = keyspan_pre_ids,
3034 .attach = keyspan_fake_startup,
3037 static struct usb_serial_driver keyspan_1port_device = {
3039 .owner = THIS_MODULE,
3040 .name = "keyspan_1",
3042 .description = "Keyspan 1 port adapter",
3043 .id_table = keyspan_1port_ids,
3045 .open = keyspan_open,
3046 .close = keyspan_close,
3047 .dtr_rts = keyspan_dtr_rts,
3048 .write = keyspan_write,
3049 .write_room = keyspan_write_room,
3050 .set_termios = keyspan_set_termios,
3051 .break_ctl = keyspan_break_ctl,
3052 .tiocmget = keyspan_tiocmget,
3053 .tiocmset = keyspan_tiocmset,
3054 .attach = keyspan_startup,
3055 .disconnect = keyspan_disconnect,
3056 .release = keyspan_release,
3057 .port_probe = keyspan_port_probe,
3058 .port_remove = keyspan_port_remove,
3061 static struct usb_serial_driver keyspan_2port_device = {
3063 .owner = THIS_MODULE,
3064 .name = "keyspan_2",
3066 .description = "Keyspan 2 port adapter",
3067 .id_table = keyspan_2port_ids,
3069 .open = keyspan_open,
3070 .close = keyspan_close,
3071 .dtr_rts = keyspan_dtr_rts,
3072 .write = keyspan_write,
3073 .write_room = keyspan_write_room,
3074 .set_termios = keyspan_set_termios,
3075 .break_ctl = keyspan_break_ctl,
3076 .tiocmget = keyspan_tiocmget,
3077 .tiocmset = keyspan_tiocmset,
3078 .attach = keyspan_startup,
3079 .disconnect = keyspan_disconnect,
3080 .release = keyspan_release,
3081 .port_probe = keyspan_port_probe,
3082 .port_remove = keyspan_port_remove,
3085 static struct usb_serial_driver keyspan_4port_device = {
3087 .owner = THIS_MODULE,
3088 .name = "keyspan_4",
3090 .description = "Keyspan 4 port adapter",
3091 .id_table = keyspan_4port_ids,
3093 .open = keyspan_open,
3094 .close = keyspan_close,
3095 .dtr_rts = keyspan_dtr_rts,
3096 .write = keyspan_write,
3097 .write_room = keyspan_write_room,
3098 .set_termios = keyspan_set_termios,
3099 .break_ctl = keyspan_break_ctl,
3100 .tiocmget = keyspan_tiocmget,
3101 .tiocmset = keyspan_tiocmset,
3102 .attach = keyspan_startup,
3103 .disconnect = keyspan_disconnect,
3104 .release = keyspan_release,
3105 .port_probe = keyspan_port_probe,
3106 .port_remove = keyspan_port_remove,
3109 static struct usb_serial_driver * const serial_drivers[] = {
3110 &keyspan_pre_device, &keyspan_1port_device,
3111 &keyspan_2port_device, &keyspan_4port_device, NULL
3114 module_usb_serial_driver(serial_drivers, keyspan_ids_combined);
3116 MODULE_AUTHOR(DRIVER_AUTHOR);
3117 MODULE_DESCRIPTION(DRIVER_DESC);
3118 MODULE_LICENSE("GPL");