diff options
author | Anton Vorontsov <cbouatmailru@gmail.com> | 2008-07-29 18:05:23 -0400 |
---|---|---|
committer | Anton Vorontsov <cbouatmailru@gmail.com> | 2008-07-29 18:05:23 -0400 |
commit | 9fec6060d9e48ed7db0dac0e16d0f0f0e615b7f6 (patch) | |
tree | 74b41f31a08f6500ff3dfcf64ba21e2d9a8e87e5 /drivers/usb/serial/garmin_gps.c | |
parent | fece418418f51e92dd7e67e17c5e3fe5a28d3279 (diff) | |
parent | 6e86841d05f371b5b9b86ce76c02aaee83352298 (diff) |
Merge branch 'master' of /home/cbou/linux-2.6
Conflicts:
drivers/power/Kconfig
drivers/power/Makefile
Diffstat (limited to 'drivers/usb/serial/garmin_gps.c')
-rw-r--r-- | drivers/usb/serial/garmin_gps.c | 400 |
1 files changed, 190 insertions, 210 deletions
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c index 8ce5a56a48e3..2e663f1afd5e 100644 --- a/drivers/usb/serial/garmin_gps.c +++ b/drivers/usb/serial/garmin_gps.c | |||
@@ -33,7 +33,7 @@ | |||
33 | #include <linux/tty_flip.h> | 33 | #include <linux/tty_flip.h> |
34 | #include <linux/module.h> | 34 | #include <linux/module.h> |
35 | #include <linux/spinlock.h> | 35 | #include <linux/spinlock.h> |
36 | #include <asm/uaccess.h> | 36 | #include <linux/uaccess.h> |
37 | #include <asm/atomic.h> | 37 | #include <asm/atomic.h> |
38 | #include <linux/usb.h> | 38 | #include <linux/usb.h> |
39 | #include <linux/usb/serial.h> | 39 | #include <linux/usb/serial.h> |
@@ -44,7 +44,7 @@ | |||
44 | static int initial_mode = 1; | 44 | static int initial_mode = 1; |
45 | 45 | ||
46 | /* debug flag */ | 46 | /* debug flag */ |
47 | static int debug = 0; | 47 | static int debug; |
48 | 48 | ||
49 | #define GARMIN_VENDOR_ID 0x091E | 49 | #define GARMIN_VENDOR_ID 0x091E |
50 | 50 | ||
@@ -56,7 +56,7 @@ static int debug = 0; | |||
56 | #define VERSION_MINOR 31 | 56 | #define VERSION_MINOR 31 |
57 | 57 | ||
58 | #define _STR(s) #s | 58 | #define _STR(s) #s |
59 | #define _DRIVER_VERSION(a,b) "v" _STR(a) "." _STR(b) | 59 | #define _DRIVER_VERSION(a, b) "v" _STR(a) "." _STR(b) |
60 | #define DRIVER_VERSION _DRIVER_VERSION(VERSION_MAJOR, VERSION_MINOR) | 60 | #define DRIVER_VERSION _DRIVER_VERSION(VERSION_MAJOR, VERSION_MINOR) |
61 | #define DRIVER_AUTHOR "hermann kneissel" | 61 | #define DRIVER_AUTHOR "hermann kneissel" |
62 | #define DRIVER_DESC "garmin gps driver" | 62 | #define DRIVER_DESC "garmin gps driver" |
@@ -65,37 +65,37 @@ static int debug = 0; | |||
65 | #define EINVPKT 1000 /* invalid packet structure */ | 65 | #define EINVPKT 1000 /* invalid packet structure */ |
66 | 66 | ||
67 | 67 | ||
68 | // size of the header of a packet using the usb protocol | 68 | /* size of the header of a packet using the usb protocol */ |
69 | #define GARMIN_PKTHDR_LENGTH 12 | 69 | #define GARMIN_PKTHDR_LENGTH 12 |
70 | 70 | ||
71 | // max. possible size of a packet using the serial protocol | 71 | /* max. possible size of a packet using the serial protocol */ |
72 | #define MAX_SERIAL_PKT_SIZ (3+255+3) | 72 | #define MAX_SERIAL_PKT_SIZ (3 + 255 + 3) |
73 | 73 | ||
74 | // max. possible size of a packet with worst case stuffing | 74 | /* max. possible size of a packet with worst case stuffing */ |
75 | #define MAX_SERIAL_PKT_SIZ_STUFFED MAX_SERIAL_PKT_SIZ+256 | 75 | #define MAX_SERIAL_PKT_SIZ_STUFFED (MAX_SERIAL_PKT_SIZ + 256) |
76 | 76 | ||
77 | // size of a buffer able to hold a complete (no stuffing) packet | 77 | /* size of a buffer able to hold a complete (no stuffing) packet |
78 | // (the document protocol does not contain packets with a larger | 78 | * (the document protocol does not contain packets with a larger |
79 | // size, but in theory a packet may be 64k+12 bytes - if in | 79 | * size, but in theory a packet may be 64k+12 bytes - if in |
80 | // later protocol versions larger packet sizes occur, this value | 80 | * later protocol versions larger packet sizes occur, this value |
81 | // should be increased accordingly, so the input buffer is always | 81 | * should be increased accordingly, so the input buffer is always |
82 | // large enough the store a complete packet inclusive header) | 82 | * large enough the store a complete packet inclusive header) */ |
83 | #define GPS_IN_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ) | 83 | #define GPS_IN_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ) |
84 | 84 | ||
85 | // size of a buffer able to hold a complete (incl. stuffing) packet | 85 | /* size of a buffer able to hold a complete (incl. stuffing) packet */ |
86 | #define GPS_OUT_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ_STUFFED) | 86 | #define GPS_OUT_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ_STUFFED) |
87 | 87 | ||
88 | // where to place the packet id of a serial packet, so we can | 88 | /* where to place the packet id of a serial packet, so we can |
89 | // prepend the usb-packet header without the need to move the | 89 | * prepend the usb-packet header without the need to move the |
90 | // packets data | 90 | * packets data */ |
91 | #define GSP_INITIAL_OFFSET (GARMIN_PKTHDR_LENGTH-2) | 91 | #define GSP_INITIAL_OFFSET (GARMIN_PKTHDR_LENGTH-2) |
92 | 92 | ||
93 | // max. size of incoming private packets (header+1 param) | 93 | /* max. size of incoming private packets (header+1 param) */ |
94 | #define PRIVPKTSIZ (GARMIN_PKTHDR_LENGTH+4) | 94 | #define PRIVPKTSIZ (GARMIN_PKTHDR_LENGTH+4) |
95 | 95 | ||
96 | #define GARMIN_LAYERID_TRANSPORT 0 | 96 | #define GARMIN_LAYERID_TRANSPORT 0 |
97 | #define GARMIN_LAYERID_APPL 20 | 97 | #define GARMIN_LAYERID_APPL 20 |
98 | // our own layer-id to use for some control mechanisms | 98 | /* our own layer-id to use for some control mechanisms */ |
99 | #define GARMIN_LAYERID_PRIVATE 0x01106E4B | 99 | #define GARMIN_LAYERID_PRIVATE 0x01106E4B |
100 | 100 | ||
101 | #define GARMIN_PKTID_PVT_DATA 51 | 101 | #define GARMIN_PKTID_PVT_DATA 51 |
@@ -103,7 +103,7 @@ static int debug = 0; | |||
103 | 103 | ||
104 | #define CMND_ABORT_TRANSFER 0 | 104 | #define CMND_ABORT_TRANSFER 0 |
105 | 105 | ||
106 | // packet ids used in private layer | 106 | /* packet ids used in private layer */ |
107 | #define PRIV_PKTID_SET_DEBUG 1 | 107 | #define PRIV_PKTID_SET_DEBUG 1 |
108 | #define PRIV_PKTID_SET_MODE 2 | 108 | #define PRIV_PKTID_SET_MODE 2 |
109 | #define PRIV_PKTID_INFO_REQ 3 | 109 | #define PRIV_PKTID_INFO_REQ 3 |
@@ -121,7 +121,8 @@ static int debug = 0; | |||
121 | struct garmin_packet { | 121 | struct garmin_packet { |
122 | struct list_head list; | 122 | struct list_head list; |
123 | int seq; | 123 | int seq; |
124 | int size; // the real size of the data array, always > 0 | 124 | /* the real size of the data array, always > 0 */ |
125 | int size; | ||
125 | __u8 data[1]; | 126 | __u8 data[1]; |
126 | }; | 127 | }; |
127 | 128 | ||
@@ -164,7 +165,7 @@ struct garmin_data { | |||
164 | #define MODE_NATIVE 0 | 165 | #define MODE_NATIVE 0 |
165 | #define MODE_GARMIN_SERIAL 1 | 166 | #define MODE_GARMIN_SERIAL 1 |
166 | 167 | ||
167 | // Flags used in garmin_data.flags: | 168 | /* Flags used in garmin_data.flags: */ |
168 | #define FLAGS_SESSION_REPLY_MASK 0x00C0 | 169 | #define FLAGS_SESSION_REPLY_MASK 0x00C0 |
169 | #define FLAGS_SESSION_REPLY1_SEEN 0x0080 | 170 | #define FLAGS_SESSION_REPLY1_SEEN 0x0080 |
170 | #define FLAGS_SESSION_REPLY2_SEEN 0x0040 | 171 | #define FLAGS_SESSION_REPLY2_SEEN 0x0040 |
@@ -185,7 +186,7 @@ struct garmin_data { | |||
185 | 186 | ||
186 | 187 | ||
187 | /* function prototypes */ | 188 | /* function prototypes */ |
188 | static void gsp_next_packet(struct garmin_data * garmin_data_p); | 189 | static void gsp_next_packet(struct garmin_data *garmin_data_p); |
189 | static int garmin_write_bulk(struct usb_serial_port *port, | 190 | static int garmin_write_bulk(struct usb_serial_port *port, |
190 | const unsigned char *buf, int count, | 191 | const unsigned char *buf, int count, |
191 | int dismiss_ack); | 192 | int dismiss_ack); |
@@ -217,12 +218,13 @@ static unsigned char const PRIVATE_REQ[] | |||
217 | 218 | ||
218 | 219 | ||
219 | static struct usb_device_id id_table [] = { | 220 | static struct usb_device_id id_table [] = { |
220 | /* the same device id seems to be used by all usb enabled gps devices */ | 221 | /* the same device id seems to be used by all |
221 | { USB_DEVICE(GARMIN_VENDOR_ID, 3 ) }, | 222 | usb enabled GPS devices */ |
223 | { USB_DEVICE(GARMIN_VENDOR_ID, 3) }, | ||
222 | { } /* Terminating entry */ | 224 | { } /* Terminating entry */ |
223 | }; | 225 | }; |
224 | 226 | ||
225 | MODULE_DEVICE_TABLE (usb, id_table); | 227 | MODULE_DEVICE_TABLE(usb, id_table); |
226 | 228 | ||
227 | static struct usb_driver garmin_driver = { | 229 | static struct usb_driver garmin_driver = { |
228 | .name = "garmin_gps", | 230 | .name = "garmin_gps", |
@@ -233,9 +235,10 @@ static struct usb_driver garmin_driver = { | |||
233 | }; | 235 | }; |
234 | 236 | ||
235 | 237 | ||
236 | static inline int noResponseFromAppLayer(struct garmin_data * garmin_data_p) | 238 | static inline int noResponseFromAppLayer(struct garmin_data *garmin_data_p) |
237 | { | 239 | { |
238 | return atomic_read(&garmin_data_p->req_count) == atomic_read(&garmin_data_p->resp_count); | 240 | return atomic_read(&garmin_data_p->req_count) == |
241 | atomic_read(&garmin_data_p->resp_count); | ||
239 | } | 242 | } |
240 | 243 | ||
241 | 244 | ||
@@ -261,10 +264,10 @@ static inline int getDataLength(const __u8 *usbPacket) | |||
261 | */ | 264 | */ |
262 | static inline int isAbortTrfCmnd(const unsigned char *buf) | 265 | static inline int isAbortTrfCmnd(const unsigned char *buf) |
263 | { | 266 | { |
264 | if (0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ, | 267 | if (0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ, |
265 | sizeof(GARMIN_STOP_TRANSFER_REQ)) || | 268 | sizeof(GARMIN_STOP_TRANSFER_REQ)) || |
266 | 0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ_V2, | 269 | 0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ_V2, |
267 | sizeof(GARMIN_STOP_TRANSFER_REQ_V2))) | 270 | sizeof(GARMIN_STOP_TRANSFER_REQ_V2))) |
268 | return 1; | 271 | return 1; |
269 | else | 272 | else |
270 | return 0; | 273 | return 0; |
@@ -275,11 +278,11 @@ static inline int isAbortTrfCmnd(const unsigned char *buf) | |||
275 | static void send_to_tty(struct usb_serial_port *port, | 278 | static void send_to_tty(struct usb_serial_port *port, |
276 | char *data, unsigned int actual_length) | 279 | char *data, unsigned int actual_length) |
277 | { | 280 | { |
278 | struct tty_struct *tty = port->tty; | 281 | struct tty_struct *tty = port->port.tty; |
279 | 282 | ||
280 | if (tty && actual_length) { | 283 | if (tty && actual_length) { |
281 | 284 | ||
282 | usb_serial_debug_data(debug, &port->dev, | 285 | usb_serial_debug_data(debug, &port->dev, |
283 | __func__, actual_length, data); | 286 | __func__, actual_length, data); |
284 | 287 | ||
285 | tty_buffer_request_room(tty, actual_length); | 288 | tty_buffer_request_room(tty, actual_length); |
@@ -296,7 +299,7 @@ static void send_to_tty(struct usb_serial_port *port, | |||
296 | /* | 299 | /* |
297 | * queue a received (usb-)packet for later processing | 300 | * queue a received (usb-)packet for later processing |
298 | */ | 301 | */ |
299 | static int pkt_add(struct garmin_data * garmin_data_p, | 302 | static int pkt_add(struct garmin_data *garmin_data_p, |
300 | unsigned char *data, unsigned int data_length) | 303 | unsigned char *data, unsigned int data_length) |
301 | { | 304 | { |
302 | int state = 0; | 305 | int state = 0; |
@@ -307,7 +310,7 @@ static int pkt_add(struct garmin_data * garmin_data_p, | |||
307 | /* process only packets containg data ... */ | 310 | /* process only packets containg data ... */ |
308 | if (data_length) { | 311 | if (data_length) { |
309 | pkt = kmalloc(sizeof(struct garmin_packet)+data_length, | 312 | pkt = kmalloc(sizeof(struct garmin_packet)+data_length, |
310 | GFP_ATOMIC); | 313 | GFP_ATOMIC); |
311 | if (pkt == NULL) { | 314 | if (pkt == NULL) { |
312 | dev_err(&garmin_data_p->port->dev, "out of memory\n"); | 315 | dev_err(&garmin_data_p->port->dev, "out of memory\n"); |
313 | return 0; | 316 | return 0; |
@@ -325,16 +328,15 @@ static int pkt_add(struct garmin_data * garmin_data_p, | |||
325 | 328 | ||
326 | /* in serial mode, if someone is waiting for data from | 329 | /* in serial mode, if someone is waiting for data from |
327 | the device, iconvert and send the next packet to tty. */ | 330 | the device, iconvert and send the next packet to tty. */ |
328 | if (result && (state == STATE_GSP_WAIT_DATA)) { | 331 | if (result && (state == STATE_GSP_WAIT_DATA)) |
329 | gsp_next_packet(garmin_data_p); | 332 | gsp_next_packet(garmin_data_p); |
330 | } | ||
331 | } | 333 | } |
332 | return result; | 334 | return result; |
333 | } | 335 | } |
334 | 336 | ||
335 | 337 | ||
336 | /* get the next pending packet */ | 338 | /* get the next pending packet */ |
337 | static struct garmin_packet *pkt_pop(struct garmin_data * garmin_data_p) | 339 | static struct garmin_packet *pkt_pop(struct garmin_data *garmin_data_p) |
338 | { | 340 | { |
339 | unsigned long flags; | 341 | unsigned long flags; |
340 | struct garmin_packet *result = NULL; | 342 | struct garmin_packet *result = NULL; |
@@ -350,7 +352,7 @@ static struct garmin_packet *pkt_pop(struct garmin_data * garmin_data_p) | |||
350 | 352 | ||
351 | 353 | ||
352 | /* free up all queued data */ | 354 | /* free up all queued data */ |
353 | static void pkt_clear(struct garmin_data * garmin_data_p) | 355 | static void pkt_clear(struct garmin_data *garmin_data_p) |
354 | { | 356 | { |
355 | unsigned long flags; | 357 | unsigned long flags; |
356 | struct garmin_packet *result = NULL; | 358 | struct garmin_packet *result = NULL; |
@@ -372,7 +374,7 @@ static void pkt_clear(struct garmin_data * garmin_data_p) | |||
372 | ******************************************************************************/ | 374 | ******************************************************************************/ |
373 | 375 | ||
374 | /* send an ack packet back to the tty */ | 376 | /* send an ack packet back to the tty */ |
375 | static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id) | 377 | static int gsp_send_ack(struct garmin_data *garmin_data_p, __u8 pkt_id) |
376 | { | 378 | { |
377 | __u8 pkt[10]; | 379 | __u8 pkt[10]; |
378 | __u8 cksum = 0; | 380 | __u8 cksum = 0; |
@@ -391,9 +393,8 @@ static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id) | |||
391 | *ptr++ = pkt_id; | 393 | *ptr++ = pkt_id; |
392 | cksum += pkt_id; | 394 | cksum += pkt_id; |
393 | 395 | ||
394 | if (pkt_id == DLE) { | 396 | if (pkt_id == DLE) |
395 | *ptr++ = DLE; | 397 | *ptr++ = DLE; |
396 | } | ||
397 | 398 | ||
398 | *ptr++ = 0; | 399 | *ptr++ = 0; |
399 | *ptr++ = 0xFF & (-cksum); | 400 | *ptr++ = 0xFF & (-cksum); |
@@ -415,12 +416,12 @@ static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id) | |||
415 | * at GSP_INITIAL_OFFSET. | 416 | * at GSP_INITIAL_OFFSET. |
416 | * | 417 | * |
417 | * count - number of bytes in the input buffer including space reserved for | 418 | * count - number of bytes in the input buffer including space reserved for |
418 | * the usb header: GSP_INITIAL_OFFSET + number of bytes in packet | 419 | * the usb header: GSP_INITIAL_OFFSET + number of bytes in packet |
419 | * (including pkt-id, data-length a. cksum) | 420 | * (including pkt-id, data-length a. cksum) |
420 | */ | 421 | */ |
421 | static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count) | 422 | static int gsp_rec_packet(struct garmin_data *garmin_data_p, int count) |
422 | { | 423 | { |
423 | const __u8* recpkt = garmin_data_p->inbuffer+GSP_INITIAL_OFFSET; | 424 | const __u8 *recpkt = garmin_data_p->inbuffer+GSP_INITIAL_OFFSET; |
424 | __le32 *usbdata = (__le32 *) garmin_data_p->inbuffer; | 425 | __le32 *usbdata = (__le32 *) garmin_data_p->inbuffer; |
425 | 426 | ||
426 | int cksum = 0; | 427 | int cksum = 0; |
@@ -440,8 +441,8 @@ static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count) | |||
440 | cksum += *recpkt++; | 441 | cksum += *recpkt++; |
441 | cksum += *recpkt++; | 442 | cksum += *recpkt++; |
442 | 443 | ||
443 | // sanity check, remove after test ... | 444 | /* sanity check, remove after test ... */ |
444 | if ((__u8*)&(usbdata[3]) != recpkt) { | 445 | if ((__u8 *)&(usbdata[3]) != recpkt) { |
445 | dbg("%s - ptr mismatch %p - %p", | 446 | dbg("%s - ptr mismatch %p - %p", |
446 | __func__, &(usbdata[4]), recpkt); | 447 | __func__, &(usbdata[4]), recpkt); |
447 | return -EINVPKT; | 448 | return -EINVPKT; |
@@ -462,7 +463,7 @@ static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count) | |||
462 | usbdata[1] = __cpu_to_le32(pktid); | 463 | usbdata[1] = __cpu_to_le32(pktid); |
463 | usbdata[2] = __cpu_to_le32(size); | 464 | usbdata[2] = __cpu_to_le32(size); |
464 | 465 | ||
465 | garmin_write_bulk (garmin_data_p->port, garmin_data_p->inbuffer, | 466 | garmin_write_bulk(garmin_data_p->port, garmin_data_p->inbuffer, |
466 | GARMIN_PKTHDR_LENGTH+size, 0); | 467 | GARMIN_PKTHDR_LENGTH+size, 0); |
467 | 468 | ||
468 | /* if this was an abort-transfer command, flush all | 469 | /* if this was an abort-transfer command, flush all |
@@ -495,7 +496,7 @@ static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count) | |||
495 | * if the input is an abort command, drop all queued data. | 496 | * if the input is an abort command, drop all queued data. |
496 | */ | 497 | */ |
497 | 498 | ||
498 | static int gsp_receive(struct garmin_data * garmin_data_p, | 499 | static int gsp_receive(struct garmin_data *garmin_data_p, |
499 | const unsigned char *buf, int count) | 500 | const unsigned char *buf, int count) |
500 | { | 501 | { |
501 | unsigned long flags; | 502 | unsigned long flags; |
@@ -504,10 +505,11 @@ static int gsp_receive(struct garmin_data * garmin_data_p, | |||
504 | int i = 0; | 505 | int i = 0; |
505 | __u8 *dest; | 506 | __u8 *dest; |
506 | int size; | 507 | int size; |
507 | // dleSeen: set if last byte read was a DLE | 508 | /* dleSeen: set if last byte read was a DLE */ |
508 | int dleSeen; | 509 | int dleSeen; |
509 | // skip: if set, skip incoming data until possible start of | 510 | /* skip: if set, skip incoming data until possible start of |
510 | // new packet | 511 | * new packet |
512 | */ | ||
511 | int skip; | 513 | int skip; |
512 | __u8 data; | 514 | __u8 data; |
513 | 515 | ||
@@ -521,14 +523,13 @@ static int gsp_receive(struct garmin_data * garmin_data_p, | |||
521 | dbg("%s - dle=%d skip=%d size=%d count=%d", | 523 | dbg("%s - dle=%d skip=%d size=%d count=%d", |
522 | __func__, dleSeen, skip, size, count); | 524 | __func__, dleSeen, skip, size, count); |
523 | 525 | ||
524 | if (size == 0) { | 526 | if (size == 0) |
525 | size = GSP_INITIAL_OFFSET; | 527 | size = GSP_INITIAL_OFFSET; |
526 | } | ||
527 | 528 | ||
528 | while (offs < count) { | 529 | while (offs < count) { |
529 | 530 | ||
530 | data = *(buf+offs); | 531 | data = *(buf+offs); |
531 | offs ++; | 532 | offs++; |
532 | 533 | ||
533 | if (data == DLE) { | 534 | if (data == DLE) { |
534 | if (skip) { /* start of a new pkt */ | 535 | if (skip) { /* start of a new pkt */ |
@@ -554,9 +555,8 @@ static int gsp_receive(struct garmin_data * garmin_data_p, | |||
554 | ack_or_nak_seen = NAK; | 555 | ack_or_nak_seen = NAK; |
555 | dbg("NAK packet complete."); | 556 | dbg("NAK packet complete."); |
556 | } else { | 557 | } else { |
557 | dbg("packet complete " | 558 | dbg("packet complete - id=0x%X.", |
558 | "- id=0x%X.", | 559 | 0xFF & data); |
559 | 0xFF & data); | ||
560 | gsp_rec_packet(garmin_data_p, size); | 560 | gsp_rec_packet(garmin_data_p, size); |
561 | } | 561 | } |
562 | 562 | ||
@@ -589,7 +589,7 @@ static int gsp_receive(struct garmin_data * garmin_data_p, | |||
589 | 589 | ||
590 | garmin_data_p->insize = size; | 590 | garmin_data_p->insize = size; |
591 | 591 | ||
592 | // copy flags back to structure | 592 | /* copy flags back to structure */ |
593 | if (skip) | 593 | if (skip) |
594 | garmin_data_p->flags |= FLAGS_GSP_SKIP; | 594 | garmin_data_p->flags |= FLAGS_GSP_SKIP; |
595 | else | 595 | else |
@@ -600,16 +600,13 @@ static int gsp_receive(struct garmin_data * garmin_data_p, | |||
600 | else | 600 | else |
601 | garmin_data_p->flags &= ~FLAGS_GSP_DLESEEN; | 601 | garmin_data_p->flags &= ~FLAGS_GSP_DLESEEN; |
602 | 602 | ||
603 | if (ack_or_nak_seen) { | 603 | if (ack_or_nak_seen) |
604 | garmin_data_p->state = STATE_GSP_WAIT_DATA; | 604 | garmin_data_p->state = STATE_GSP_WAIT_DATA; |
605 | } | ||
606 | 605 | ||
607 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | 606 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
608 | 607 | ||
609 | if (ack_or_nak_seen) { | 608 | if (ack_or_nak_seen) |
610 | gsp_next_packet(garmin_data_p); | 609 | gsp_next_packet(garmin_data_p); |
611 | } | ||
612 | |||
613 | return count; | 610 | return count; |
614 | } | 611 | } |
615 | 612 | ||
@@ -623,7 +620,7 @@ static int gsp_receive(struct garmin_data * garmin_data_p, | |||
623 | * | 620 | * |
624 | * return <0 on error, 0 if packet is incomplete or > 0 if packet was sent | 621 | * return <0 on error, 0 if packet is incomplete or > 0 if packet was sent |
625 | */ | 622 | */ |
626 | static int gsp_send(struct garmin_data * garmin_data_p, | 623 | static int gsp_send(struct garmin_data *garmin_data_p, |
627 | const unsigned char *buf, int count) | 624 | const unsigned char *buf, int count) |
628 | { | 625 | { |
629 | const unsigned char *src; | 626 | const unsigned char *src; |
@@ -631,11 +628,11 @@ static int gsp_send(struct garmin_data * garmin_data_p, | |||
631 | int pktid = 0; | 628 | int pktid = 0; |
632 | int datalen = 0; | 629 | int datalen = 0; |
633 | int cksum = 0; | 630 | int cksum = 0; |
634 | int i=0; | 631 | int i = 0; |
635 | int k; | 632 | int k; |
636 | 633 | ||
637 | dbg("%s - state %d - %d bytes.", __func__, | 634 | dbg("%s - state %d - %d bytes.", __func__, |
638 | garmin_data_p->state, count); | 635 | garmin_data_p->state, count); |
639 | 636 | ||
640 | k = garmin_data_p->outsize; | 637 | k = garmin_data_p->outsize; |
641 | if ((k+count) > GPS_OUT_BUFSIZ) { | 638 | if ((k+count) > GPS_OUT_BUFSIZ) { |
@@ -650,7 +647,7 @@ static int gsp_send(struct garmin_data * garmin_data_p, | |||
650 | 647 | ||
651 | if (k >= GARMIN_PKTHDR_LENGTH) { | 648 | if (k >= GARMIN_PKTHDR_LENGTH) { |
652 | pktid = getPacketId(garmin_data_p->outbuffer); | 649 | pktid = getPacketId(garmin_data_p->outbuffer); |
653 | datalen= getDataLength(garmin_data_p->outbuffer); | 650 | datalen = getDataLength(garmin_data_p->outbuffer); |
654 | i = GARMIN_PKTHDR_LENGTH + datalen; | 651 | i = GARMIN_PKTHDR_LENGTH + datalen; |
655 | if (k < i) | 652 | if (k < i) |
656 | return 0; | 653 | return 0; |
@@ -658,19 +655,18 @@ static int gsp_send(struct garmin_data * garmin_data_p, | |||
658 | return 0; | 655 | return 0; |
659 | } | 656 | } |
660 | 657 | ||
661 | dbg("%s - %d bytes in buffer, %d bytes in pkt.", __func__, | 658 | dbg("%s - %d bytes in buffer, %d bytes in pkt.", __func__, k, i); |
662 | k, i); | ||
663 | 659 | ||
664 | /* garmin_data_p->outbuffer now contains a complete packet */ | 660 | /* garmin_data_p->outbuffer now contains a complete packet */ |
665 | 661 | ||
666 | usb_serial_debug_data(debug, &garmin_data_p->port->dev, | 662 | usb_serial_debug_data(debug, &garmin_data_p->port->dev, |
667 | __func__, k, garmin_data_p->outbuffer); | 663 | __func__, k, garmin_data_p->outbuffer); |
668 | 664 | ||
669 | garmin_data_p->outsize = 0; | 665 | garmin_data_p->outsize = 0; |
670 | 666 | ||
671 | if (GARMIN_LAYERID_APPL != getLayerId(garmin_data_p->outbuffer)) { | 667 | if (GARMIN_LAYERID_APPL != getLayerId(garmin_data_p->outbuffer)) { |
672 | dbg("not an application packet (%d)", | 668 | dbg("not an application packet (%d)", |
673 | getLayerId(garmin_data_p->outbuffer)); | 669 | getLayerId(garmin_data_p->outbuffer)); |
674 | return -1; | 670 | return -1; |
675 | } | 671 | } |
676 | 672 | ||
@@ -688,14 +684,14 @@ static int gsp_send(struct garmin_data * garmin_data_p, | |||
688 | 684 | ||
689 | k = 0; | 685 | k = 0; |
690 | src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH; | 686 | src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH; |
691 | for (i=0; i<datalen; i++) { | 687 | for (i = 0; i < datalen; i++) { |
692 | if (*src++ == DLE) | 688 | if (*src++ == DLE) |
693 | k++; | 689 | k++; |
694 | } | 690 | } |
695 | 691 | ||
696 | src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH; | 692 | src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH; |
697 | if (k > (GARMIN_PKTHDR_LENGTH-2)) { | 693 | if (k > (GARMIN_PKTHDR_LENGTH-2)) { |
698 | /* can't add stuffing DLEs in place, move data to end | 694 | /* can't add stuffing DLEs in place, move data to end |
699 | of buffer ... */ | 695 | of buffer ... */ |
700 | dst = garmin_data_p->outbuffer+GPS_OUT_BUFSIZ-datalen; | 696 | dst = garmin_data_p->outbuffer+GPS_OUT_BUFSIZ-datalen; |
701 | memcpy(dst, src, datalen); | 697 | memcpy(dst, src, datalen); |
@@ -712,14 +708,14 @@ static int gsp_send(struct garmin_data * garmin_data_p, | |||
712 | if (datalen == DLE) | 708 | if (datalen == DLE) |
713 | *dst++ = DLE; | 709 | *dst++ = DLE; |
714 | 710 | ||
715 | for (i=0; i<datalen; i++) { | 711 | for (i = 0; i < datalen; i++) { |
716 | __u8 c = *src++; | 712 | __u8 c = *src++; |
717 | *dst++ = c; | 713 | *dst++ = c; |
718 | cksum += c; | 714 | cksum += c; |
719 | if (c == DLE) | 715 | if (c == DLE) |
720 | *dst++ = DLE; | 716 | *dst++ = DLE; |
721 | } | 717 | } |
722 | 718 | ||
723 | cksum = 0xFF & -cksum; | 719 | cksum = 0xFF & -cksum; |
724 | *dst++ = cksum; | 720 | *dst++ = cksum; |
725 | if (cksum == DLE) | 721 | if (cksum == DLE) |
@@ -744,7 +740,7 @@ static int gsp_send(struct garmin_data * garmin_data_p, | |||
744 | /* | 740 | /* |
745 | * Process the next pending data packet - if there is one | 741 | * Process the next pending data packet - if there is one |
746 | */ | 742 | */ |
747 | static void gsp_next_packet(struct garmin_data * garmin_data_p) | 743 | static void gsp_next_packet(struct garmin_data *garmin_data_p) |
748 | { | 744 | { |
749 | struct garmin_packet *pkt = NULL; | 745 | struct garmin_packet *pkt = NULL; |
750 | 746 | ||
@@ -774,17 +770,17 @@ static void gsp_next_packet(struct garmin_data * garmin_data_p) | |||
774 | * buf contains the data read, it may span more than one packet | 770 | * buf contains the data read, it may span more than one packet |
775 | * or even incomplete packets | 771 | * or even incomplete packets |
776 | */ | 772 | */ |
777 | static int nat_receive(struct garmin_data * garmin_data_p, | 773 | static int nat_receive(struct garmin_data *garmin_data_p, |
778 | const unsigned char *buf, int count) | 774 | const unsigned char *buf, int count) |
779 | { | 775 | { |
780 | unsigned long flags; | 776 | unsigned long flags; |
781 | __u8 * dest; | 777 | __u8 *dest; |
782 | int offs = 0; | 778 | int offs = 0; |
783 | int result = count; | 779 | int result = count; |
784 | int len; | 780 | int len; |
785 | 781 | ||
786 | while (offs < count) { | 782 | while (offs < count) { |
787 | // if buffer contains header, copy rest of data | 783 | /* if buffer contains header, copy rest of data */ |
788 | if (garmin_data_p->insize >= GARMIN_PKTHDR_LENGTH) | 784 | if (garmin_data_p->insize >= GARMIN_PKTHDR_LENGTH) |
789 | len = GARMIN_PKTHDR_LENGTH | 785 | len = GARMIN_PKTHDR_LENGTH |
790 | +getDataLength(garmin_data_p->inbuffer); | 786 | +getDataLength(garmin_data_p->inbuffer); |
@@ -792,9 +788,9 @@ static int nat_receive(struct garmin_data * garmin_data_p, | |||
792 | len = GARMIN_PKTHDR_LENGTH; | 788 | len = GARMIN_PKTHDR_LENGTH; |
793 | 789 | ||
794 | if (len >= GPS_IN_BUFSIZ) { | 790 | if (len >= GPS_IN_BUFSIZ) { |
795 | /* seem to be an invalid packet, ignore rest of input */ | 791 | /* seems to be an invalid packet, ignore rest |
796 | dbg("%s - packet size too large: %d", | 792 | of input */ |
797 | __func__, len); | 793 | dbg("%s - packet size too large: %d", __func__, len); |
798 | garmin_data_p->insize = 0; | 794 | garmin_data_p->insize = 0; |
799 | count = 0; | 795 | count = 0; |
800 | result = -EINVPKT; | 796 | result = -EINVPKT; |
@@ -804,7 +800,7 @@ static int nat_receive(struct garmin_data * garmin_data_p, | |||
804 | len = (count-offs); | 800 | len = (count-offs); |
805 | if (len > 0) { | 801 | if (len > 0) { |
806 | dest = garmin_data_p->inbuffer | 802 | dest = garmin_data_p->inbuffer |
807 | +garmin_data_p->insize; | 803 | + garmin_data_p->insize; |
808 | memcpy(dest, buf+offs, len); | 804 | memcpy(dest, buf+offs, len); |
809 | garmin_data_p->insize += len; | 805 | garmin_data_p->insize += len; |
810 | offs += len; | 806 | offs += len; |
@@ -816,17 +812,19 @@ static int nat_receive(struct garmin_data * garmin_data_p, | |||
816 | len = GARMIN_PKTHDR_LENGTH+ | 812 | len = GARMIN_PKTHDR_LENGTH+ |
817 | getDataLength(garmin_data_p->inbuffer); | 813 | getDataLength(garmin_data_p->inbuffer); |
818 | if (garmin_data_p->insize >= len) { | 814 | if (garmin_data_p->insize >= len) { |
819 | garmin_write_bulk (garmin_data_p->port, | 815 | garmin_write_bulk(garmin_data_p->port, |
820 | garmin_data_p->inbuffer, | 816 | garmin_data_p->inbuffer, |
821 | len, 0); | 817 | len, 0); |
822 | garmin_data_p->insize = 0; | 818 | garmin_data_p->insize = 0; |
823 | 819 | ||
824 | /* if this was an abort-transfer command, | 820 | /* if this was an abort-transfer command, |
825 | flush all queued data. */ | 821 | flush all queued data. */ |
826 | if (isAbortTrfCmnd(garmin_data_p->inbuffer)) { | 822 | if (isAbortTrfCmnd(garmin_data_p->inbuffer)) { |
827 | spin_lock_irqsave(&garmin_data_p->lock, flags); | 823 | spin_lock_irqsave(&garmin_data_p->lock, |
824 | flags); | ||
828 | garmin_data_p->flags |= FLAGS_DROP_DATA; | 825 | garmin_data_p->flags |= FLAGS_DROP_DATA; |
829 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | 826 | spin_unlock_irqrestore( |
827 | &garmin_data_p->lock, flags); | ||
830 | pkt_clear(garmin_data_p); | 828 | pkt_clear(garmin_data_p); |
831 | } | 829 | } |
832 | } | 830 | } |
@@ -842,7 +840,7 @@ static int nat_receive(struct garmin_data * garmin_data_p, | |||
842 | 840 | ||
843 | static void priv_status_resp(struct usb_serial_port *port) | 841 | static void priv_status_resp(struct usb_serial_port *port) |
844 | { | 842 | { |
845 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 843 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
846 | __le32 *pkt = (__le32 *)garmin_data_p->privpkt; | 844 | __le32 *pkt = (__le32 *)garmin_data_p->privpkt; |
847 | 845 | ||
848 | pkt[0] = __cpu_to_le32(GARMIN_LAYERID_PRIVATE); | 846 | pkt[0] = __cpu_to_le32(GARMIN_LAYERID_PRIVATE); |
@@ -852,7 +850,7 @@ static void priv_status_resp(struct usb_serial_port *port) | |||
852 | pkt[4] = __cpu_to_le32(garmin_data_p->mode); | 850 | pkt[4] = __cpu_to_le32(garmin_data_p->mode); |
853 | pkt[5] = __cpu_to_le32(garmin_data_p->serial_num); | 851 | pkt[5] = __cpu_to_le32(garmin_data_p->serial_num); |
854 | 852 | ||
855 | send_to_tty(port, (__u8*)pkt, 6*4); | 853 | send_to_tty(port, (__u8 *)pkt, 6 * 4); |
856 | } | 854 | } |
857 | 855 | ||
858 | 856 | ||
@@ -864,7 +862,7 @@ static int process_resetdev_request(struct usb_serial_port *port) | |||
864 | { | 862 | { |
865 | unsigned long flags; | 863 | unsigned long flags; |
866 | int status; | 864 | int status; |
867 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 865 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
868 | 866 | ||
869 | spin_lock_irqsave(&garmin_data_p->lock, flags); | 867 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
870 | garmin_data_p->flags &= ~(CLEAR_HALT_REQUIRED); | 868 | garmin_data_p->flags &= ~(CLEAR_HALT_REQUIRED); |
@@ -872,8 +870,8 @@ static int process_resetdev_request(struct usb_serial_port *port) | |||
872 | garmin_data_p->serial_num = 0; | 870 | garmin_data_p->serial_num = 0; |
873 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | 871 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
874 | 872 | ||
875 | usb_kill_urb (port->interrupt_in_urb); | 873 | usb_kill_urb(port->interrupt_in_urb); |
876 | dbg("%s - usb_reset_device", __func__ ); | 874 | dbg("%s - usb_reset_device", __func__); |
877 | status = usb_reset_device(port->serial->dev); | 875 | status = usb_reset_device(port->serial->dev); |
878 | if (status) | 876 | if (status) |
879 | dbg("%s - usb_reset_device failed: %d", | 877 | dbg("%s - usb_reset_device failed: %d", |
@@ -886,7 +884,7 @@ static int process_resetdev_request(struct usb_serial_port *port) | |||
886 | /* | 884 | /* |
887 | * clear all cached data | 885 | * clear all cached data |
888 | */ | 886 | */ |
889 | static int garmin_clear(struct garmin_data * garmin_data_p) | 887 | static int garmin_clear(struct garmin_data *garmin_data_p) |
890 | { | 888 | { |
891 | unsigned long flags; | 889 | unsigned long flags; |
892 | int status = 0; | 890 | int status = 0; |
@@ -896,8 +894,7 @@ static int garmin_clear(struct garmin_data * garmin_data_p) | |||
896 | if (port != NULL && atomic_read(&garmin_data_p->resp_count)) { | 894 | if (port != NULL && atomic_read(&garmin_data_p->resp_count)) { |
897 | /* send a terminate command */ | 895 | /* send a terminate command */ |
898 | status = garmin_write_bulk(port, GARMIN_STOP_TRANSFER_REQ, | 896 | status = garmin_write_bulk(port, GARMIN_STOP_TRANSFER_REQ, |
899 | sizeof(GARMIN_STOP_TRANSFER_REQ), | 897 | sizeof(GARMIN_STOP_TRANSFER_REQ), 1); |
900 | 1); | ||
901 | } | 898 | } |
902 | 899 | ||
903 | /* flush all queued data */ | 900 | /* flush all queued data */ |
@@ -920,28 +917,26 @@ static int garmin_init_session(struct usb_serial_port *port) | |||
920 | { | 917 | { |
921 | unsigned long flags; | 918 | unsigned long flags; |
922 | struct usb_serial *serial = port->serial; | 919 | struct usb_serial *serial = port->serial; |
923 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 920 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
924 | int status = 0; | 921 | int status = 0; |
925 | 922 | ||
926 | if (status == 0) { | 923 | if (status == 0) { |
927 | usb_kill_urb (port->interrupt_in_urb); | 924 | usb_kill_urb(port->interrupt_in_urb); |
928 | 925 | ||
929 | dbg("%s - adding interrupt input", __func__); | 926 | dbg("%s - adding interrupt input", __func__); |
930 | port->interrupt_in_urb->dev = serial->dev; | 927 | port->interrupt_in_urb->dev = serial->dev; |
931 | status = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); | 928 | status = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
932 | if (status) | 929 | if (status) |
933 | dev_err(&serial->dev->dev, | 930 | dev_err(&serial->dev->dev, |
934 | "%s - failed submitting interrupt urb," | 931 | "%s - failed submitting interrupt urb, error %d\n", |
935 | " error %d\n", | 932 | __func__, status); |
936 | __func__, status); | ||
937 | } | 933 | } |
938 | 934 | ||
939 | if (status == 0) { | 935 | if (status == 0) { |
940 | dbg("%s - starting session ...", __func__); | 936 | dbg("%s - starting session ...", __func__); |
941 | garmin_data_p->state = STATE_ACTIVE; | 937 | garmin_data_p->state = STATE_ACTIVE; |
942 | status = garmin_write_bulk(port, GARMIN_START_SESSION_REQ, | 938 | status = garmin_write_bulk(port, GARMIN_START_SESSION_REQ, |
943 | sizeof(GARMIN_START_SESSION_REQ), | 939 | sizeof(GARMIN_START_SESSION_REQ), 0); |
944 | 0); | ||
945 | 940 | ||
946 | if (status >= 0) { | 941 | if (status >= 0) { |
947 | 942 | ||
@@ -951,14 +946,14 @@ static int garmin_init_session(struct usb_serial_port *port) | |||
951 | 946 | ||
952 | /* not needed, but the win32 driver does it too ... */ | 947 | /* not needed, but the win32 driver does it too ... */ |
953 | status = garmin_write_bulk(port, | 948 | status = garmin_write_bulk(port, |
954 | GARMIN_START_SESSION_REQ2, | 949 | GARMIN_START_SESSION_REQ2, |
955 | sizeof(GARMIN_START_SESSION_REQ2), | 950 | sizeof(GARMIN_START_SESSION_REQ2), 0); |
956 | 0); | ||
957 | if (status >= 0) { | 951 | if (status >= 0) { |
958 | status = 0; | 952 | status = 0; |
959 | spin_lock_irqsave(&garmin_data_p->lock, flags); | 953 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
960 | garmin_data_p->ignorePkts++; | 954 | garmin_data_p->ignorePkts++; |
961 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | 955 | spin_unlock_irqrestore(&garmin_data_p->lock, |
956 | flags); | ||
962 | } | 957 | } |
963 | } | 958 | } |
964 | } | 959 | } |
@@ -970,11 +965,12 @@ static int garmin_init_session(struct usb_serial_port *port) | |||
970 | 965 | ||
971 | 966 | ||
972 | 967 | ||
973 | static int garmin_open (struct usb_serial_port *port, struct file *filp) | 968 | static int garmin_open(struct tty_struct *tty, |
969 | struct usb_serial_port *port, struct file *filp) | ||
974 | { | 970 | { |
975 | unsigned long flags; | 971 | unsigned long flags; |
976 | int status = 0; | 972 | int status = 0; |
977 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 973 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
978 | 974 | ||
979 | dbg("%s - port %d", __func__, port->number); | 975 | dbg("%s - port %d", __func__, port->number); |
980 | 976 | ||
@@ -983,8 +979,8 @@ static int garmin_open (struct usb_serial_port *port, struct file *filp) | |||
983 | * through, otherwise it is scheduled, and with high data rates (like | 979 | * through, otherwise it is scheduled, and with high data rates (like |
984 | * with OHCI) data can get lost. | 980 | * with OHCI) data can get lost. |
985 | */ | 981 | */ |
986 | if (port->tty) | 982 | if (tty) |
987 | port->tty->low_latency = 1; | 983 | tty->low_latency = 1; |
988 | 984 | ||
989 | spin_lock_irqsave(&garmin_data_p->lock, flags); | 985 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
990 | garmin_data_p->mode = initial_mode; | 986 | garmin_data_p->mode = initial_mode; |
@@ -995,23 +991,22 @@ static int garmin_open (struct usb_serial_port *port, struct file *filp) | |||
995 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | 991 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
996 | 992 | ||
997 | /* shutdown any bulk reads that might be going on */ | 993 | /* shutdown any bulk reads that might be going on */ |
998 | usb_kill_urb (port->write_urb); | 994 | usb_kill_urb(port->write_urb); |
999 | usb_kill_urb (port->read_urb); | 995 | usb_kill_urb(port->read_urb); |
1000 | 996 | ||
1001 | if (garmin_data_p->state == STATE_RESET) { | 997 | if (garmin_data_p->state == STATE_RESET) |
1002 | status = garmin_init_session(port); | 998 | status = garmin_init_session(port); |
1003 | } | ||
1004 | 999 | ||
1005 | garmin_data_p->state = STATE_ACTIVE; | 1000 | garmin_data_p->state = STATE_ACTIVE; |
1006 | |||
1007 | return status; | 1001 | return status; |
1008 | } | 1002 | } |
1009 | 1003 | ||
1010 | 1004 | ||
1011 | static void garmin_close (struct usb_serial_port *port, struct file * filp) | 1005 | static void garmin_close(struct tty_struct *tty, |
1006 | struct usb_serial_port *port, struct file *filp) | ||
1012 | { | 1007 | { |
1013 | struct usb_serial *serial = port->serial; | 1008 | struct usb_serial *serial = port->serial; |
1014 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 1009 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
1015 | 1010 | ||
1016 | dbg("%s - port %d - mode=%d state=%d flags=0x%X", __func__, | 1011 | dbg("%s - port %d - mode=%d state=%d flags=0x%X", __func__, |
1017 | port->number, garmin_data_p->mode, | 1012 | port->number, garmin_data_p->mode, |
@@ -1025,8 +1020,8 @@ static void garmin_close (struct usb_serial_port *port, struct file * filp) | |||
1025 | garmin_clear(garmin_data_p); | 1020 | garmin_clear(garmin_data_p); |
1026 | 1021 | ||
1027 | /* shutdown our urbs */ | 1022 | /* shutdown our urbs */ |
1028 | usb_kill_urb (port->read_urb); | 1023 | usb_kill_urb(port->read_urb); |
1029 | usb_kill_urb (port->write_urb); | 1024 | usb_kill_urb(port->write_urb); |
1030 | 1025 | ||
1031 | if (!port->serial->disconnected) { | 1026 | if (!port->serial->disconnected) { |
1032 | if (noResponseFromAppLayer(garmin_data_p) || | 1027 | if (noResponseFromAppLayer(garmin_data_p) || |
@@ -1042,21 +1037,22 @@ static void garmin_close (struct usb_serial_port *port, struct file * filp) | |||
1042 | mutex_unlock(&port->serial->disc_mutex); | 1037 | mutex_unlock(&port->serial->disc_mutex); |
1043 | } | 1038 | } |
1044 | 1039 | ||
1045 | 1040 | static void garmin_write_bulk_callback(struct urb *urb) | |
1046 | static void garmin_write_bulk_callback (struct urb *urb) | ||
1047 | { | 1041 | { |
1048 | unsigned long flags; | 1042 | unsigned long flags; |
1049 | struct usb_serial_port *port = urb->context; | 1043 | struct usb_serial_port *port = urb->context; |
1050 | int status = urb->status; | 1044 | int status = urb->status; |
1051 | 1045 | ||
1052 | if (port) { | 1046 | if (port) { |
1053 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 1047 | struct garmin_data *garmin_data_p = |
1048 | usb_get_serial_port_data(port); | ||
1054 | 1049 | ||
1055 | dbg("%s - port %d", __func__, port->number); | 1050 | dbg("%s - port %d", __func__, port->number); |
1056 | 1051 | ||
1057 | if (GARMIN_LAYERID_APPL == getLayerId(urb->transfer_buffer) | 1052 | if (GARMIN_LAYERID_APPL == getLayerId(urb->transfer_buffer) |
1058 | && (garmin_data_p->mode == MODE_GARMIN_SERIAL)) { | 1053 | && (garmin_data_p->mode == MODE_GARMIN_SERIAL)) { |
1059 | gsp_send_ack(garmin_data_p, ((__u8 *)urb->transfer_buffer)[4]); | 1054 | gsp_send_ack(garmin_data_p, |
1055 | ((__u8 *)urb->transfer_buffer)[4]); | ||
1060 | } | 1056 | } |
1061 | 1057 | ||
1062 | if (status) { | 1058 | if (status) { |
@@ -1070,20 +1066,21 @@ static void garmin_write_bulk_callback (struct urb *urb) | |||
1070 | usb_serial_port_softint(port); | 1066 | usb_serial_port_softint(port); |
1071 | } | 1067 | } |
1072 | 1068 | ||
1073 | /* Ignore errors that resulted from garmin_write_bulk with dismiss_ack=1 */ | 1069 | /* Ignore errors that resulted from garmin_write_bulk with |
1070 | dismiss_ack = 1 */ | ||
1074 | 1071 | ||
1075 | /* free up the transfer buffer, as usb_free_urb() does not do this */ | 1072 | /* free up the transfer buffer, as usb_free_urb() does not do this */ |
1076 | kfree (urb->transfer_buffer); | 1073 | kfree(urb->transfer_buffer); |
1077 | } | 1074 | } |
1078 | 1075 | ||
1079 | 1076 | ||
1080 | static int garmin_write_bulk (struct usb_serial_port *port, | 1077 | static int garmin_write_bulk(struct usb_serial_port *port, |
1081 | const unsigned char *buf, int count, | 1078 | const unsigned char *buf, int count, |
1082 | int dismiss_ack) | 1079 | int dismiss_ack) |
1083 | { | 1080 | { |
1084 | unsigned long flags; | 1081 | unsigned long flags; |
1085 | struct usb_serial *serial = port->serial; | 1082 | struct usb_serial *serial = port->serial; |
1086 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 1083 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
1087 | struct urb *urb; | 1084 | struct urb *urb; |
1088 | unsigned char *buffer; | 1085 | unsigned char *buffer; |
1089 | int status; | 1086 | int status; |
@@ -1095,7 +1092,7 @@ static int garmin_write_bulk (struct usb_serial_port *port, | |||
1095 | garmin_data_p->flags &= ~FLAGS_DROP_DATA; | 1092 | garmin_data_p->flags &= ~FLAGS_DROP_DATA; |
1096 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | 1093 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
1097 | 1094 | ||
1098 | buffer = kmalloc (count, GFP_ATOMIC); | 1095 | buffer = kmalloc(count, GFP_ATOMIC); |
1099 | if (!buffer) { | 1096 | if (!buffer) { |
1100 | dev_err(&port->dev, "out of memory\n"); | 1097 | dev_err(&port->dev, "out of memory\n"); |
1101 | return -ENOMEM; | 1098 | return -ENOMEM; |
@@ -1104,17 +1101,17 @@ static int garmin_write_bulk (struct usb_serial_port *port, | |||
1104 | urb = usb_alloc_urb(0, GFP_ATOMIC); | 1101 | urb = usb_alloc_urb(0, GFP_ATOMIC); |
1105 | if (!urb) { | 1102 | if (!urb) { |
1106 | dev_err(&port->dev, "no more free urbs\n"); | 1103 | dev_err(&port->dev, "no more free urbs\n"); |
1107 | kfree (buffer); | 1104 | kfree(buffer); |
1108 | return -ENOMEM; | 1105 | return -ENOMEM; |
1109 | } | 1106 | } |
1110 | 1107 | ||
1111 | memcpy (buffer, buf, count); | 1108 | memcpy(buffer, buf, count); |
1112 | 1109 | ||
1113 | usb_serial_debug_data(debug, &port->dev, __func__, count, buffer); | 1110 | usb_serial_debug_data(debug, &port->dev, __func__, count, buffer); |
1114 | 1111 | ||
1115 | usb_fill_bulk_urb (urb, serial->dev, | 1112 | usb_fill_bulk_urb(urb, serial->dev, |
1116 | usb_sndbulkpipe (serial->dev, | 1113 | usb_sndbulkpipe(serial->dev, |
1117 | port->bulk_out_endpointAddress), | 1114 | port->bulk_out_endpointAddress), |
1118 | buffer, count, | 1115 | buffer, count, |
1119 | garmin_write_bulk_callback, | 1116 | garmin_write_bulk_callback, |
1120 | dismiss_ack ? NULL : port); | 1117 | dismiss_ack ? NULL : port); |
@@ -1132,33 +1129,29 @@ static int garmin_write_bulk (struct usb_serial_port *port, | |||
1132 | status = usb_submit_urb(urb, GFP_ATOMIC); | 1129 | status = usb_submit_urb(urb, GFP_ATOMIC); |
1133 | if (status) { | 1130 | if (status) { |
1134 | dev_err(&port->dev, | 1131 | dev_err(&port->dev, |
1135 | "%s - usb_submit_urb(write bulk) " | 1132 | "%s - usb_submit_urb(write bulk) failed with status = %d\n", |
1136 | "failed with status = %d\n", | ||
1137 | __func__, status); | 1133 | __func__, status); |
1138 | count = status; | 1134 | count = status; |
1139 | } | 1135 | } |
1140 | 1136 | ||
1141 | /* we are done with this urb, so let the host driver | 1137 | /* we are done with this urb, so let the host driver |
1142 | * really free it when it is finished with it */ | 1138 | * really free it when it is finished with it */ |
1143 | usb_free_urb (urb); | 1139 | usb_free_urb(urb); |
1144 | 1140 | ||
1145 | return count; | 1141 | return count; |
1146 | } | 1142 | } |
1147 | 1143 | ||
1148 | 1144 | static int garmin_write(struct tty_struct *tty, struct usb_serial_port *port, | |
1149 | 1145 | const unsigned char *buf, int count) | |
1150 | static int garmin_write (struct usb_serial_port *port, | ||
1151 | const unsigned char *buf, int count) | ||
1152 | { | 1146 | { |
1153 | int pktid, pktsiz, len; | 1147 | int pktid, pktsiz, len; |
1154 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 1148 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
1155 | __le32 *privpkt = (__le32 *)garmin_data_p->privpkt; | 1149 | __le32 *privpkt = (__le32 *)garmin_data_p->privpkt; |
1156 | 1150 | ||
1157 | usb_serial_debug_data(debug, &port->dev, __func__, count, buf); | 1151 | usb_serial_debug_data(debug, &port->dev, __func__, count, buf); |
1158 | 1152 | ||
1159 | /* check for our private packets */ | 1153 | /* check for our private packets */ |
1160 | if (count >= GARMIN_PKTHDR_LENGTH) { | 1154 | if (count >= GARMIN_PKTHDR_LENGTH) { |
1161 | |||
1162 | len = PRIVPKTSIZ; | 1155 | len = PRIVPKTSIZ; |
1163 | if (count < len) | 1156 | if (count < len) |
1164 | len = count; | 1157 | len = count; |
@@ -1169,15 +1162,16 @@ static int garmin_write (struct usb_serial_port *port, | |||
1169 | pktid = getPacketId(garmin_data_p->privpkt); | 1162 | pktid = getPacketId(garmin_data_p->privpkt); |
1170 | 1163 | ||
1171 | if (count == (GARMIN_PKTHDR_LENGTH+pktsiz) | 1164 | if (count == (GARMIN_PKTHDR_LENGTH+pktsiz) |
1172 | && GARMIN_LAYERID_PRIVATE == getLayerId(garmin_data_p->privpkt)) { | 1165 | && GARMIN_LAYERID_PRIVATE == |
1166 | getLayerId(garmin_data_p->privpkt)) { | ||
1173 | 1167 | ||
1174 | dbg("%s - processing private request %d", | 1168 | dbg("%s - processing private request %d", |
1175 | __func__, pktid); | 1169 | __func__, pktid); |
1176 | 1170 | ||
1177 | // drop all unfinished transfers | 1171 | /* drop all unfinished transfers */ |
1178 | garmin_clear(garmin_data_p); | 1172 | garmin_clear(garmin_data_p); |
1179 | 1173 | ||
1180 | switch(pktid) { | 1174 | switch (pktid) { |
1181 | 1175 | ||
1182 | case PRIV_PKTID_SET_DEBUG: | 1176 | case PRIV_PKTID_SET_DEBUG: |
1183 | if (pktsiz != 4) | 1177 | if (pktsiz != 4) |
@@ -1226,44 +1220,31 @@ static int garmin_write (struct usb_serial_port *port, | |||
1226 | } | 1220 | } |
1227 | 1221 | ||
1228 | 1222 | ||
1229 | static int garmin_write_room (struct usb_serial_port *port) | 1223 | static int garmin_write_room(struct tty_struct *tty) |
1230 | { | 1224 | { |
1225 | struct usb_serial_port *port = tty->driver_data; | ||
1231 | /* | 1226 | /* |
1232 | * Report back the bytes currently available in the output buffer. | 1227 | * Report back the bytes currently available in the output buffer. |
1233 | */ | 1228 | */ |
1234 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 1229 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
1235 | return GPS_OUT_BUFSIZ-garmin_data_p->outsize; | 1230 | return GPS_OUT_BUFSIZ-garmin_data_p->outsize; |
1236 | } | 1231 | } |
1237 | 1232 | ||
1238 | 1233 | ||
1239 | static int garmin_chars_in_buffer (struct usb_serial_port *port) | 1234 | static void garmin_read_process(struct garmin_data *garmin_data_p, |
1240 | { | ||
1241 | /* | ||
1242 | * Report back the number of bytes currently in our input buffer. | ||
1243 | * Will this lock up the driver - the buffer contains an incomplete | ||
1244 | * package which will not be written to the device until it | ||
1245 | * has been completed ? | ||
1246 | */ | ||
1247 | //struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | ||
1248 | //return garmin_data_p->insize; | ||
1249 | return 0; | ||
1250 | } | ||
1251 | |||
1252 | |||
1253 | static void garmin_read_process(struct garmin_data * garmin_data_p, | ||
1254 | unsigned char *data, unsigned data_length) | 1235 | unsigned char *data, unsigned data_length) |
1255 | { | 1236 | { |
1256 | if (garmin_data_p->flags & FLAGS_DROP_DATA) { | 1237 | if (garmin_data_p->flags & FLAGS_DROP_DATA) { |
1257 | /* abort-transfer cmd is actice */ | 1238 | /* abort-transfer cmd is actice */ |
1258 | dbg("%s - pkt dropped", __func__); | 1239 | dbg("%s - pkt dropped", __func__); |
1259 | } else if (garmin_data_p->state != STATE_DISCONNECTED && | 1240 | } else if (garmin_data_p->state != STATE_DISCONNECTED && |
1260 | garmin_data_p->state != STATE_RESET ) { | 1241 | garmin_data_p->state != STATE_RESET) { |
1261 | 1242 | ||
1262 | /* remember any appl.layer packets, so we know | 1243 | /* remember any appl.layer packets, so we know |
1263 | if a reset is required or not when closing | 1244 | if a reset is required or not when closing |
1264 | the device */ | 1245 | the device */ |
1265 | if (0 == memcmp(data, GARMIN_APP_LAYER_REPLY, | 1246 | if (0 == memcmp(data, GARMIN_APP_LAYER_REPLY, |
1266 | sizeof(GARMIN_APP_LAYER_REPLY))) { | 1247 | sizeof(GARMIN_APP_LAYER_REPLY))) { |
1267 | atomic_inc(&garmin_data_p->resp_count); | 1248 | atomic_inc(&garmin_data_p->resp_count); |
1268 | } | 1249 | } |
1269 | 1250 | ||
@@ -1273,9 +1254,8 @@ static void garmin_read_process(struct garmin_data * garmin_data_p, | |||
1273 | if (garmin_data_p->flags & FLAGS_QUEUING) { | 1254 | if (garmin_data_p->flags & FLAGS_QUEUING) { |
1274 | pkt_add(garmin_data_p, data, data_length); | 1255 | pkt_add(garmin_data_p, data, data_length); |
1275 | } else if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { | 1256 | } else if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { |
1276 | if (getLayerId(data) == GARMIN_LAYERID_APPL) { | 1257 | if (getLayerId(data) == GARMIN_LAYERID_APPL) |
1277 | pkt_add(garmin_data_p, data, data_length); | 1258 | pkt_add(garmin_data_p, data, data_length); |
1278 | } | ||
1279 | } else { | 1259 | } else { |
1280 | send_to_tty(garmin_data_p->port, data, data_length); | 1260 | send_to_tty(garmin_data_p->port, data, data_length); |
1281 | } | 1261 | } |
@@ -1283,12 +1263,12 @@ static void garmin_read_process(struct garmin_data * garmin_data_p, | |||
1283 | } | 1263 | } |
1284 | 1264 | ||
1285 | 1265 | ||
1286 | static void garmin_read_bulk_callback (struct urb *urb) | 1266 | static void garmin_read_bulk_callback(struct urb *urb) |
1287 | { | 1267 | { |
1288 | unsigned long flags; | 1268 | unsigned long flags; |
1289 | struct usb_serial_port *port = urb->context; | 1269 | struct usb_serial_port *port = urb->context; |
1290 | struct usb_serial *serial = port->serial; | 1270 | struct usb_serial *serial = port->serial; |
1291 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 1271 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
1292 | unsigned char *data = urb->transfer_buffer; | 1272 | unsigned char *data = urb->transfer_buffer; |
1293 | int status = urb->status; | 1273 | int status = urb->status; |
1294 | int retval; | 1274 | int retval; |
@@ -1306,7 +1286,7 @@ static void garmin_read_bulk_callback (struct urb *urb) | |||
1306 | return; | 1286 | return; |
1307 | } | 1287 | } |
1308 | 1288 | ||
1309 | usb_serial_debug_data(debug, &port->dev, | 1289 | usb_serial_debug_data(debug, &port->dev, |
1310 | __func__, urb->actual_length, data); | 1290 | __func__, urb->actual_length, data); |
1311 | 1291 | ||
1312 | garmin_read_process(garmin_data_p, data, urb->actual_length); | 1292 | garmin_read_process(garmin_data_p, data, urb->actual_length); |
@@ -1340,13 +1320,13 @@ static void garmin_read_bulk_callback (struct urb *urb) | |||
1340 | } | 1320 | } |
1341 | 1321 | ||
1342 | 1322 | ||
1343 | static void garmin_read_int_callback (struct urb *urb) | 1323 | static void garmin_read_int_callback(struct urb *urb) |
1344 | { | 1324 | { |
1345 | unsigned long flags; | 1325 | unsigned long flags; |
1346 | int retval; | 1326 | int retval; |
1347 | struct usb_serial_port *port = urb->context; | 1327 | struct usb_serial_port *port = urb->context; |
1348 | struct usb_serial *serial = port->serial; | 1328 | struct usb_serial *serial = port->serial; |
1349 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 1329 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
1350 | unsigned char *data = urb->transfer_buffer; | 1330 | unsigned char *data = urb->transfer_buffer; |
1351 | int status = urb->status; | 1331 | int status = urb->status; |
1352 | 1332 | ||
@@ -1372,30 +1352,31 @@ static void garmin_read_int_callback (struct urb *urb) | |||
1372 | 1352 | ||
1373 | if (urb->actual_length == sizeof(GARMIN_BULK_IN_AVAIL_REPLY) && | 1353 | if (urb->actual_length == sizeof(GARMIN_BULK_IN_AVAIL_REPLY) && |
1374 | 0 == memcmp(data, GARMIN_BULK_IN_AVAIL_REPLY, | 1354 | 0 == memcmp(data, GARMIN_BULK_IN_AVAIL_REPLY, |
1375 | sizeof(GARMIN_BULK_IN_AVAIL_REPLY))) { | 1355 | sizeof(GARMIN_BULK_IN_AVAIL_REPLY))) { |
1376 | 1356 | ||
1377 | dbg("%s - bulk data available.", __func__); | 1357 | dbg("%s - bulk data available.", __func__); |
1378 | 1358 | ||
1379 | if (0 == (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) { | 1359 | if (0 == (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) { |
1380 | 1360 | ||
1381 | /* bulk data available */ | 1361 | /* bulk data available */ |
1382 | usb_fill_bulk_urb (port->read_urb, serial->dev, | 1362 | usb_fill_bulk_urb(port->read_urb, serial->dev, |
1383 | usb_rcvbulkpipe (serial->dev, | 1363 | usb_rcvbulkpipe(serial->dev, |
1384 | port->bulk_in_endpointAddress), | 1364 | port->bulk_in_endpointAddress), |
1385 | port->read_urb->transfer_buffer, | 1365 | port->read_urb->transfer_buffer, |
1386 | port->read_urb->transfer_buffer_length, | 1366 | port->read_urb->transfer_buffer_length, |
1387 | garmin_read_bulk_callback, port); | 1367 | garmin_read_bulk_callback, port); |
1388 | retval = usb_submit_urb(port->read_urb, GFP_ATOMIC); | 1368 | retval = usb_submit_urb(port->read_urb, GFP_ATOMIC); |
1389 | if (retval) { | 1369 | if (retval) { |
1390 | dev_err(&port->dev, | 1370 | dev_err(&port->dev, |
1391 | "%s - failed submitting read urb, error %d\n", | 1371 | "%s - failed submitting read urb, error %d\n", |
1392 | __func__, retval); | 1372 | __func__, retval); |
1393 | } else { | 1373 | } else { |
1394 | spin_lock_irqsave(&garmin_data_p->lock, flags); | 1374 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
1395 | garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE; | 1375 | garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE; |
1396 | /* do not send this packet to the user */ | 1376 | /* do not send this packet to the user */ |
1397 | garmin_data_p->ignorePkts = 1; | 1377 | garmin_data_p->ignorePkts = 1; |
1398 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | 1378 | spin_unlock_irqrestore(&garmin_data_p->lock, |
1379 | flags); | ||
1399 | } | 1380 | } |
1400 | } else { | 1381 | } else { |
1401 | /* bulk-in transfer still active */ | 1382 | /* bulk-in transfer still active */ |
@@ -1406,15 +1387,15 @@ static void garmin_read_int_callback (struct urb *urb) | |||
1406 | 1387 | ||
1407 | } else if (urb->actual_length == (4+sizeof(GARMIN_START_SESSION_REPLY)) | 1388 | } else if (urb->actual_length == (4+sizeof(GARMIN_START_SESSION_REPLY)) |
1408 | && 0 == memcmp(data, GARMIN_START_SESSION_REPLY, | 1389 | && 0 == memcmp(data, GARMIN_START_SESSION_REPLY, |
1409 | sizeof(GARMIN_START_SESSION_REPLY))) { | 1390 | sizeof(GARMIN_START_SESSION_REPLY))) { |
1410 | 1391 | ||
1411 | spin_lock_irqsave(&garmin_data_p->lock, flags); | 1392 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
1412 | garmin_data_p->flags |= FLAGS_SESSION_REPLY1_SEEN; | 1393 | garmin_data_p->flags |= FLAGS_SESSION_REPLY1_SEEN; |
1413 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); | 1394 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
1414 | 1395 | ||
1415 | /* save the serial number */ | 1396 | /* save the serial number */ |
1416 | garmin_data_p->serial_num | 1397 | garmin_data_p->serial_num = __le32_to_cpup( |
1417 | = __le32_to_cpup((__le32*)(data+GARMIN_PKTHDR_LENGTH)); | 1398 | (__le32 *)(data+GARMIN_PKTHDR_LENGTH)); |
1418 | 1399 | ||
1419 | dbg("%s - start-of-session reply seen - serial %u.", | 1400 | dbg("%s - start-of-session reply seen - serial %u.", |
1420 | __func__, garmin_data_p->serial_num); | 1401 | __func__, garmin_data_p->serial_num); |
@@ -1433,7 +1414,7 @@ static void garmin_read_int_callback (struct urb *urb) | |||
1433 | } | 1414 | } |
1434 | 1415 | ||
1435 | port->interrupt_in_urb->dev = port->serial->dev; | 1416 | port->interrupt_in_urb->dev = port->serial->dev; |
1436 | retval = usb_submit_urb (urb, GFP_ATOMIC); | 1417 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
1437 | if (retval) | 1418 | if (retval) |
1438 | dev_err(&urb->dev->dev, | 1419 | dev_err(&urb->dev->dev, |
1439 | "%s - Error %d submitting interrupt urb\n", | 1420 | "%s - Error %d submitting interrupt urb\n", |
@@ -1446,7 +1427,7 @@ static void garmin_read_int_callback (struct urb *urb) | |||
1446 | * and then sets a timer to call itself again until all queued data | 1427 | * and then sets a timer to call itself again until all queued data |
1447 | * is sent. | 1428 | * is sent. |
1448 | */ | 1429 | */ |
1449 | static int garmin_flush_queue(struct garmin_data * garmin_data_p) | 1430 | static int garmin_flush_queue(struct garmin_data *garmin_data_p) |
1450 | { | 1431 | { |
1451 | unsigned long flags; | 1432 | unsigned long flags; |
1452 | struct garmin_packet *pkt; | 1433 | struct garmin_packet *pkt; |
@@ -1468,10 +1449,11 @@ static int garmin_flush_queue(struct garmin_data * garmin_data_p) | |||
1468 | } | 1449 | } |
1469 | 1450 | ||
1470 | 1451 | ||
1471 | static void garmin_throttle (struct usb_serial_port *port) | 1452 | static void garmin_throttle(struct tty_struct *tty) |
1472 | { | 1453 | { |
1454 | struct usb_serial_port *port = tty->driver_data; | ||
1455 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); | ||
1473 | unsigned long flags; | 1456 | unsigned long flags; |
1474 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | ||
1475 | 1457 | ||
1476 | dbg("%s - port %d", __func__, port->number); | 1458 | dbg("%s - port %d", __func__, port->number); |
1477 | /* set flag, data received will be put into a queue | 1459 | /* set flag, data received will be put into a queue |
@@ -1482,10 +1464,11 @@ static void garmin_throttle (struct usb_serial_port *port) | |||
1482 | } | 1464 | } |
1483 | 1465 | ||
1484 | 1466 | ||
1485 | static void garmin_unthrottle (struct usb_serial_port *port) | 1467 | static void garmin_unthrottle(struct tty_struct *tty) |
1486 | { | 1468 | { |
1469 | struct usb_serial_port *port = tty->driver_data; | ||
1470 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); | ||
1487 | unsigned long flags; | 1471 | unsigned long flags; |
1488 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | ||
1489 | int status; | 1472 | int status; |
1490 | 1473 | ||
1491 | dbg("%s - port %d", __func__, port->number); | 1474 | dbg("%s - port %d", __func__, port->number); |
@@ -1507,8 +1490,6 @@ static void garmin_unthrottle (struct usb_serial_port *port) | |||
1507 | } | 1490 | } |
1508 | } | 1491 | } |
1509 | 1492 | ||
1510 | |||
1511 | |||
1512 | /* | 1493 | /* |
1513 | * The timer is currently only used to send queued packets to | 1494 | * The timer is currently only used to send queued packets to |
1514 | * the tty in cases where the protocol provides no own handshaking | 1495 | * the tty in cases where the protocol provides no own handshaking |
@@ -1526,11 +1507,11 @@ static void timeout_handler(unsigned long data) | |||
1526 | 1507 | ||
1527 | 1508 | ||
1528 | 1509 | ||
1529 | static int garmin_attach (struct usb_serial *serial) | 1510 | static int garmin_attach(struct usb_serial *serial) |
1530 | { | 1511 | { |
1531 | int status = 0; | 1512 | int status = 0; |
1532 | struct usb_serial_port *port = serial->port[0]; | 1513 | struct usb_serial_port *port = serial->port[0]; |
1533 | struct garmin_data * garmin_data_p = NULL; | 1514 | struct garmin_data *garmin_data_p = NULL; |
1534 | 1515 | ||
1535 | dbg("%s", __func__); | 1516 | dbg("%s", __func__); |
1536 | 1517 | ||
@@ -1542,7 +1523,7 @@ static int garmin_attach (struct usb_serial *serial) | |||
1542 | init_timer(&garmin_data_p->timer); | 1523 | init_timer(&garmin_data_p->timer); |
1543 | spin_lock_init(&garmin_data_p->lock); | 1524 | spin_lock_init(&garmin_data_p->lock); |
1544 | INIT_LIST_HEAD(&garmin_data_p->pktlist); | 1525 | INIT_LIST_HEAD(&garmin_data_p->pktlist); |
1545 | //garmin_data_p->timer.expires = jiffies + session_timeout; | 1526 | /* garmin_data_p->timer.expires = jiffies + session_timeout; */ |
1546 | garmin_data_p->timer.data = (unsigned long)garmin_data_p; | 1527 | garmin_data_p->timer.data = (unsigned long)garmin_data_p; |
1547 | garmin_data_p->timer.function = timeout_handler; | 1528 | garmin_data_p->timer.function = timeout_handler; |
1548 | garmin_data_p->port = port; | 1529 | garmin_data_p->port = port; |
@@ -1556,16 +1537,16 @@ static int garmin_attach (struct usb_serial *serial) | |||
1556 | } | 1537 | } |
1557 | 1538 | ||
1558 | 1539 | ||
1559 | static void garmin_shutdown (struct usb_serial *serial) | 1540 | static void garmin_shutdown(struct usb_serial *serial) |
1560 | { | 1541 | { |
1561 | struct usb_serial_port *port = serial->port[0]; | 1542 | struct usb_serial_port *port = serial->port[0]; |
1562 | struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); | 1543 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
1563 | 1544 | ||
1564 | dbg("%s", __func__); | 1545 | dbg("%s", __func__); |
1565 | 1546 | ||
1566 | usb_kill_urb (port->interrupt_in_urb); | 1547 | usb_kill_urb(port->interrupt_in_urb); |
1567 | del_timer_sync(&garmin_data_p->timer); | 1548 | del_timer_sync(&garmin_data_p->timer); |
1568 | kfree (garmin_data_p); | 1549 | kfree(garmin_data_p); |
1569 | usb_set_serial_port_data(port, NULL); | 1550 | usb_set_serial_port_data(port, NULL); |
1570 | } | 1551 | } |
1571 | 1552 | ||
@@ -1588,7 +1569,6 @@ static struct usb_serial_driver garmin_device = { | |||
1588 | .shutdown = garmin_shutdown, | 1569 | .shutdown = garmin_shutdown, |
1589 | .write = garmin_write, | 1570 | .write = garmin_write, |
1590 | .write_room = garmin_write_room, | 1571 | .write_room = garmin_write_room, |
1591 | .chars_in_buffer = garmin_chars_in_buffer, | ||
1592 | .write_bulk_callback = garmin_write_bulk_callback, | 1572 | .write_bulk_callback = garmin_write_bulk_callback, |
1593 | .read_bulk_callback = garmin_read_bulk_callback, | 1573 | .read_bulk_callback = garmin_read_bulk_callback, |
1594 | .read_int_callback = garmin_read_int_callback, | 1574 | .read_int_callback = garmin_read_int_callback, |
@@ -1596,7 +1576,7 @@ static struct usb_serial_driver garmin_device = { | |||
1596 | 1576 | ||
1597 | 1577 | ||
1598 | 1578 | ||
1599 | static int __init garmin_init (void) | 1579 | static int __init garmin_init(void) |
1600 | { | 1580 | { |
1601 | int retval; | 1581 | int retval; |
1602 | 1582 | ||
@@ -1616,10 +1596,10 @@ failed_garmin_register: | |||
1616 | } | 1596 | } |
1617 | 1597 | ||
1618 | 1598 | ||
1619 | static void __exit garmin_exit (void) | 1599 | static void __exit garmin_exit(void) |
1620 | { | 1600 | { |
1621 | usb_deregister (&garmin_driver); | 1601 | usb_deregister(&garmin_driver); |
1622 | usb_serial_deregister (&garmin_device); | 1602 | usb_serial_deregister(&garmin_device); |
1623 | } | 1603 | } |
1624 | 1604 | ||
1625 | 1605 | ||
@@ -1628,8 +1608,8 @@ static void __exit garmin_exit (void) | |||
1628 | module_init(garmin_init); | 1608 | module_init(garmin_init); |
1629 | module_exit(garmin_exit); | 1609 | module_exit(garmin_exit); |
1630 | 1610 | ||
1631 | MODULE_AUTHOR( DRIVER_AUTHOR ); | 1611 | MODULE_AUTHOR(DRIVER_AUTHOR); |
1632 | MODULE_DESCRIPTION( DRIVER_DESC ); | 1612 | MODULE_DESCRIPTION(DRIVER_DESC); |
1633 | MODULE_LICENSE("GPL"); | 1613 | MODULE_LICENSE("GPL"); |
1634 | 1614 | ||
1635 | module_param(debug, bool, S_IWUSR | S_IRUGO); | 1615 | module_param(debug, bool, S_IWUSR | S_IRUGO); |