Linux 4.2.1
[linux/fpc-iii.git] / drivers / usb / serial / garmin_gps.c
blobdb591d19d416d92913b1be1a66b697dab8e5a56e
1 /*
2 * Garmin GPS driver
4 * Copyright (C) 2006-2011 Hermann Kneissel herkne@gmx.de
6 * The latest version of the driver can be found at
7 * http://sourceforge.net/projects/garmin-gps/
9 * This driver has been derived from v2.1 of the visor driver.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
26 #include <linux/kernel.h>
27 #include <linux/errno.h>
28 #include <linux/slab.h>
29 #include <linux/timer.h>
30 #include <linux/tty.h>
31 #include <linux/tty_driver.h>
32 #include <linux/tty_flip.h>
33 #include <linux/module.h>
34 #include <linux/spinlock.h>
35 #include <linux/uaccess.h>
36 #include <linux/atomic.h>
37 #include <linux/usb.h>
38 #include <linux/usb/serial.h>
40 /* the mode to be set when the port ist opened */
41 static int initial_mode = 1;
43 #define GARMIN_VENDOR_ID 0x091E
46 * Version Information
49 #define VERSION_MAJOR 0
50 #define VERSION_MINOR 36
52 #define _STR(s) #s
53 #define _DRIVER_VERSION(a, b) "v" _STR(a) "." _STR(b)
54 #define DRIVER_VERSION _DRIVER_VERSION(VERSION_MAJOR, VERSION_MINOR)
55 #define DRIVER_AUTHOR "hermann kneissel"
56 #define DRIVER_DESC "garmin gps driver"
58 /* error codes returned by the driver */
59 #define EINVPKT 1000 /* invalid packet structure */
62 /* size of the header of a packet using the usb protocol */
63 #define GARMIN_PKTHDR_LENGTH 12
65 /* max. possible size of a packet using the serial protocol */
66 #define MAX_SERIAL_PKT_SIZ (3 + 255 + 3)
68 /* max. possible size of a packet with worst case stuffing */
69 #define MAX_SERIAL_PKT_SIZ_STUFFED (MAX_SERIAL_PKT_SIZ + 256)
71 /* size of a buffer able to hold a complete (no stuffing) packet
72 * (the document protocol does not contain packets with a larger
73 * size, but in theory a packet may be 64k+12 bytes - if in
74 * later protocol versions larger packet sizes occur, this value
75 * should be increased accordingly, so the input buffer is always
76 * large enough the store a complete packet inclusive header) */
77 #define GPS_IN_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ)
79 /* size of a buffer able to hold a complete (incl. stuffing) packet */
80 #define GPS_OUT_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ_STUFFED)
82 /* where to place the packet id of a serial packet, so we can
83 * prepend the usb-packet header without the need to move the
84 * packets data */
85 #define GSP_INITIAL_OFFSET (GARMIN_PKTHDR_LENGTH-2)
87 /* max. size of incoming private packets (header+1 param) */
88 #define PRIVPKTSIZ (GARMIN_PKTHDR_LENGTH+4)
90 #define GARMIN_LAYERID_TRANSPORT 0
91 #define GARMIN_LAYERID_APPL 20
92 /* our own layer-id to use for some control mechanisms */
93 #define GARMIN_LAYERID_PRIVATE 0x01106E4B
95 #define GARMIN_PKTID_PVT_DATA 51
96 #define GARMIN_PKTID_L001_COMMAND_DATA 10
98 #define CMND_ABORT_TRANSFER 0
100 /* packet ids used in private layer */
101 #define PRIV_PKTID_SET_DEBUG 1
102 #define PRIV_PKTID_SET_MODE 2
103 #define PRIV_PKTID_INFO_REQ 3
104 #define PRIV_PKTID_INFO_RESP 4
105 #define PRIV_PKTID_RESET_REQ 5
106 #define PRIV_PKTID_SET_DEF_MODE 6
109 #define ETX 0x03
110 #define DLE 0x10
111 #define ACK 0x06
112 #define NAK 0x15
114 /* structure used to queue incoming packets */
115 struct garmin_packet {
116 struct list_head list;
117 int seq;
118 /* the real size of the data array, always > 0 */
119 int size;
120 __u8 data[1];
123 /* structure used to keep the current state of the driver */
124 struct garmin_data {
125 __u8 state;
126 __u16 flags;
127 __u8 mode;
128 __u8 count;
129 __u8 pkt_id;
130 __u32 serial_num;
131 struct timer_list timer;
132 struct usb_serial_port *port;
133 int seq_counter;
134 int insize;
135 int outsize;
136 __u8 inbuffer [GPS_IN_BUFSIZ]; /* tty -> usb */
137 __u8 outbuffer[GPS_OUT_BUFSIZ]; /* usb -> tty */
138 __u8 privpkt[4*6];
139 spinlock_t lock;
140 struct list_head pktlist;
144 #define STATE_NEW 0
145 #define STATE_INITIAL_DELAY 1
146 #define STATE_TIMEOUT 2
147 #define STATE_SESSION_REQ1 3
148 #define STATE_SESSION_REQ2 4
149 #define STATE_ACTIVE 5
151 #define STATE_RESET 8
152 #define STATE_DISCONNECTED 9
153 #define STATE_WAIT_TTY_ACK 10
154 #define STATE_GSP_WAIT_DATA 11
156 #define MODE_NATIVE 0
157 #define MODE_GARMIN_SERIAL 1
159 /* Flags used in garmin_data.flags: */
160 #define FLAGS_SESSION_REPLY_MASK 0x00C0
161 #define FLAGS_SESSION_REPLY1_SEEN 0x0080
162 #define FLAGS_SESSION_REPLY2_SEEN 0x0040
163 #define FLAGS_BULK_IN_ACTIVE 0x0020
164 #define FLAGS_BULK_IN_RESTART 0x0010
165 #define FLAGS_THROTTLED 0x0008
166 #define APP_REQ_SEEN 0x0004
167 #define APP_RESP_SEEN 0x0002
168 #define CLEAR_HALT_REQUIRED 0x0001
170 #define FLAGS_QUEUING 0x0100
171 #define FLAGS_DROP_DATA 0x0800
173 #define FLAGS_GSP_SKIP 0x1000
174 #define FLAGS_GSP_DLESEEN 0x2000
181 /* function prototypes */
182 static int gsp_next_packet(struct garmin_data *garmin_data_p);
183 static int garmin_write_bulk(struct usb_serial_port *port,
184 const unsigned char *buf, int count,
185 int dismiss_ack);
187 /* some special packets to be send or received */
188 static unsigned char const GARMIN_START_SESSION_REQ[]
189 = { 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0 };
190 static unsigned char const GARMIN_START_SESSION_REPLY[]
191 = { 0, 0, 0, 0, 6, 0, 0, 0, 4, 0, 0, 0 };
192 static unsigned char const GARMIN_BULK_IN_AVAIL_REPLY[]
193 = { 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0 };
194 static unsigned char const GARMIN_APP_LAYER_REPLY[]
195 = { 0x14, 0, 0, 0 };
196 static unsigned char const GARMIN_START_PVT_REQ[]
197 = { 20, 0, 0, 0, 10, 0, 0, 0, 2, 0, 0, 0, 49, 0 };
198 static unsigned char const GARMIN_STOP_PVT_REQ[]
199 = { 20, 0, 0, 0, 10, 0, 0, 0, 2, 0, 0, 0, 50, 0 };
200 static unsigned char const GARMIN_STOP_TRANSFER_REQ[]
201 = { 20, 0, 0, 0, 10, 0, 0, 0, 2, 0, 0, 0, 0, 0 };
202 static unsigned char const GARMIN_STOP_TRANSFER_REQ_V2[]
203 = { 20, 0, 0, 0, 10, 0, 0, 0, 1, 0, 0, 0, 0 };
204 static unsigned char const PRIVATE_REQ[]
205 = { 0x4B, 0x6E, 0x10, 0x01, 0xFF, 0, 0, 0, 0xFF, 0, 0, 0 };
209 static const struct usb_device_id id_table[] = {
210 /* the same device id seems to be used by all
211 usb enabled GPS devices */
212 { USB_DEVICE(GARMIN_VENDOR_ID, 3) },
213 { } /* Terminating entry */
215 MODULE_DEVICE_TABLE(usb, id_table);
218 static inline int getLayerId(const __u8 *usbPacket)
220 return __le32_to_cpup((__le32 *)(usbPacket));
223 static inline int getPacketId(const __u8 *usbPacket)
225 return __le32_to_cpup((__le32 *)(usbPacket+4));
228 static inline int getDataLength(const __u8 *usbPacket)
230 return __le32_to_cpup((__le32 *)(usbPacket+8));
235 * check if the usb-packet in buf contains an abort-transfer command.
236 * (if yes, all queued data will be dropped)
238 static inline int isAbortTrfCmnd(const unsigned char *buf)
240 if (0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ,
241 sizeof(GARMIN_STOP_TRANSFER_REQ)) ||
242 0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ_V2,
243 sizeof(GARMIN_STOP_TRANSFER_REQ_V2)))
244 return 1;
245 else
246 return 0;
251 static void send_to_tty(struct usb_serial_port *port,
252 char *data, unsigned int actual_length)
254 if (actual_length) {
255 usb_serial_debug_data(&port->dev, __func__, actual_length, data);
256 tty_insert_flip_string(&port->port, data, actual_length);
257 tty_flip_buffer_push(&port->port);
262 /******************************************************************************
263 * packet queue handling
264 ******************************************************************************/
267 * queue a received (usb-)packet for later processing
269 static int pkt_add(struct garmin_data *garmin_data_p,
270 unsigned char *data, unsigned int data_length)
272 int state = 0;
273 int result = 0;
274 unsigned long flags;
275 struct garmin_packet *pkt;
277 /* process only packets containing data ... */
278 if (data_length) {
279 pkt = kmalloc(sizeof(struct garmin_packet)+data_length,
280 GFP_ATOMIC);
281 if (!pkt)
282 return 0;
284 pkt->size = data_length;
285 memcpy(pkt->data, data, data_length);
287 spin_lock_irqsave(&garmin_data_p->lock, flags);
288 garmin_data_p->flags |= FLAGS_QUEUING;
289 result = list_empty(&garmin_data_p->pktlist);
290 pkt->seq = garmin_data_p->seq_counter++;
291 list_add_tail(&pkt->list, &garmin_data_p->pktlist);
292 state = garmin_data_p->state;
293 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
295 dev_dbg(&garmin_data_p->port->dev,
296 "%s - added: pkt: %d - %d bytes\n", __func__,
297 pkt->seq, data_length);
299 /* in serial mode, if someone is waiting for data from
300 the device, convert and send the next packet to tty. */
301 if (result && (state == STATE_GSP_WAIT_DATA))
302 gsp_next_packet(garmin_data_p);
304 return result;
308 /* get the next pending packet */
309 static struct garmin_packet *pkt_pop(struct garmin_data *garmin_data_p)
311 unsigned long flags;
312 struct garmin_packet *result = NULL;
314 spin_lock_irqsave(&garmin_data_p->lock, flags);
315 if (!list_empty(&garmin_data_p->pktlist)) {
316 result = (struct garmin_packet *)garmin_data_p->pktlist.next;
317 list_del(&result->list);
319 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
320 return result;
324 /* free up all queued data */
325 static void pkt_clear(struct garmin_data *garmin_data_p)
327 unsigned long flags;
328 struct garmin_packet *result = NULL;
330 spin_lock_irqsave(&garmin_data_p->lock, flags);
331 while (!list_empty(&garmin_data_p->pktlist)) {
332 result = (struct garmin_packet *)garmin_data_p->pktlist.next;
333 list_del(&result->list);
334 kfree(result);
336 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
340 /******************************************************************************
341 * garmin serial protocol handling handling
342 ******************************************************************************/
344 /* send an ack packet back to the tty */
345 static int gsp_send_ack(struct garmin_data *garmin_data_p, __u8 pkt_id)
347 __u8 pkt[10];
348 __u8 cksum = 0;
349 __u8 *ptr = pkt;
350 unsigned l = 0;
352 dev_dbg(&garmin_data_p->port->dev, "%s - pkt-id: 0x%X.\n", __func__,
353 0xFF & pkt_id);
355 *ptr++ = DLE;
356 *ptr++ = ACK;
357 cksum += ACK;
359 *ptr++ = 2;
360 cksum += 2;
362 *ptr++ = pkt_id;
363 cksum += pkt_id;
365 if (pkt_id == DLE)
366 *ptr++ = DLE;
368 *ptr++ = 0;
369 *ptr++ = 0xFF & (-cksum);
370 *ptr++ = DLE;
371 *ptr++ = ETX;
373 l = ptr-pkt;
375 send_to_tty(garmin_data_p->port, pkt, l);
376 return 0;
382 * called for a complete packet received from tty layer
384 * the complete packet (pktid ... cksum) is in garmin_data_p->inbuf starting
385 * at GSP_INITIAL_OFFSET.
387 * count - number of bytes in the input buffer including space reserved for
388 * the usb header: GSP_INITIAL_OFFSET + number of bytes in packet
389 * (including pkt-id, data-length a. cksum)
391 static int gsp_rec_packet(struct garmin_data *garmin_data_p, int count)
393 struct device *dev = &garmin_data_p->port->dev;
394 unsigned long flags;
395 const __u8 *recpkt = garmin_data_p->inbuffer+GSP_INITIAL_OFFSET;
396 __le32 *usbdata = (__le32 *) garmin_data_p->inbuffer;
397 int cksum = 0;
398 int n = 0;
399 int pktid = recpkt[0];
400 int size = recpkt[1];
402 usb_serial_debug_data(&garmin_data_p->port->dev, __func__,
403 count-GSP_INITIAL_OFFSET, recpkt);
405 if (size != (count-GSP_INITIAL_OFFSET-3)) {
406 dev_dbg(dev, "%s - invalid size, expected %d bytes, got %d\n",
407 __func__, size, (count-GSP_INITIAL_OFFSET-3));
408 return -EINVPKT;
411 cksum += *recpkt++;
412 cksum += *recpkt++;
414 /* sanity check, remove after test ... */
415 if ((__u8 *)&(usbdata[3]) != recpkt) {
416 dev_dbg(dev, "%s - ptr mismatch %p - %p\n", __func__,
417 &(usbdata[4]), recpkt);
418 return -EINVPKT;
421 while (n < size) {
422 cksum += *recpkt++;
423 n++;
426 if ((0xff & (cksum + *recpkt)) != 0) {
427 dev_dbg(dev, "%s - invalid checksum, expected %02x, got %02x\n",
428 __func__, 0xff & -cksum, 0xff & *recpkt);
429 return -EINVPKT;
432 usbdata[0] = __cpu_to_le32(GARMIN_LAYERID_APPL);
433 usbdata[1] = __cpu_to_le32(pktid);
434 usbdata[2] = __cpu_to_le32(size);
436 garmin_write_bulk(garmin_data_p->port, garmin_data_p->inbuffer,
437 GARMIN_PKTHDR_LENGTH+size, 0);
439 /* if this was an abort-transfer command, flush all
440 queued data. */
441 if (isAbortTrfCmnd(garmin_data_p->inbuffer)) {
442 spin_lock_irqsave(&garmin_data_p->lock, flags);
443 garmin_data_p->flags |= FLAGS_DROP_DATA;
444 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
445 pkt_clear(garmin_data_p);
448 return count;
454 * Called for data received from tty
456 * buf contains the data read, it may span more than one packet or even
457 * incomplete packets
459 * input record should be a serial-record, but it may not be complete.
460 * Copy it into our local buffer, until an etx is seen (or an error
461 * occurs).
462 * Once the record is complete, convert into a usb packet and send it
463 * to the bulk pipe, send an ack back to the tty.
465 * If the input is an ack, just send the last queued packet to the
466 * tty layer.
468 * if the input is an abort command, drop all queued data.
471 static int gsp_receive(struct garmin_data *garmin_data_p,
472 const unsigned char *buf, int count)
474 struct device *dev = &garmin_data_p->port->dev;
475 unsigned long flags;
476 int offs = 0;
477 int ack_or_nak_seen = 0;
478 __u8 *dest;
479 int size;
480 /* dleSeen: set if last byte read was a DLE */
481 int dleSeen;
482 /* skip: if set, skip incoming data until possible start of
483 * new packet
485 int skip;
486 __u8 data;
488 spin_lock_irqsave(&garmin_data_p->lock, flags);
489 dest = garmin_data_p->inbuffer;
490 size = garmin_data_p->insize;
491 dleSeen = garmin_data_p->flags & FLAGS_GSP_DLESEEN;
492 skip = garmin_data_p->flags & FLAGS_GSP_SKIP;
493 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
495 /* dev_dbg(dev, "%s - dle=%d skip=%d size=%d count=%d\n",
496 __func__, dleSeen, skip, size, count); */
498 if (size == 0)
499 size = GSP_INITIAL_OFFSET;
501 while (offs < count) {
503 data = *(buf+offs);
504 offs++;
506 if (data == DLE) {
507 if (skip) { /* start of a new pkt */
508 skip = 0;
509 size = GSP_INITIAL_OFFSET;
510 dleSeen = 1;
511 } else if (dleSeen) {
512 dest[size++] = data;
513 dleSeen = 0;
514 } else {
515 dleSeen = 1;
517 } else if (data == ETX) {
518 if (dleSeen) {
519 /* packet complete */
521 data = dest[GSP_INITIAL_OFFSET];
523 if (data == ACK) {
524 ack_or_nak_seen = ACK;
525 dev_dbg(dev, "ACK packet complete.\n");
526 } else if (data == NAK) {
527 ack_or_nak_seen = NAK;
528 dev_dbg(dev, "NAK packet complete.\n");
529 } else {
530 dev_dbg(dev, "packet complete - id=0x%X.\n",
531 0xFF & data);
532 gsp_rec_packet(garmin_data_p, size);
535 skip = 1;
536 size = GSP_INITIAL_OFFSET;
537 dleSeen = 0;
538 } else {
539 dest[size++] = data;
541 } else if (!skip) {
543 if (dleSeen) {
544 size = GSP_INITIAL_OFFSET;
545 dleSeen = 0;
548 dest[size++] = data;
551 if (size >= GPS_IN_BUFSIZ) {
552 dev_dbg(dev, "%s - packet too large.\n", __func__);
553 skip = 1;
554 size = GSP_INITIAL_OFFSET;
555 dleSeen = 0;
559 spin_lock_irqsave(&garmin_data_p->lock, flags);
561 garmin_data_p->insize = size;
563 /* copy flags back to structure */
564 if (skip)
565 garmin_data_p->flags |= FLAGS_GSP_SKIP;
566 else
567 garmin_data_p->flags &= ~FLAGS_GSP_SKIP;
569 if (dleSeen)
570 garmin_data_p->flags |= FLAGS_GSP_DLESEEN;
571 else
572 garmin_data_p->flags &= ~FLAGS_GSP_DLESEEN;
574 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
576 if (ack_or_nak_seen) {
577 if (gsp_next_packet(garmin_data_p) > 0)
578 garmin_data_p->state = STATE_ACTIVE;
579 else
580 garmin_data_p->state = STATE_GSP_WAIT_DATA;
582 return count;
588 * Sends a usb packet to the tty
590 * Assumes, that all packages and at an usb-packet boundary.
592 * return <0 on error, 0 if packet is incomplete or > 0 if packet was sent
594 static int gsp_send(struct garmin_data *garmin_data_p,
595 const unsigned char *buf, int count)
597 struct device *dev = &garmin_data_p->port->dev;
598 const unsigned char *src;
599 unsigned char *dst;
600 int pktid = 0;
601 int datalen = 0;
602 int cksum = 0;
603 int i = 0;
604 int k;
606 dev_dbg(dev, "%s - state %d - %d bytes.\n", __func__,
607 garmin_data_p->state, count);
609 k = garmin_data_p->outsize;
610 if ((k+count) > GPS_OUT_BUFSIZ) {
611 dev_dbg(dev, "packet too large\n");
612 garmin_data_p->outsize = 0;
613 return -4;
616 memcpy(garmin_data_p->outbuffer+k, buf, count);
617 k += count;
618 garmin_data_p->outsize = k;
620 if (k >= GARMIN_PKTHDR_LENGTH) {
621 pktid = getPacketId(garmin_data_p->outbuffer);
622 datalen = getDataLength(garmin_data_p->outbuffer);
623 i = GARMIN_PKTHDR_LENGTH + datalen;
624 if (k < i)
625 return 0;
626 } else {
627 return 0;
630 dev_dbg(dev, "%s - %d bytes in buffer, %d bytes in pkt.\n", __func__, k, i);
632 /* garmin_data_p->outbuffer now contains a complete packet */
634 usb_serial_debug_data(&garmin_data_p->port->dev, __func__, k,
635 garmin_data_p->outbuffer);
637 garmin_data_p->outsize = 0;
639 if (GARMIN_LAYERID_APPL != getLayerId(garmin_data_p->outbuffer)) {
640 dev_dbg(dev, "not an application packet (%d)\n",
641 getLayerId(garmin_data_p->outbuffer));
642 return -1;
645 if (pktid > 255) {
646 dev_dbg(dev, "packet-id %d too large\n", pktid);
647 return -2;
650 if (datalen > 255) {
651 dev_dbg(dev, "packet-size %d too large\n", datalen);
652 return -3;
655 /* the serial protocol should be able to handle this packet */
657 k = 0;
658 src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH;
659 for (i = 0; i < datalen; i++) {
660 if (*src++ == DLE)
661 k++;
664 src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH;
665 if (k > (GARMIN_PKTHDR_LENGTH-2)) {
666 /* can't add stuffing DLEs in place, move data to end
667 of buffer ... */
668 dst = garmin_data_p->outbuffer+GPS_OUT_BUFSIZ-datalen;
669 memcpy(dst, src, datalen);
670 src = dst;
673 dst = garmin_data_p->outbuffer;
675 *dst++ = DLE;
676 *dst++ = pktid;
677 cksum += pktid;
678 *dst++ = datalen;
679 cksum += datalen;
680 if (datalen == DLE)
681 *dst++ = DLE;
683 for (i = 0; i < datalen; i++) {
684 __u8 c = *src++;
685 *dst++ = c;
686 cksum += c;
687 if (c == DLE)
688 *dst++ = DLE;
691 cksum = 0xFF & -cksum;
692 *dst++ = cksum;
693 if (cksum == DLE)
694 *dst++ = DLE;
695 *dst++ = DLE;
696 *dst++ = ETX;
698 i = dst-garmin_data_p->outbuffer;
700 send_to_tty(garmin_data_p->port, garmin_data_p->outbuffer, i);
702 garmin_data_p->pkt_id = pktid;
703 garmin_data_p->state = STATE_WAIT_TTY_ACK;
705 return i;
710 * Process the next pending data packet - if there is one
712 static int gsp_next_packet(struct garmin_data *garmin_data_p)
714 int result = 0;
715 struct garmin_packet *pkt = NULL;
717 while ((pkt = pkt_pop(garmin_data_p)) != NULL) {
718 dev_dbg(&garmin_data_p->port->dev, "%s - next pkt: %d\n", __func__, pkt->seq);
719 result = gsp_send(garmin_data_p, pkt->data, pkt->size);
720 if (result > 0) {
721 kfree(pkt);
722 return result;
724 kfree(pkt);
726 return result;
731 /******************************************************************************
732 * garmin native mode
733 ******************************************************************************/
737 * Called for data received from tty
739 * The input data is expected to be in garmin usb-packet format.
741 * buf contains the data read, it may span more than one packet
742 * or even incomplete packets
744 static int nat_receive(struct garmin_data *garmin_data_p,
745 const unsigned char *buf, int count)
747 unsigned long flags;
748 __u8 *dest;
749 int offs = 0;
750 int result = count;
751 int len;
753 while (offs < count) {
754 /* if buffer contains header, copy rest of data */
755 if (garmin_data_p->insize >= GARMIN_PKTHDR_LENGTH)
756 len = GARMIN_PKTHDR_LENGTH
757 +getDataLength(garmin_data_p->inbuffer);
758 else
759 len = GARMIN_PKTHDR_LENGTH;
761 if (len >= GPS_IN_BUFSIZ) {
762 /* seems to be an invalid packet, ignore rest
763 of input */
764 dev_dbg(&garmin_data_p->port->dev,
765 "%s - packet size too large: %d\n",
766 __func__, len);
767 garmin_data_p->insize = 0;
768 count = 0;
769 result = -EINVPKT;
770 } else {
771 len -= garmin_data_p->insize;
772 if (len > (count-offs))
773 len = (count-offs);
774 if (len > 0) {
775 dest = garmin_data_p->inbuffer
776 + garmin_data_p->insize;
777 memcpy(dest, buf+offs, len);
778 garmin_data_p->insize += len;
779 offs += len;
783 /* do we have a complete packet ? */
784 if (garmin_data_p->insize >= GARMIN_PKTHDR_LENGTH) {
785 len = GARMIN_PKTHDR_LENGTH+
786 getDataLength(garmin_data_p->inbuffer);
787 if (garmin_data_p->insize >= len) {
788 garmin_write_bulk(garmin_data_p->port,
789 garmin_data_p->inbuffer,
790 len, 0);
791 garmin_data_p->insize = 0;
793 /* if this was an abort-transfer command,
794 flush all queued data. */
795 if (isAbortTrfCmnd(garmin_data_p->inbuffer)) {
796 spin_lock_irqsave(&garmin_data_p->lock,
797 flags);
798 garmin_data_p->flags |= FLAGS_DROP_DATA;
799 spin_unlock_irqrestore(
800 &garmin_data_p->lock, flags);
801 pkt_clear(garmin_data_p);
806 return result;
810 /******************************************************************************
811 * private packets
812 ******************************************************************************/
814 static void priv_status_resp(struct usb_serial_port *port)
816 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
817 __le32 *pkt = (__le32 *)garmin_data_p->privpkt;
819 pkt[0] = __cpu_to_le32(GARMIN_LAYERID_PRIVATE);
820 pkt[1] = __cpu_to_le32(PRIV_PKTID_INFO_RESP);
821 pkt[2] = __cpu_to_le32(12);
822 pkt[3] = __cpu_to_le32(VERSION_MAJOR << 16 | VERSION_MINOR);
823 pkt[4] = __cpu_to_le32(garmin_data_p->mode);
824 pkt[5] = __cpu_to_le32(garmin_data_p->serial_num);
826 send_to_tty(port, (__u8 *)pkt, 6 * 4);
830 /******************************************************************************
831 * Garmin specific driver functions
832 ******************************************************************************/
834 static int process_resetdev_request(struct usb_serial_port *port)
836 unsigned long flags;
837 int status;
838 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
840 spin_lock_irqsave(&garmin_data_p->lock, flags);
841 garmin_data_p->flags &= ~(CLEAR_HALT_REQUIRED);
842 garmin_data_p->state = STATE_RESET;
843 garmin_data_p->serial_num = 0;
844 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
846 usb_kill_urb(port->interrupt_in_urb);
847 dev_dbg(&port->dev, "%s - usb_reset_device\n", __func__);
848 status = usb_reset_device(port->serial->dev);
849 if (status)
850 dev_dbg(&port->dev, "%s - usb_reset_device failed: %d\n",
851 __func__, status);
852 return status;
858 * clear all cached data
860 static int garmin_clear(struct garmin_data *garmin_data_p)
862 unsigned long flags;
863 int status = 0;
865 /* flush all queued data */
866 pkt_clear(garmin_data_p);
868 spin_lock_irqsave(&garmin_data_p->lock, flags);
869 garmin_data_p->insize = 0;
870 garmin_data_p->outsize = 0;
871 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
873 return status;
877 static int garmin_init_session(struct usb_serial_port *port)
879 struct usb_serial *serial = port->serial;
880 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
881 int status = 0;
882 int i = 0;
884 if (status == 0) {
885 usb_kill_urb(port->interrupt_in_urb);
887 dev_dbg(&serial->dev->dev, "%s - adding interrupt input\n", __func__);
888 status = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
889 if (status)
890 dev_err(&serial->dev->dev,
891 "%s - failed submitting interrupt urb, error %d\n",
892 __func__, status);
896 * using the initialization method from gpsbabel. See comments in
897 * gpsbabel/jeeps/gpslibusb.c gusb_reset_toggles()
899 if (status == 0) {
900 dev_dbg(&serial->dev->dev, "%s - starting session ...\n", __func__);
901 garmin_data_p->state = STATE_ACTIVE;
903 for (i = 0; i < 3; i++) {
904 status = garmin_write_bulk(port,
905 GARMIN_START_SESSION_REQ,
906 sizeof(GARMIN_START_SESSION_REQ), 0);
908 if (status < 0)
909 break;
912 if (status > 0)
913 status = 0;
916 return status;
921 static int garmin_open(struct tty_struct *tty, struct usb_serial_port *port)
923 unsigned long flags;
924 int status = 0;
925 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
927 spin_lock_irqsave(&garmin_data_p->lock, flags);
928 garmin_data_p->mode = initial_mode;
929 garmin_data_p->count = 0;
930 garmin_data_p->flags &= FLAGS_SESSION_REPLY1_SEEN;
931 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
933 /* shutdown any bulk reads that might be going on */
934 usb_kill_urb(port->write_urb);
935 usb_kill_urb(port->read_urb);
937 if (garmin_data_p->state == STATE_RESET)
938 status = garmin_init_session(port);
940 garmin_data_p->state = STATE_ACTIVE;
941 return status;
945 static void garmin_close(struct usb_serial_port *port)
947 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
949 dev_dbg(&port->dev, "%s - mode=%d state=%d flags=0x%X\n",
950 __func__, garmin_data_p->mode, garmin_data_p->state,
951 garmin_data_p->flags);
953 garmin_clear(garmin_data_p);
955 /* shutdown our urbs */
956 usb_kill_urb(port->read_urb);
957 usb_kill_urb(port->write_urb);
959 /* keep reset state so we know that we must start a new session */
960 if (garmin_data_p->state != STATE_RESET)
961 garmin_data_p->state = STATE_DISCONNECTED;
965 static void garmin_write_bulk_callback(struct urb *urb)
967 struct usb_serial_port *port = urb->context;
969 if (port) {
970 struct garmin_data *garmin_data_p =
971 usb_get_serial_port_data(port);
973 if (GARMIN_LAYERID_APPL == getLayerId(urb->transfer_buffer)) {
975 if (garmin_data_p->mode == MODE_GARMIN_SERIAL) {
976 gsp_send_ack(garmin_data_p,
977 ((__u8 *)urb->transfer_buffer)[4]);
980 usb_serial_port_softint(port);
983 /* Ignore errors that resulted from garmin_write_bulk with
984 dismiss_ack = 1 */
986 /* free up the transfer buffer, as usb_free_urb() does not do this */
987 kfree(urb->transfer_buffer);
991 static int garmin_write_bulk(struct usb_serial_port *port,
992 const unsigned char *buf, int count,
993 int dismiss_ack)
995 unsigned long flags;
996 struct usb_serial *serial = port->serial;
997 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
998 struct urb *urb;
999 unsigned char *buffer;
1000 int status;
1002 spin_lock_irqsave(&garmin_data_p->lock, flags);
1003 garmin_data_p->flags &= ~FLAGS_DROP_DATA;
1004 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1006 buffer = kmalloc(count, GFP_ATOMIC);
1007 if (!buffer)
1008 return -ENOMEM;
1010 urb = usb_alloc_urb(0, GFP_ATOMIC);
1011 if (!urb) {
1012 kfree(buffer);
1013 return -ENOMEM;
1016 memcpy(buffer, buf, count);
1018 usb_serial_debug_data(&port->dev, __func__, count, buffer);
1020 usb_fill_bulk_urb(urb, serial->dev,
1021 usb_sndbulkpipe(serial->dev,
1022 port->bulk_out_endpointAddress),
1023 buffer, count,
1024 garmin_write_bulk_callback,
1025 dismiss_ack ? NULL : port);
1026 urb->transfer_flags |= URB_ZERO_PACKET;
1028 if (GARMIN_LAYERID_APPL == getLayerId(buffer)) {
1030 spin_lock_irqsave(&garmin_data_p->lock, flags);
1031 garmin_data_p->flags |= APP_REQ_SEEN;
1032 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1034 if (garmin_data_p->mode == MODE_GARMIN_SERIAL) {
1035 pkt_clear(garmin_data_p);
1036 garmin_data_p->state = STATE_GSP_WAIT_DATA;
1040 /* send it down the pipe */
1041 status = usb_submit_urb(urb, GFP_ATOMIC);
1042 if (status) {
1043 dev_err(&port->dev,
1044 "%s - usb_submit_urb(write bulk) failed with status = %d\n",
1045 __func__, status);
1046 count = status;
1049 /* we are done with this urb, so let the host driver
1050 * really free it when it is finished with it */
1051 usb_free_urb(urb);
1053 return count;
1056 static int garmin_write(struct tty_struct *tty, struct usb_serial_port *port,
1057 const unsigned char *buf, int count)
1059 struct device *dev = &port->dev;
1060 int pktid, pktsiz, len;
1061 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1062 __le32 *privpkt = (__le32 *)garmin_data_p->privpkt;
1064 usb_serial_debug_data(dev, __func__, count, buf);
1066 if (garmin_data_p->state == STATE_RESET)
1067 return -EIO;
1069 /* check for our private packets */
1070 if (count >= GARMIN_PKTHDR_LENGTH) {
1071 len = PRIVPKTSIZ;
1072 if (count < len)
1073 len = count;
1075 memcpy(garmin_data_p->privpkt, buf, len);
1077 pktsiz = getDataLength(garmin_data_p->privpkt);
1078 pktid = getPacketId(garmin_data_p->privpkt);
1080 if (count == (GARMIN_PKTHDR_LENGTH+pktsiz)
1081 && GARMIN_LAYERID_PRIVATE ==
1082 getLayerId(garmin_data_p->privpkt)) {
1084 dev_dbg(dev, "%s - processing private request %d\n",
1085 __func__, pktid);
1087 /* drop all unfinished transfers */
1088 garmin_clear(garmin_data_p);
1090 switch (pktid) {
1091 case PRIV_PKTID_SET_MODE:
1092 if (pktsiz != 4)
1093 return -EINVPKT;
1094 garmin_data_p->mode = __le32_to_cpu(privpkt[3]);
1095 dev_dbg(dev, "%s - mode set to %d\n",
1096 __func__, garmin_data_p->mode);
1097 break;
1099 case PRIV_PKTID_INFO_REQ:
1100 priv_status_resp(port);
1101 break;
1103 case PRIV_PKTID_RESET_REQ:
1104 process_resetdev_request(port);
1105 break;
1107 case PRIV_PKTID_SET_DEF_MODE:
1108 if (pktsiz != 4)
1109 return -EINVPKT;
1110 initial_mode = __le32_to_cpu(privpkt[3]);
1111 dev_dbg(dev, "%s - initial_mode set to %d\n",
1112 __func__,
1113 garmin_data_p->mode);
1114 break;
1116 return count;
1120 if (garmin_data_p->mode == MODE_GARMIN_SERIAL) {
1121 return gsp_receive(garmin_data_p, buf, count);
1122 } else { /* MODE_NATIVE */
1123 return nat_receive(garmin_data_p, buf, count);
1128 static int garmin_write_room(struct tty_struct *tty)
1130 struct usb_serial_port *port = tty->driver_data;
1132 * Report back the bytes currently available in the output buffer.
1134 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1135 return GPS_OUT_BUFSIZ-garmin_data_p->outsize;
1139 static void garmin_read_process(struct garmin_data *garmin_data_p,
1140 unsigned char *data, unsigned data_length,
1141 int bulk_data)
1143 unsigned long flags;
1145 if (garmin_data_p->flags & FLAGS_DROP_DATA) {
1146 /* abort-transfer cmd is active */
1147 dev_dbg(&garmin_data_p->port->dev, "%s - pkt dropped\n", __func__);
1148 } else if (garmin_data_p->state != STATE_DISCONNECTED &&
1149 garmin_data_p->state != STATE_RESET) {
1151 /* if throttling is active or postprecessing is required
1152 put the received data in the input queue, otherwise
1153 send it directly to the tty port */
1154 if (garmin_data_p->flags & FLAGS_QUEUING) {
1155 pkt_add(garmin_data_p, data, data_length);
1156 } else if (bulk_data ||
1157 getLayerId(data) == GARMIN_LAYERID_APPL) {
1159 spin_lock_irqsave(&garmin_data_p->lock, flags);
1160 garmin_data_p->flags |= APP_RESP_SEEN;
1161 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1163 if (garmin_data_p->mode == MODE_GARMIN_SERIAL) {
1164 pkt_add(garmin_data_p, data, data_length);
1165 } else {
1166 send_to_tty(garmin_data_p->port, data,
1167 data_length);
1170 /* ignore system layer packets ... */
1175 static void garmin_read_bulk_callback(struct urb *urb)
1177 unsigned long flags;
1178 struct usb_serial_port *port = urb->context;
1179 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1180 unsigned char *data = urb->transfer_buffer;
1181 int status = urb->status;
1182 int retval;
1184 if (status) {
1185 dev_dbg(&urb->dev->dev, "%s - nonzero read bulk status received: %d\n",
1186 __func__, status);
1187 return;
1190 usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data);
1192 garmin_read_process(garmin_data_p, data, urb->actual_length, 1);
1194 if (urb->actual_length == 0 &&
1195 0 != (garmin_data_p->flags & FLAGS_BULK_IN_RESTART)) {
1196 spin_lock_irqsave(&garmin_data_p->lock, flags);
1197 garmin_data_p->flags &= ~FLAGS_BULK_IN_RESTART;
1198 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1199 retval = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1200 if (retval)
1201 dev_err(&port->dev,
1202 "%s - failed resubmitting read urb, error %d\n",
1203 __func__, retval);
1204 } else if (urb->actual_length > 0) {
1205 /* Continue trying to read until nothing more is received */
1206 if (0 == (garmin_data_p->flags & FLAGS_THROTTLED)) {
1207 retval = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1208 if (retval)
1209 dev_err(&port->dev,
1210 "%s - failed resubmitting read urb, error %d\n",
1211 __func__, retval);
1213 } else {
1214 dev_dbg(&port->dev, "%s - end of bulk data\n", __func__);
1215 spin_lock_irqsave(&garmin_data_p->lock, flags);
1216 garmin_data_p->flags &= ~FLAGS_BULK_IN_ACTIVE;
1217 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1222 static void garmin_read_int_callback(struct urb *urb)
1224 unsigned long flags;
1225 int retval;
1226 struct usb_serial_port *port = urb->context;
1227 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1228 unsigned char *data = urb->transfer_buffer;
1229 int status = urb->status;
1231 switch (status) {
1232 case 0:
1233 /* success */
1234 break;
1235 case -ECONNRESET:
1236 case -ENOENT:
1237 case -ESHUTDOWN:
1238 /* this urb is terminated, clean up */
1239 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n",
1240 __func__, status);
1241 return;
1242 default:
1243 dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n",
1244 __func__, status);
1245 return;
1248 usb_serial_debug_data(&port->dev, __func__, urb->actual_length,
1249 urb->transfer_buffer);
1251 if (urb->actual_length == sizeof(GARMIN_BULK_IN_AVAIL_REPLY) &&
1252 0 == memcmp(data, GARMIN_BULK_IN_AVAIL_REPLY,
1253 sizeof(GARMIN_BULK_IN_AVAIL_REPLY))) {
1255 dev_dbg(&port->dev, "%s - bulk data available.\n", __func__);
1257 if (0 == (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) {
1259 /* bulk data available */
1260 retval = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1261 if (retval) {
1262 dev_err(&port->dev,
1263 "%s - failed submitting read urb, error %d\n",
1264 __func__, retval);
1265 } else {
1266 spin_lock_irqsave(&garmin_data_p->lock, flags);
1267 garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE;
1268 spin_unlock_irqrestore(&garmin_data_p->lock,
1269 flags);
1271 } else {
1272 /* bulk-in transfer still active */
1273 spin_lock_irqsave(&garmin_data_p->lock, flags);
1274 garmin_data_p->flags |= FLAGS_BULK_IN_RESTART;
1275 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1278 } else if (urb->actual_length == (4+sizeof(GARMIN_START_SESSION_REPLY))
1279 && 0 == memcmp(data, GARMIN_START_SESSION_REPLY,
1280 sizeof(GARMIN_START_SESSION_REPLY))) {
1282 spin_lock_irqsave(&garmin_data_p->lock, flags);
1283 garmin_data_p->flags |= FLAGS_SESSION_REPLY1_SEEN;
1284 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1286 /* save the serial number */
1287 garmin_data_p->serial_num = __le32_to_cpup(
1288 (__le32 *)(data+GARMIN_PKTHDR_LENGTH));
1290 dev_dbg(&port->dev, "%s - start-of-session reply seen - serial %u.\n",
1291 __func__, garmin_data_p->serial_num);
1294 garmin_read_process(garmin_data_p, data, urb->actual_length, 0);
1296 retval = usb_submit_urb(urb, GFP_ATOMIC);
1297 if (retval)
1298 dev_err(&urb->dev->dev,
1299 "%s - Error %d submitting interrupt urb\n",
1300 __func__, retval);
1305 * Sends the next queued packt to the tty port (garmin native mode only)
1306 * and then sets a timer to call itself again until all queued data
1307 * is sent.
1309 static int garmin_flush_queue(struct garmin_data *garmin_data_p)
1311 unsigned long flags;
1312 struct garmin_packet *pkt;
1314 if ((garmin_data_p->flags & FLAGS_THROTTLED) == 0) {
1315 pkt = pkt_pop(garmin_data_p);
1316 if (pkt != NULL) {
1317 send_to_tty(garmin_data_p->port, pkt->data, pkt->size);
1318 kfree(pkt);
1319 mod_timer(&garmin_data_p->timer, (1)+jiffies);
1321 } else {
1322 spin_lock_irqsave(&garmin_data_p->lock, flags);
1323 garmin_data_p->flags &= ~FLAGS_QUEUING;
1324 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1327 return 0;
1331 static void garmin_throttle(struct tty_struct *tty)
1333 struct usb_serial_port *port = tty->driver_data;
1334 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1336 /* set flag, data received will be put into a queue
1337 for later processing */
1338 spin_lock_irq(&garmin_data_p->lock);
1339 garmin_data_p->flags |= FLAGS_QUEUING|FLAGS_THROTTLED;
1340 spin_unlock_irq(&garmin_data_p->lock);
1344 static void garmin_unthrottle(struct tty_struct *tty)
1346 struct usb_serial_port *port = tty->driver_data;
1347 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1348 int status;
1350 spin_lock_irq(&garmin_data_p->lock);
1351 garmin_data_p->flags &= ~FLAGS_THROTTLED;
1352 spin_unlock_irq(&garmin_data_p->lock);
1354 /* in native mode send queued data to tty, in
1355 serial mode nothing needs to be done here */
1356 if (garmin_data_p->mode == MODE_NATIVE)
1357 garmin_flush_queue(garmin_data_p);
1359 if (0 != (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) {
1360 status = usb_submit_urb(port->read_urb, GFP_KERNEL);
1361 if (status)
1362 dev_err(&port->dev,
1363 "%s - failed resubmitting read urb, error %d\n",
1364 __func__, status);
1369 * The timer is currently only used to send queued packets to
1370 * the tty in cases where the protocol provides no own handshaking
1371 * to initiate the transfer.
1373 static void timeout_handler(unsigned long data)
1375 struct garmin_data *garmin_data_p = (struct garmin_data *) data;
1377 /* send the next queued packet to the tty port */
1378 if (garmin_data_p->mode == MODE_NATIVE)
1379 if (garmin_data_p->flags & FLAGS_QUEUING)
1380 garmin_flush_queue(garmin_data_p);
1385 static int garmin_port_probe(struct usb_serial_port *port)
1387 int status;
1388 struct garmin_data *garmin_data_p;
1390 garmin_data_p = kzalloc(sizeof(struct garmin_data), GFP_KERNEL);
1391 if (!garmin_data_p)
1392 return -ENOMEM;
1394 init_timer(&garmin_data_p->timer);
1395 spin_lock_init(&garmin_data_p->lock);
1396 INIT_LIST_HEAD(&garmin_data_p->pktlist);
1397 /* garmin_data_p->timer.expires = jiffies + session_timeout; */
1398 garmin_data_p->timer.data = (unsigned long)garmin_data_p;
1399 garmin_data_p->timer.function = timeout_handler;
1400 garmin_data_p->port = port;
1401 garmin_data_p->state = 0;
1402 garmin_data_p->flags = 0;
1403 garmin_data_p->count = 0;
1404 usb_set_serial_port_data(port, garmin_data_p);
1406 status = garmin_init_session(port);
1408 return status;
1412 static int garmin_port_remove(struct usb_serial_port *port)
1414 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1416 usb_kill_urb(port->interrupt_in_urb);
1417 del_timer_sync(&garmin_data_p->timer);
1418 kfree(garmin_data_p);
1419 return 0;
1423 /* All of the device info needed */
1424 static struct usb_serial_driver garmin_device = {
1425 .driver = {
1426 .owner = THIS_MODULE,
1427 .name = "garmin_gps",
1429 .description = "Garmin GPS usb/tty",
1430 .id_table = id_table,
1431 .num_ports = 1,
1432 .open = garmin_open,
1433 .close = garmin_close,
1434 .throttle = garmin_throttle,
1435 .unthrottle = garmin_unthrottle,
1436 .port_probe = garmin_port_probe,
1437 .port_remove = garmin_port_remove,
1438 .write = garmin_write,
1439 .write_room = garmin_write_room,
1440 .write_bulk_callback = garmin_write_bulk_callback,
1441 .read_bulk_callback = garmin_read_bulk_callback,
1442 .read_int_callback = garmin_read_int_callback,
1445 static struct usb_serial_driver * const serial_drivers[] = {
1446 &garmin_device, NULL
1449 module_usb_serial_driver(serial_drivers, id_table);
1451 MODULE_AUTHOR(DRIVER_AUTHOR);
1452 MODULE_DESCRIPTION(DRIVER_DESC);
1453 MODULE_LICENSE("GPL");
1455 module_param(initial_mode, int, S_IRUGO);
1456 MODULE_PARM_DESC(initial_mode, "Initial mode");