mmc: rtsx_pci: Enable MMC_CAP_ERASE to allow erase/discard/trim requests
[linux/fpc-iii.git] / drivers / usb / serial / garmin_gps.c
blob97cabf803c2fa91a134c957dba74c4f77b97c712
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 (memcmp(buf, GARMIN_STOP_TRANSFER_REQ,
241 sizeof(GARMIN_STOP_TRANSFER_REQ)) == 0 ||
242 memcmp(buf, GARMIN_STOP_TRANSFER_REQ_V2,
243 sizeof(GARMIN_STOP_TRANSFER_REQ_V2)) == 0)
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 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++ = (-cksum) & 0xFF;
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 (((cksum + *recpkt) & 0xff) != 0) {
427 dev_dbg(dev, "%s - invalid checksum, expected %02x, got %02x\n",
428 __func__, -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 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 (getLayerId(garmin_data_p->outbuffer) != GARMIN_LAYERID_APPL) {
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 = -cksum & 0xFF;
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;
864 /* flush all queued data */
865 pkt_clear(garmin_data_p);
867 spin_lock_irqsave(&garmin_data_p->lock, flags);
868 garmin_data_p->insize = 0;
869 garmin_data_p->outsize = 0;
870 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
872 return 0;
876 static int garmin_init_session(struct usb_serial_port *port)
878 struct usb_serial *serial = port->serial;
879 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
880 int status = 0;
881 int i = 0;
883 if (status == 0) {
884 usb_kill_urb(port->interrupt_in_urb);
886 dev_dbg(&serial->dev->dev, "%s - adding interrupt input\n", __func__);
887 status = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
888 if (status)
889 dev_err(&serial->dev->dev,
890 "%s - failed submitting interrupt urb, error %d\n",
891 __func__, status);
895 * using the initialization method from gpsbabel. See comments in
896 * gpsbabel/jeeps/gpslibusb.c gusb_reset_toggles()
898 if (status == 0) {
899 dev_dbg(&serial->dev->dev, "%s - starting session ...\n", __func__);
900 garmin_data_p->state = STATE_ACTIVE;
902 for (i = 0; i < 3; i++) {
903 status = garmin_write_bulk(port,
904 GARMIN_START_SESSION_REQ,
905 sizeof(GARMIN_START_SESSION_REQ), 0);
907 if (status < 0)
908 break;
911 if (status > 0)
912 status = 0;
915 return status;
920 static int garmin_open(struct tty_struct *tty, struct usb_serial_port *port)
922 unsigned long flags;
923 int status = 0;
924 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
926 spin_lock_irqsave(&garmin_data_p->lock, flags);
927 garmin_data_p->mode = initial_mode;
928 garmin_data_p->count = 0;
929 garmin_data_p->flags &= FLAGS_SESSION_REPLY1_SEEN;
930 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
932 /* shutdown any bulk reads that might be going on */
933 usb_kill_urb(port->write_urb);
934 usb_kill_urb(port->read_urb);
936 if (garmin_data_p->state == STATE_RESET)
937 status = garmin_init_session(port);
939 garmin_data_p->state = STATE_ACTIVE;
940 return status;
944 static void garmin_close(struct usb_serial_port *port)
946 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
948 dev_dbg(&port->dev, "%s - mode=%d state=%d flags=0x%X\n",
949 __func__, garmin_data_p->mode, garmin_data_p->state,
950 garmin_data_p->flags);
952 garmin_clear(garmin_data_p);
954 /* shutdown our urbs */
955 usb_kill_urb(port->read_urb);
956 usb_kill_urb(port->write_urb);
958 /* keep reset state so we know that we must start a new session */
959 if (garmin_data_p->state != STATE_RESET)
960 garmin_data_p->state = STATE_DISCONNECTED;
964 static void garmin_write_bulk_callback(struct urb *urb)
966 struct usb_serial_port *port = urb->context;
968 if (port) {
969 struct garmin_data *garmin_data_p =
970 usb_get_serial_port_data(port);
972 if (getLayerId(urb->transfer_buffer) == GARMIN_LAYERID_APPL) {
974 if (garmin_data_p->mode == MODE_GARMIN_SERIAL) {
975 gsp_send_ack(garmin_data_p,
976 ((__u8 *)urb->transfer_buffer)[4]);
979 usb_serial_port_softint(port);
982 /* Ignore errors that resulted from garmin_write_bulk with
983 dismiss_ack = 1 */
985 /* free up the transfer buffer, as usb_free_urb() does not do this */
986 kfree(urb->transfer_buffer);
990 static int garmin_write_bulk(struct usb_serial_port *port,
991 const unsigned char *buf, int count,
992 int dismiss_ack)
994 unsigned long flags;
995 struct usb_serial *serial = port->serial;
996 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
997 struct urb *urb;
998 unsigned char *buffer;
999 int status;
1001 spin_lock_irqsave(&garmin_data_p->lock, flags);
1002 garmin_data_p->flags &= ~FLAGS_DROP_DATA;
1003 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1005 buffer = kmalloc(count, GFP_ATOMIC);
1006 if (!buffer)
1007 return -ENOMEM;
1009 urb = usb_alloc_urb(0, GFP_ATOMIC);
1010 if (!urb) {
1011 kfree(buffer);
1012 return -ENOMEM;
1015 memcpy(buffer, buf, count);
1017 usb_serial_debug_data(&port->dev, __func__, count, buffer);
1019 usb_fill_bulk_urb(urb, serial->dev,
1020 usb_sndbulkpipe(serial->dev,
1021 port->bulk_out_endpointAddress),
1022 buffer, count,
1023 garmin_write_bulk_callback,
1024 dismiss_ack ? NULL : port);
1025 urb->transfer_flags |= URB_ZERO_PACKET;
1027 if (getLayerId(buffer) == GARMIN_LAYERID_APPL) {
1029 spin_lock_irqsave(&garmin_data_p->lock, flags);
1030 garmin_data_p->flags |= APP_REQ_SEEN;
1031 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1033 if (garmin_data_p->mode == MODE_GARMIN_SERIAL) {
1034 pkt_clear(garmin_data_p);
1035 garmin_data_p->state = STATE_GSP_WAIT_DATA;
1039 /* send it down the pipe */
1040 status = usb_submit_urb(urb, GFP_ATOMIC);
1041 if (status) {
1042 dev_err(&port->dev,
1043 "%s - usb_submit_urb(write bulk) failed with status = %d\n",
1044 __func__, status);
1045 count = status;
1048 /* we are done with this urb, so let the host driver
1049 * really free it when it is finished with it */
1050 usb_free_urb(urb);
1052 return count;
1055 static int garmin_write(struct tty_struct *tty, struct usb_serial_port *port,
1056 const unsigned char *buf, int count)
1058 struct device *dev = &port->dev;
1059 int pktid, pktsiz, len;
1060 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1061 __le32 *privpkt = (__le32 *)garmin_data_p->privpkt;
1063 usb_serial_debug_data(dev, __func__, count, buf);
1065 if (garmin_data_p->state == STATE_RESET)
1066 return -EIO;
1068 /* check for our private packets */
1069 if (count >= GARMIN_PKTHDR_LENGTH) {
1070 len = PRIVPKTSIZ;
1071 if (count < len)
1072 len = count;
1074 memcpy(garmin_data_p->privpkt, buf, len);
1076 pktsiz = getDataLength(garmin_data_p->privpkt);
1077 pktid = getPacketId(garmin_data_p->privpkt);
1079 if (count == (GARMIN_PKTHDR_LENGTH + pktsiz) &&
1080 getLayerId(garmin_data_p->privpkt) ==
1081 GARMIN_LAYERID_PRIVATE) {
1083 dev_dbg(dev, "%s - processing private request %d\n",
1084 __func__, pktid);
1086 /* drop all unfinished transfers */
1087 garmin_clear(garmin_data_p);
1089 switch (pktid) {
1090 case PRIV_PKTID_SET_MODE:
1091 if (pktsiz != 4)
1092 return -EINVPKT;
1093 garmin_data_p->mode = __le32_to_cpu(privpkt[3]);
1094 dev_dbg(dev, "%s - mode set to %d\n",
1095 __func__, garmin_data_p->mode);
1096 break;
1098 case PRIV_PKTID_INFO_REQ:
1099 priv_status_resp(port);
1100 break;
1102 case PRIV_PKTID_RESET_REQ:
1103 process_resetdev_request(port);
1104 break;
1106 case PRIV_PKTID_SET_DEF_MODE:
1107 if (pktsiz != 4)
1108 return -EINVPKT;
1109 initial_mode = __le32_to_cpu(privpkt[3]);
1110 dev_dbg(dev, "%s - initial_mode set to %d\n",
1111 __func__,
1112 garmin_data_p->mode);
1113 break;
1115 return count;
1119 if (garmin_data_p->mode == MODE_GARMIN_SERIAL) {
1120 return gsp_receive(garmin_data_p, buf, count);
1121 } else { /* MODE_NATIVE */
1122 return nat_receive(garmin_data_p, buf, count);
1127 static int garmin_write_room(struct tty_struct *tty)
1129 struct usb_serial_port *port = tty->driver_data;
1131 * Report back the bytes currently available in the output buffer.
1133 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1134 return GPS_OUT_BUFSIZ-garmin_data_p->outsize;
1138 static void garmin_read_process(struct garmin_data *garmin_data_p,
1139 unsigned char *data, unsigned data_length,
1140 int bulk_data)
1142 unsigned long flags;
1144 if (garmin_data_p->flags & FLAGS_DROP_DATA) {
1145 /* abort-transfer cmd is active */
1146 dev_dbg(&garmin_data_p->port->dev, "%s - pkt dropped\n", __func__);
1147 } else if (garmin_data_p->state != STATE_DISCONNECTED &&
1148 garmin_data_p->state != STATE_RESET) {
1150 /* if throttling is active or postprecessing is required
1151 put the received data in the input queue, otherwise
1152 send it directly to the tty port */
1153 if (garmin_data_p->flags & FLAGS_QUEUING) {
1154 pkt_add(garmin_data_p, data, data_length);
1155 } else if (bulk_data ||
1156 getLayerId(data) == GARMIN_LAYERID_APPL) {
1158 spin_lock_irqsave(&garmin_data_p->lock, flags);
1159 garmin_data_p->flags |= APP_RESP_SEEN;
1160 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1162 if (garmin_data_p->mode == MODE_GARMIN_SERIAL) {
1163 pkt_add(garmin_data_p, data, data_length);
1164 } else {
1165 send_to_tty(garmin_data_p->port, data,
1166 data_length);
1169 /* ignore system layer packets ... */
1174 static void garmin_read_bulk_callback(struct urb *urb)
1176 unsigned long flags;
1177 struct usb_serial_port *port = urb->context;
1178 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1179 unsigned char *data = urb->transfer_buffer;
1180 int status = urb->status;
1181 int retval;
1183 if (status) {
1184 dev_dbg(&urb->dev->dev, "%s - nonzero read bulk status received: %d\n",
1185 __func__, status);
1186 return;
1189 usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data);
1191 garmin_read_process(garmin_data_p, data, urb->actual_length, 1);
1193 if (urb->actual_length == 0 &&
1194 (garmin_data_p->flags & FLAGS_BULK_IN_RESTART) != 0) {
1195 spin_lock_irqsave(&garmin_data_p->lock, flags);
1196 garmin_data_p->flags &= ~FLAGS_BULK_IN_RESTART;
1197 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1198 retval = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1199 if (retval)
1200 dev_err(&port->dev,
1201 "%s - failed resubmitting read urb, error %d\n",
1202 __func__, retval);
1203 } else if (urb->actual_length > 0) {
1204 /* Continue trying to read until nothing more is received */
1205 if ((garmin_data_p->flags & FLAGS_THROTTLED) == 0) {
1206 retval = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1207 if (retval)
1208 dev_err(&port->dev,
1209 "%s - failed resubmitting read urb, error %d\n",
1210 __func__, retval);
1212 } else {
1213 dev_dbg(&port->dev, "%s - end of bulk data\n", __func__);
1214 spin_lock_irqsave(&garmin_data_p->lock, flags);
1215 garmin_data_p->flags &= ~FLAGS_BULK_IN_ACTIVE;
1216 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1221 static void garmin_read_int_callback(struct urb *urb)
1223 unsigned long flags;
1224 int retval;
1225 struct usb_serial_port *port = urb->context;
1226 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1227 unsigned char *data = urb->transfer_buffer;
1228 int status = urb->status;
1230 switch (status) {
1231 case 0:
1232 /* success */
1233 break;
1234 case -ECONNRESET:
1235 case -ENOENT:
1236 case -ESHUTDOWN:
1237 /* this urb is terminated, clean up */
1238 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n",
1239 __func__, status);
1240 return;
1241 default:
1242 dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n",
1243 __func__, status);
1244 return;
1247 usb_serial_debug_data(&port->dev, __func__, urb->actual_length,
1248 urb->transfer_buffer);
1250 if (urb->actual_length == sizeof(GARMIN_BULK_IN_AVAIL_REPLY) &&
1251 memcmp(data, GARMIN_BULK_IN_AVAIL_REPLY,
1252 sizeof(GARMIN_BULK_IN_AVAIL_REPLY)) == 0) {
1254 dev_dbg(&port->dev, "%s - bulk data available.\n", __func__);
1256 if ((garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE) == 0) {
1258 /* bulk data available */
1259 retval = usb_submit_urb(port->read_urb, GFP_ATOMIC);
1260 if (retval) {
1261 dev_err(&port->dev,
1262 "%s - failed submitting read urb, error %d\n",
1263 __func__, retval);
1264 } else {
1265 spin_lock_irqsave(&garmin_data_p->lock, flags);
1266 garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE;
1267 spin_unlock_irqrestore(&garmin_data_p->lock,
1268 flags);
1270 } else {
1271 /* bulk-in transfer still active */
1272 spin_lock_irqsave(&garmin_data_p->lock, flags);
1273 garmin_data_p->flags |= FLAGS_BULK_IN_RESTART;
1274 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1277 } else if (urb->actual_length == (4+sizeof(GARMIN_START_SESSION_REPLY))
1278 && memcmp(data, GARMIN_START_SESSION_REPLY,
1279 sizeof(GARMIN_START_SESSION_REPLY)) == 0) {
1281 spin_lock_irqsave(&garmin_data_p->lock, flags);
1282 garmin_data_p->flags |= FLAGS_SESSION_REPLY1_SEEN;
1283 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1285 /* save the serial number */
1286 garmin_data_p->serial_num = __le32_to_cpup(
1287 (__le32 *)(data+GARMIN_PKTHDR_LENGTH));
1289 dev_dbg(&port->dev, "%s - start-of-session reply seen - serial %u.\n",
1290 __func__, garmin_data_p->serial_num);
1293 garmin_read_process(garmin_data_p, data, urb->actual_length, 0);
1295 retval = usb_submit_urb(urb, GFP_ATOMIC);
1296 if (retval)
1297 dev_err(&urb->dev->dev,
1298 "%s - Error %d submitting interrupt urb\n",
1299 __func__, retval);
1304 * Sends the next queued packt to the tty port (garmin native mode only)
1305 * and then sets a timer to call itself again until all queued data
1306 * is sent.
1308 static int garmin_flush_queue(struct garmin_data *garmin_data_p)
1310 unsigned long flags;
1311 struct garmin_packet *pkt;
1313 if ((garmin_data_p->flags & FLAGS_THROTTLED) == 0) {
1314 pkt = pkt_pop(garmin_data_p);
1315 if (pkt != NULL) {
1316 send_to_tty(garmin_data_p->port, pkt->data, pkt->size);
1317 kfree(pkt);
1318 mod_timer(&garmin_data_p->timer, (1)+jiffies);
1320 } else {
1321 spin_lock_irqsave(&garmin_data_p->lock, flags);
1322 garmin_data_p->flags &= ~FLAGS_QUEUING;
1323 spin_unlock_irqrestore(&garmin_data_p->lock, flags);
1326 return 0;
1330 static void garmin_throttle(struct tty_struct *tty)
1332 struct usb_serial_port *port = tty->driver_data;
1333 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1335 /* set flag, data received will be put into a queue
1336 for later processing */
1337 spin_lock_irq(&garmin_data_p->lock);
1338 garmin_data_p->flags |= FLAGS_QUEUING|FLAGS_THROTTLED;
1339 spin_unlock_irq(&garmin_data_p->lock);
1343 static void garmin_unthrottle(struct tty_struct *tty)
1345 struct usb_serial_port *port = tty->driver_data;
1346 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1347 int status;
1349 spin_lock_irq(&garmin_data_p->lock);
1350 garmin_data_p->flags &= ~FLAGS_THROTTLED;
1351 spin_unlock_irq(&garmin_data_p->lock);
1353 /* in native mode send queued data to tty, in
1354 serial mode nothing needs to be done here */
1355 if (garmin_data_p->mode == MODE_NATIVE)
1356 garmin_flush_queue(garmin_data_p);
1358 if ((garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE) != 0) {
1359 status = usb_submit_urb(port->read_urb, GFP_KERNEL);
1360 if (status)
1361 dev_err(&port->dev,
1362 "%s - failed resubmitting read urb, error %d\n",
1363 __func__, status);
1368 * The timer is currently only used to send queued packets to
1369 * the tty in cases where the protocol provides no own handshaking
1370 * to initiate the transfer.
1372 static void timeout_handler(unsigned long data)
1374 struct garmin_data *garmin_data_p = (struct garmin_data *) data;
1376 /* send the next queued packet to the tty port */
1377 if (garmin_data_p->mode == MODE_NATIVE)
1378 if (garmin_data_p->flags & FLAGS_QUEUING)
1379 garmin_flush_queue(garmin_data_p);
1384 static int garmin_port_probe(struct usb_serial_port *port)
1386 int status;
1387 struct garmin_data *garmin_data_p;
1389 garmin_data_p = kzalloc(sizeof(struct garmin_data), GFP_KERNEL);
1390 if (!garmin_data_p)
1391 return -ENOMEM;
1393 init_timer(&garmin_data_p->timer);
1394 spin_lock_init(&garmin_data_p->lock);
1395 INIT_LIST_HEAD(&garmin_data_p->pktlist);
1396 /* garmin_data_p->timer.expires = jiffies + session_timeout; */
1397 garmin_data_p->timer.data = (unsigned long)garmin_data_p;
1398 garmin_data_p->timer.function = timeout_handler;
1399 garmin_data_p->port = port;
1400 garmin_data_p->state = 0;
1401 garmin_data_p->flags = 0;
1402 garmin_data_p->count = 0;
1403 usb_set_serial_port_data(port, garmin_data_p);
1405 status = garmin_init_session(port);
1407 return status;
1411 static int garmin_port_remove(struct usb_serial_port *port)
1413 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1415 usb_kill_urb(port->interrupt_in_urb);
1416 del_timer_sync(&garmin_data_p->timer);
1417 kfree(garmin_data_p);
1418 return 0;
1422 /* All of the device info needed */
1423 static struct usb_serial_driver garmin_device = {
1424 .driver = {
1425 .owner = THIS_MODULE,
1426 .name = "garmin_gps",
1428 .description = "Garmin GPS usb/tty",
1429 .id_table = id_table,
1430 .num_ports = 1,
1431 .open = garmin_open,
1432 .close = garmin_close,
1433 .throttle = garmin_throttle,
1434 .unthrottle = garmin_unthrottle,
1435 .port_probe = garmin_port_probe,
1436 .port_remove = garmin_port_remove,
1437 .write = garmin_write,
1438 .write_room = garmin_write_room,
1439 .write_bulk_callback = garmin_write_bulk_callback,
1440 .read_bulk_callback = garmin_read_bulk_callback,
1441 .read_int_callback = garmin_read_int_callback,
1444 static struct usb_serial_driver * const serial_drivers[] = {
1445 &garmin_device, NULL
1448 module_usb_serial_driver(serial_drivers, id_table);
1450 MODULE_AUTHOR(DRIVER_AUTHOR);
1451 MODULE_DESCRIPTION(DRIVER_DESC);
1452 MODULE_LICENSE("GPL");
1454 module_param(initial_mode, int, S_IRUGO);
1455 MODULE_PARM_DESC(initial_mode, "Initial mode");