aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/garmin_gps.c
diff options
context:
space:
mode:
authorAlan Cox <alan@redhat.com>2008-07-22 06:11:44 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-22 16:03:23 -0400
commitaf6d780b578778d442278ac4894ff10847bebae2 (patch)
tree3d328f753b961966ea692e22d439bd361481f5a6 /drivers/usb/serial/garmin_gps.c
parent64701e8122fff3605c674c056749864c97485de4 (diff)
garmin_gps: Coding style
Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/usb/serial/garmin_gps.c')
-rw-r--r--drivers/usb/serial/garmin_gps.c354
1 files changed, 176 insertions, 178 deletions
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index 06cfa43c6f02..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 @@
44static int initial_mode = 1; 44static int initial_mode = 1;
45 45
46/* debug flag */ 46/* debug flag */
47static int debug = 0; 47static 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;
121struct garmin_packet { 121struct 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 */
188static void gsp_next_packet(struct garmin_data * garmin_data_p); 189static void gsp_next_packet(struct garmin_data *garmin_data_p);
189static int garmin_write_bulk(struct usb_serial_port *port, 190static 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
219static struct usb_device_id id_table [] = { 220static 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
225MODULE_DEVICE_TABLE (usb, id_table); 227MODULE_DEVICE_TABLE(usb, id_table);
226 228
227static struct usb_driver garmin_driver = { 229static 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
236static inline int noResponseFromAppLayer(struct garmin_data * garmin_data_p) 238static 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 */
262static inline int isAbortTrfCmnd(const unsigned char *buf) 265static 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;
@@ -279,7 +282,7 @@ static void send_to_tty(struct usb_serial_port *port,
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 */
299static int pkt_add(struct garmin_data * garmin_data_p, 302static 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 */
337static struct garmin_packet *pkt_pop(struct garmin_data * garmin_data_p) 339static 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 */
353static void pkt_clear(struct garmin_data * garmin_data_p) 355static 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 */
375static int gsp_send_ack(struct garmin_data * garmin_data_p, __u8 pkt_id) 377static 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 */
421static int gsp_rec_packet(struct garmin_data * garmin_data_p, int count) 422static 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
498static int gsp_receive(struct garmin_data * garmin_data_p, 499static 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 */
626static int gsp_send(struct garmin_data * garmin_data_p, 623static 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 */
747static void gsp_next_packet(struct garmin_data * garmin_data_p) 743static 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 */
777static int nat_receive(struct garmin_data * garmin_data_p, 773static 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
843static void priv_status_resp(struct usb_serial_port *port) 841static 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 */
889static int garmin_clear(struct garmin_data * garmin_data_p) 887static 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,12 +965,12 @@ static int garmin_init_session(struct usb_serial_port *port)
970 965
971 966
972 967
973static int garmin_open (struct tty_struct *tty, 968static int garmin_open(struct tty_struct *tty,
974 struct usb_serial_port *port, struct file *filp) 969 struct usb_serial_port *port, struct file *filp)
975{ 970{
976 unsigned long flags; 971 unsigned long flags;
977 int status = 0; 972 int status = 0;
978 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);
979 974
980 dbg("%s - port %d", __func__, port->number); 975 dbg("%s - port %d", __func__, port->number);
981 976
@@ -996,8 +991,8 @@ static int garmin_open (struct tty_struct *tty,
996 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 991 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
997 992
998 /* shutdown any bulk reads that might be going on */ 993 /* shutdown any bulk reads that might be going on */
999 usb_kill_urb (port->write_urb); 994 usb_kill_urb(port->write_urb);
1000 usb_kill_urb (port->read_urb); 995 usb_kill_urb(port->read_urb);
1001 996
1002 if (garmin_data_p->state == STATE_RESET) 997 if (garmin_data_p->state == STATE_RESET)
1003 status = garmin_init_session(port); 998 status = garmin_init_session(port);
@@ -1008,10 +1003,10 @@ static int garmin_open (struct tty_struct *tty,
1008 1003
1009 1004
1010static void garmin_close(struct tty_struct *tty, 1005static void garmin_close(struct tty_struct *tty,
1011 struct usb_serial_port *port, struct file * filp) 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 tty_struct *tty,
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,20 +1037,22 @@ static void garmin_close(struct tty_struct *tty,
1042 mutex_unlock(&port->serial->disc_mutex); 1037 mutex_unlock(&port->serial->disc_mutex);
1043} 1038}
1044 1039
1045static void garmin_write_bulk_callback (struct urb *urb) 1040static void garmin_write_bulk_callback(struct urb *urb)
1046{ 1041{
1047 unsigned long flags; 1042 unsigned long flags;
1048 struct usb_serial_port *port = urb->context; 1043 struct usb_serial_port *port = urb->context;
1049 int status = urb->status; 1044 int status = urb->status;
1050 1045
1051 if (port) { 1046 if (port) {
1052 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);
1053 1049
1054 dbg("%s - port %d", __func__, port->number); 1050 dbg("%s - port %d", __func__, port->number);
1055 1051
1056 if (GARMIN_LAYERID_APPL == getLayerId(urb->transfer_buffer) 1052 if (GARMIN_LAYERID_APPL == getLayerId(urb->transfer_buffer)
1057 && (garmin_data_p->mode == MODE_GARMIN_SERIAL)) { 1053 && (garmin_data_p->mode == MODE_GARMIN_SERIAL)) {
1058 gsp_send_ack(garmin_data_p, ((__u8 *)urb->transfer_buffer)[4]); 1054 gsp_send_ack(garmin_data_p,
1055 ((__u8 *)urb->transfer_buffer)[4]);
1059 } 1056 }
1060 1057
1061 if (status) { 1058 if (status) {
@@ -1069,20 +1066,21 @@ static void garmin_write_bulk_callback (struct urb *urb)
1069 usb_serial_port_softint(port); 1066 usb_serial_port_softint(port);
1070 } 1067 }
1071 1068
1072 /* 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 */
1073 1071
1074 /* 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 */
1075 kfree (urb->transfer_buffer); 1073 kfree(urb->transfer_buffer);
1076} 1074}
1077 1075
1078 1076
1079static int garmin_write_bulk (struct usb_serial_port *port, 1077static int garmin_write_bulk(struct usb_serial_port *port,
1080 const unsigned char *buf, int count, 1078 const unsigned char *buf, int count,
1081 int dismiss_ack) 1079 int dismiss_ack)
1082{ 1080{
1083 unsigned long flags; 1081 unsigned long flags;
1084 struct usb_serial *serial = port->serial; 1082 struct usb_serial *serial = port->serial;
1085 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);
1086 struct urb *urb; 1084 struct urb *urb;
1087 unsigned char *buffer; 1085 unsigned char *buffer;
1088 int status; 1086 int status;
@@ -1094,7 +1092,7 @@ static int garmin_write_bulk (struct usb_serial_port *port,
1094 garmin_data_p->flags &= ~FLAGS_DROP_DATA; 1092 garmin_data_p->flags &= ~FLAGS_DROP_DATA;
1095 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 1093 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1096 1094
1097 buffer = kmalloc (count, GFP_ATOMIC); 1095 buffer = kmalloc(count, GFP_ATOMIC);
1098 if (!buffer) { 1096 if (!buffer) {
1099 dev_err(&port->dev, "out of memory\n"); 1097 dev_err(&port->dev, "out of memory\n");
1100 return -ENOMEM; 1098 return -ENOMEM;
@@ -1103,17 +1101,17 @@ static int garmin_write_bulk (struct usb_serial_port *port,
1103 urb = usb_alloc_urb(0, GFP_ATOMIC); 1101 urb = usb_alloc_urb(0, GFP_ATOMIC);
1104 if (!urb) { 1102 if (!urb) {
1105 dev_err(&port->dev, "no more free urbs\n"); 1103 dev_err(&port->dev, "no more free urbs\n");
1106 kfree (buffer); 1104 kfree(buffer);
1107 return -ENOMEM; 1105 return -ENOMEM;
1108 } 1106 }
1109 1107
1110 memcpy (buffer, buf, count); 1108 memcpy(buffer, buf, count);
1111 1109
1112 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer); 1110 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);
1113 1111
1114 usb_fill_bulk_urb (urb, serial->dev, 1112 usb_fill_bulk_urb(urb, serial->dev,
1115 usb_sndbulkpipe (serial->dev, 1113 usb_sndbulkpipe(serial->dev,
1116 port->bulk_out_endpointAddress), 1114 port->bulk_out_endpointAddress),
1117 buffer, count, 1115 buffer, count,
1118 garmin_write_bulk_callback, 1116 garmin_write_bulk_callback,
1119 dismiss_ack ? NULL : port); 1117 dismiss_ack ? NULL : port);
@@ -1131,24 +1129,23 @@ static int garmin_write_bulk (struct usb_serial_port *port,
1131 status = usb_submit_urb(urb, GFP_ATOMIC); 1129 status = usb_submit_urb(urb, GFP_ATOMIC);
1132 if (status) { 1130 if (status) {
1133 dev_err(&port->dev, 1131 dev_err(&port->dev,
1134 "%s - usb_submit_urb(write bulk) " 1132 "%s - usb_submit_urb(write bulk) failed with status = %d\n",
1135 "failed with status = %d\n",
1136 __func__, status); 1133 __func__, status);
1137 count = status; 1134 count = status;
1138 } 1135 }
1139 1136
1140 /* we are done with this urb, so let the host driver 1137 /* we are done with this urb, so let the host driver
1141 * really free it when it is finished with it */ 1138 * really free it when it is finished with it */
1142 usb_free_urb (urb); 1139 usb_free_urb(urb);
1143 1140
1144 return count; 1141 return count;
1145} 1142}
1146 1143
1147static int garmin_write (struct tty_struct *tty, struct usb_serial_port *port, 1144static int garmin_write(struct tty_struct *tty, struct usb_serial_port *port,
1148 const unsigned char *buf, int count) 1145 const unsigned char *buf, int count)
1149{ 1146{
1150 int pktid, pktsiz, len; 1147 int pktid, pktsiz, len;
1151 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);
1152 __le32 *privpkt = (__le32 *)garmin_data_p->privpkt; 1149 __le32 *privpkt = (__le32 *)garmin_data_p->privpkt;
1153 1150
1154 usb_serial_debug_data(debug, &port->dev, __func__, count, buf); 1151 usb_serial_debug_data(debug, &port->dev, __func__, count, buf);
@@ -1165,15 +1162,16 @@ static int garmin_write (struct tty_struct *tty, struct usb_serial_port *port,
1165 pktid = getPacketId(garmin_data_p->privpkt); 1162 pktid = getPacketId(garmin_data_p->privpkt);
1166 1163
1167 if (count == (GARMIN_PKTHDR_LENGTH+pktsiz) 1164 if (count == (GARMIN_PKTHDR_LENGTH+pktsiz)
1168 && GARMIN_LAYERID_PRIVATE == getLayerId(garmin_data_p->privpkt)) { 1165 && GARMIN_LAYERID_PRIVATE ==
1166 getLayerId(garmin_data_p->privpkt)) {
1169 1167
1170 dbg("%s - processing private request %d", 1168 dbg("%s - processing private request %d",
1171 __func__, pktid); 1169 __func__, pktid);
1172 1170
1173 // drop all unfinished transfers 1171 /* drop all unfinished transfers */
1174 garmin_clear(garmin_data_p); 1172 garmin_clear(garmin_data_p);
1175 1173
1176 switch(pktid) { 1174 switch (pktid) {
1177 1175
1178 case PRIV_PKTID_SET_DEBUG: 1176 case PRIV_PKTID_SET_DEBUG:
1179 if (pktsiz != 4) 1177 if (pktsiz != 4)
@@ -1228,25 +1226,25 @@ static int garmin_write_room(struct tty_struct *tty)
1228 /* 1226 /*
1229 * Report back the bytes currently available in the output buffer. 1227 * Report back the bytes currently available in the output buffer.
1230 */ 1228 */
1231 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);
1232 return GPS_OUT_BUFSIZ-garmin_data_p->outsize; 1230 return GPS_OUT_BUFSIZ-garmin_data_p->outsize;
1233} 1231}
1234 1232
1235 1233
1236static void garmin_read_process(struct garmin_data * garmin_data_p, 1234static void garmin_read_process(struct garmin_data *garmin_data_p,
1237 unsigned char *data, unsigned data_length) 1235 unsigned char *data, unsigned data_length)
1238{ 1236{
1239 if (garmin_data_p->flags & FLAGS_DROP_DATA) { 1237 if (garmin_data_p->flags & FLAGS_DROP_DATA) {
1240 /* abort-transfer cmd is actice */ 1238 /* abort-transfer cmd is actice */
1241 dbg("%s - pkt dropped", __func__); 1239 dbg("%s - pkt dropped", __func__);
1242 } else if (garmin_data_p->state != STATE_DISCONNECTED && 1240 } else if (garmin_data_p->state != STATE_DISCONNECTED &&
1243 garmin_data_p->state != STATE_RESET ) { 1241 garmin_data_p->state != STATE_RESET) {
1244 1242
1245 /* remember any appl.layer packets, so we know 1243 /* remember any appl.layer packets, so we know
1246 if a reset is required or not when closing 1244 if a reset is required or not when closing
1247 the device */ 1245 the device */
1248 if (0 == memcmp(data, GARMIN_APP_LAYER_REPLY, 1246 if (0 == memcmp(data, GARMIN_APP_LAYER_REPLY,
1249 sizeof(GARMIN_APP_LAYER_REPLY))) { 1247 sizeof(GARMIN_APP_LAYER_REPLY))) {
1250 atomic_inc(&garmin_data_p->resp_count); 1248 atomic_inc(&garmin_data_p->resp_count);
1251 } 1249 }
1252 1250
@@ -1256,9 +1254,8 @@ static void garmin_read_process(struct garmin_data * garmin_data_p,
1256 if (garmin_data_p->flags & FLAGS_QUEUING) { 1254 if (garmin_data_p->flags & FLAGS_QUEUING) {
1257 pkt_add(garmin_data_p, data, data_length); 1255 pkt_add(garmin_data_p, data, data_length);
1258 } else if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { 1256 } else if (garmin_data_p->mode == MODE_GARMIN_SERIAL) {
1259 if (getLayerId(data) == GARMIN_LAYERID_APPL) { 1257 if (getLayerId(data) == GARMIN_LAYERID_APPL)
1260 pkt_add(garmin_data_p, data, data_length); 1258 pkt_add(garmin_data_p, data, data_length);
1261 }
1262 } else { 1259 } else {
1263 send_to_tty(garmin_data_p->port, data, data_length); 1260 send_to_tty(garmin_data_p->port, data, data_length);
1264 } 1261 }
@@ -1266,12 +1263,12 @@ static void garmin_read_process(struct garmin_data * garmin_data_p,
1266} 1263}
1267 1264
1268 1265
1269static void garmin_read_bulk_callback (struct urb *urb) 1266static void garmin_read_bulk_callback(struct urb *urb)
1270{ 1267{
1271 unsigned long flags; 1268 unsigned long flags;
1272 struct usb_serial_port *port = urb->context; 1269 struct usb_serial_port *port = urb->context;
1273 struct usb_serial *serial = port->serial; 1270 struct usb_serial *serial = port->serial;
1274 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);
1275 unsigned char *data = urb->transfer_buffer; 1272 unsigned char *data = urb->transfer_buffer;
1276 int status = urb->status; 1273 int status = urb->status;
1277 int retval; 1274 int retval;
@@ -1289,7 +1286,7 @@ static void garmin_read_bulk_callback (struct urb *urb)
1289 return; 1286 return;
1290 } 1287 }
1291 1288
1292 usb_serial_debug_data(debug, &port->dev, 1289 usb_serial_debug_data(debug, &port->dev,
1293 __func__, urb->actual_length, data); 1290 __func__, urb->actual_length, data);
1294 1291
1295 garmin_read_process(garmin_data_p, data, urb->actual_length); 1292 garmin_read_process(garmin_data_p, data, urb->actual_length);
@@ -1323,13 +1320,13 @@ static void garmin_read_bulk_callback (struct urb *urb)
1323} 1320}
1324 1321
1325 1322
1326static void garmin_read_int_callback (struct urb *urb) 1323static void garmin_read_int_callback(struct urb *urb)
1327{ 1324{
1328 unsigned long flags; 1325 unsigned long flags;
1329 int retval; 1326 int retval;
1330 struct usb_serial_port *port = urb->context; 1327 struct usb_serial_port *port = urb->context;
1331 struct usb_serial *serial = port->serial; 1328 struct usb_serial *serial = port->serial;
1332 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);
1333 unsigned char *data = urb->transfer_buffer; 1330 unsigned char *data = urb->transfer_buffer;
1334 int status = urb->status; 1331 int status = urb->status;
1335 1332
@@ -1355,30 +1352,31 @@ static void garmin_read_int_callback (struct urb *urb)
1355 1352
1356 if (urb->actual_length == sizeof(GARMIN_BULK_IN_AVAIL_REPLY) && 1353 if (urb->actual_length == sizeof(GARMIN_BULK_IN_AVAIL_REPLY) &&
1357 0 == memcmp(data, GARMIN_BULK_IN_AVAIL_REPLY, 1354 0 == memcmp(data, GARMIN_BULK_IN_AVAIL_REPLY,
1358 sizeof(GARMIN_BULK_IN_AVAIL_REPLY))) { 1355 sizeof(GARMIN_BULK_IN_AVAIL_REPLY))) {
1359 1356
1360 dbg("%s - bulk data available.", __func__); 1357 dbg("%s - bulk data available.", __func__);
1361 1358
1362 if (0 == (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) { 1359 if (0 == (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) {
1363 1360
1364 /* bulk data available */ 1361 /* bulk data available */
1365 usb_fill_bulk_urb (port->read_urb, serial->dev, 1362 usb_fill_bulk_urb(port->read_urb, serial->dev,
1366 usb_rcvbulkpipe (serial->dev, 1363 usb_rcvbulkpipe(serial->dev,
1367 port->bulk_in_endpointAddress), 1364 port->bulk_in_endpointAddress),
1368 port->read_urb->transfer_buffer, 1365 port->read_urb->transfer_buffer,
1369 port->read_urb->transfer_buffer_length, 1366 port->read_urb->transfer_buffer_length,
1370 garmin_read_bulk_callback, port); 1367 garmin_read_bulk_callback, port);
1371 retval = usb_submit_urb(port->read_urb, GFP_ATOMIC); 1368 retval = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1372 if (retval) { 1369 if (retval) {
1373 dev_err(&port->dev, 1370 dev_err(&port->dev,
1374 "%s - failed submitting read urb, error %d\n", 1371 "%s - failed submitting read urb, error %d\n",
1375 __func__, retval); 1372 __func__, retval);
1376 } else { 1373 } else {
1377 spin_lock_irqsave(&garmin_data_p->lock, flags); 1374 spin_lock_irqsave(&garmin_data_p->lock, flags);
1378 garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE; 1375 garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE;
1379 /* do not send this packet to the user */ 1376 /* do not send this packet to the user */
1380 garmin_data_p->ignorePkts = 1; 1377 garmin_data_p->ignorePkts = 1;
1381 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 1378 spin_unlock_irqrestore(&garmin_data_p->lock,
1379 flags);
1382 } 1380 }
1383 } else { 1381 } else {
1384 /* bulk-in transfer still active */ 1382 /* bulk-in transfer still active */
@@ -1389,15 +1387,15 @@ static void garmin_read_int_callback (struct urb *urb)
1389 1387
1390 } else if (urb->actual_length == (4+sizeof(GARMIN_START_SESSION_REPLY)) 1388 } else if (urb->actual_length == (4+sizeof(GARMIN_START_SESSION_REPLY))
1391 && 0 == memcmp(data, GARMIN_START_SESSION_REPLY, 1389 && 0 == memcmp(data, GARMIN_START_SESSION_REPLY,
1392 sizeof(GARMIN_START_SESSION_REPLY))) { 1390 sizeof(GARMIN_START_SESSION_REPLY))) {
1393 1391
1394 spin_lock_irqsave(&garmin_data_p->lock, flags); 1392 spin_lock_irqsave(&garmin_data_p->lock, flags);
1395 garmin_data_p->flags |= FLAGS_SESSION_REPLY1_SEEN; 1393 garmin_data_p->flags |= FLAGS_SESSION_REPLY1_SEEN;
1396 spin_unlock_irqrestore(&garmin_data_p->lock, flags); 1394 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1397 1395
1398 /* save the serial number */ 1396 /* save the serial number */
1399 garmin_data_p->serial_num 1397 garmin_data_p->serial_num = __le32_to_cpup(
1400 = __le32_to_cpup((__le32*)(data+GARMIN_PKTHDR_LENGTH)); 1398 (__le32 *)(data+GARMIN_PKTHDR_LENGTH));
1401 1399
1402 dbg("%s - start-of-session reply seen - serial %u.", 1400 dbg("%s - start-of-session reply seen - serial %u.",
1403 __func__, garmin_data_p->serial_num); 1401 __func__, garmin_data_p->serial_num);
@@ -1416,7 +1414,7 @@ static void garmin_read_int_callback (struct urb *urb)
1416 } 1414 }
1417 1415
1418 port->interrupt_in_urb->dev = port->serial->dev; 1416 port->interrupt_in_urb->dev = port->serial->dev;
1419 retval = usb_submit_urb (urb, GFP_ATOMIC); 1417 retval = usb_submit_urb(urb, GFP_ATOMIC);
1420 if (retval) 1418 if (retval)
1421 dev_err(&urb->dev->dev, 1419 dev_err(&urb->dev->dev,
1422 "%s - Error %d submitting interrupt urb\n", 1420 "%s - Error %d submitting interrupt urb\n",
@@ -1429,7 +1427,7 @@ static void garmin_read_int_callback (struct urb *urb)
1429 * 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
1430 * is sent. 1428 * is sent.
1431 */ 1429 */
1432static int garmin_flush_queue(struct garmin_data * garmin_data_p) 1430static int garmin_flush_queue(struct garmin_data *garmin_data_p)
1433{ 1431{
1434 unsigned long flags; 1432 unsigned long flags;
1435 struct garmin_packet *pkt; 1433 struct garmin_packet *pkt;
@@ -1454,7 +1452,7 @@ static int garmin_flush_queue(struct garmin_data * garmin_data_p)
1454static void garmin_throttle(struct tty_struct *tty) 1452static void garmin_throttle(struct tty_struct *tty)
1455{ 1453{
1456 struct usb_serial_port *port = tty->driver_data; 1454 struct usb_serial_port *port = tty->driver_data;
1457 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1455 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1458 unsigned long flags; 1456 unsigned long flags;
1459 1457
1460 dbg("%s - port %d", __func__, port->number); 1458 dbg("%s - port %d", __func__, port->number);
@@ -1466,10 +1464,10 @@ static void garmin_throttle(struct tty_struct *tty)
1466} 1464}
1467 1465
1468 1466
1469static void garmin_unthrottle (struct tty_struct *tty) 1467static void garmin_unthrottle(struct tty_struct *tty)
1470{ 1468{
1471 struct usb_serial_port *port = tty->driver_data; 1469 struct usb_serial_port *port = tty->driver_data;
1472 struct garmin_data * garmin_data_p = usb_get_serial_port_data(port); 1470 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1473 unsigned long flags; 1471 unsigned long flags;
1474 int status; 1472 int status;
1475 1473
@@ -1513,7 +1511,7 @@ static int garmin_attach(struct usb_serial *serial)
1513{ 1511{
1514 int status = 0; 1512 int status = 0;
1515 struct usb_serial_port *port = serial->port[0]; 1513 struct usb_serial_port *port = serial->port[0];
1516 struct garmin_data * garmin_data_p = NULL; 1514 struct garmin_data *garmin_data_p = NULL;
1517 1515
1518 dbg("%s", __func__); 1516 dbg("%s", __func__);
1519 1517
@@ -1525,7 +1523,7 @@ static int garmin_attach(struct usb_serial *serial)
1525 init_timer(&garmin_data_p->timer); 1523 init_timer(&garmin_data_p->timer);
1526 spin_lock_init(&garmin_data_p->lock); 1524 spin_lock_init(&garmin_data_p->lock);
1527 INIT_LIST_HEAD(&garmin_data_p->pktlist); 1525 INIT_LIST_HEAD(&garmin_data_p->pktlist);
1528 //garmin_data_p->timer.expires = jiffies + session_timeout; 1526 /* garmin_data_p->timer.expires = jiffies + session_timeout; */
1529 garmin_data_p->timer.data = (unsigned long)garmin_data_p; 1527 garmin_data_p->timer.data = (unsigned long)garmin_data_p;
1530 garmin_data_p->timer.function = timeout_handler; 1528 garmin_data_p->timer.function = timeout_handler;
1531 garmin_data_p->port = port; 1529 garmin_data_p->port = port;
@@ -1542,13 +1540,13 @@ static int garmin_attach(struct usb_serial *serial)
1542static void garmin_shutdown(struct usb_serial *serial) 1540static void garmin_shutdown(struct usb_serial *serial)
1543{ 1541{
1544 struct usb_serial_port *port = serial->port[0]; 1542 struct usb_serial_port *port = serial->port[0];
1545 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);
1546 1544
1547 dbg("%s", __func__); 1545 dbg("%s", __func__);
1548 1546
1549 usb_kill_urb (port->interrupt_in_urb); 1547 usb_kill_urb(port->interrupt_in_urb);
1550 del_timer_sync(&garmin_data_p->timer); 1548 del_timer_sync(&garmin_data_p->timer);
1551 kfree (garmin_data_p); 1549 kfree(garmin_data_p);
1552 usb_set_serial_port_data(port, NULL); 1550 usb_set_serial_port_data(port, NULL);
1553} 1551}
1554 1552
@@ -1578,7 +1576,7 @@ static struct usb_serial_driver garmin_device = {
1578 1576
1579 1577
1580 1578
1581static int __init garmin_init (void) 1579static int __init garmin_init(void)
1582{ 1580{
1583 int retval; 1581 int retval;
1584 1582
@@ -1598,10 +1596,10 @@ failed_garmin_register:
1598} 1596}
1599 1597
1600 1598
1601static void __exit garmin_exit (void) 1599static void __exit garmin_exit(void)
1602{ 1600{
1603 usb_deregister (&garmin_driver); 1601 usb_deregister(&garmin_driver);
1604 usb_serial_deregister (&garmin_device); 1602 usb_serial_deregister(&garmin_device);
1605} 1603}
1606 1604
1607 1605
@@ -1610,8 +1608,8 @@ static void __exit garmin_exit (void)
1610module_init(garmin_init); 1608module_init(garmin_init);
1611module_exit(garmin_exit); 1609module_exit(garmin_exit);
1612 1610
1613MODULE_AUTHOR( DRIVER_AUTHOR ); 1611MODULE_AUTHOR(DRIVER_AUTHOR);
1614MODULE_DESCRIPTION( DRIVER_DESC ); 1612MODULE_DESCRIPTION(DRIVER_DESC);
1615MODULE_LICENSE("GPL"); 1613MODULE_LICENSE("GPL");
1616 1614
1617module_param(debug, bool, S_IWUSR | S_IRUGO); 1615module_param(debug, bool, S_IWUSR | S_IRUGO);