Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Garmin GPS driver |
| 3 | * |
Hermann Kneissel | b4026c4 | 2011-04-29 08:58:43 +0200 | [diff] [blame] | 4 | * Copyright (C) 2006-2011 Hermann Kneissel herkne@gmx.de |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * The latest version of the driver can be found at |
| 7 | * http://sourceforge.net/projects/garmin-gps/ |
| 8 | * |
| 9 | * This driver has been derived from v2.1 of the visor driver. |
| 10 | * |
| 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. |
| 15 | * |
| 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. |
| 20 | * |
| 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 |
| 24 | */ |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/kernel.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/timer.h> |
| 31 | #include <linux/tty.h> |
| 32 | #include <linux/tty_driver.h> |
| 33 | #include <linux/tty_flip.h> |
| 34 | #include <linux/module.h> |
| 35 | #include <linux/spinlock.h> |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 36 | #include <linux/uaccess.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 37 | #include <linux/atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/usb.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 39 | #include <linux/usb/serial.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | /* the mode to be set when the port ist opened */ |
| 42 | static int initial_mode = 1; |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #define GARMIN_VENDOR_ID 0x091E |
| 45 | |
| 46 | /* |
| 47 | * Version Information |
| 48 | */ |
| 49 | |
| 50 | #define VERSION_MAJOR 0 |
Hermann Kneissel | b4026c4 | 2011-04-29 08:58:43 +0200 | [diff] [blame] | 51 | #define VERSION_MINOR 36 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | #define _STR(s) #s |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 54 | #define _DRIVER_VERSION(a, b) "v" _STR(a) "." _STR(b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #define DRIVER_VERSION _DRIVER_VERSION(VERSION_MAJOR, VERSION_MINOR) |
| 56 | #define DRIVER_AUTHOR "hermann kneissel" |
| 57 | #define DRIVER_DESC "garmin gps driver" |
| 58 | |
| 59 | /* error codes returned by the driver */ |
| 60 | #define EINVPKT 1000 /* invalid packet structure */ |
| 61 | |
| 62 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 63 | /* size of the header of a packet using the usb protocol */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #define GARMIN_PKTHDR_LENGTH 12 |
| 65 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 66 | /* max. possible size of a packet using the serial protocol */ |
| 67 | #define MAX_SERIAL_PKT_SIZ (3 + 255 + 3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 69 | /* max. possible size of a packet with worst case stuffing */ |
| 70 | #define MAX_SERIAL_PKT_SIZ_STUFFED (MAX_SERIAL_PKT_SIZ + 256) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 72 | /* size of a buffer able to hold a complete (no stuffing) packet |
| 73 | * (the document protocol does not contain packets with a larger |
| 74 | * size, but in theory a packet may be 64k+12 bytes - if in |
| 75 | * later protocol versions larger packet sizes occur, this value |
| 76 | * should be increased accordingly, so the input buffer is always |
| 77 | * large enough the store a complete packet inclusive header) */ |
| 78 | #define GPS_IN_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 80 | /* size of a buffer able to hold a complete (incl. stuffing) packet */ |
| 81 | #define GPS_OUT_BUFSIZ (GARMIN_PKTHDR_LENGTH+MAX_SERIAL_PKT_SIZ_STUFFED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 83 | /* where to place the packet id of a serial packet, so we can |
| 84 | * prepend the usb-packet header without the need to move the |
| 85 | * packets data */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | #define GSP_INITIAL_OFFSET (GARMIN_PKTHDR_LENGTH-2) |
| 87 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 88 | /* max. size of incoming private packets (header+1 param) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | #define PRIVPKTSIZ (GARMIN_PKTHDR_LENGTH+4) |
| 90 | |
| 91 | #define GARMIN_LAYERID_TRANSPORT 0 |
| 92 | #define GARMIN_LAYERID_APPL 20 |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 93 | /* our own layer-id to use for some control mechanisms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | #define GARMIN_LAYERID_PRIVATE 0x01106E4B |
| 95 | |
| 96 | #define GARMIN_PKTID_PVT_DATA 51 |
| 97 | #define GARMIN_PKTID_L001_COMMAND_DATA 10 |
| 98 | |
| 99 | #define CMND_ABORT_TRANSFER 0 |
| 100 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 101 | /* packet ids used in private layer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | #define PRIV_PKTID_SET_DEBUG 1 |
| 103 | #define PRIV_PKTID_SET_MODE 2 |
| 104 | #define PRIV_PKTID_INFO_REQ 3 |
| 105 | #define PRIV_PKTID_INFO_RESP 4 |
| 106 | #define PRIV_PKTID_RESET_REQ 5 |
| 107 | #define PRIV_PKTID_SET_DEF_MODE 6 |
| 108 | |
| 109 | |
| 110 | #define ETX 0x03 |
| 111 | #define DLE 0x10 |
| 112 | #define ACK 0x06 |
| 113 | #define NAK 0x15 |
| 114 | |
| 115 | /* structure used to queue incoming packets */ |
| 116 | struct garmin_packet { |
| 117 | struct list_head list; |
| 118 | int seq; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 119 | /* the real size of the data array, always > 0 */ |
| 120 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | __u8 data[1]; |
| 122 | }; |
| 123 | |
| 124 | /* structure used to keep the current state of the driver */ |
| 125 | struct garmin_data { |
| 126 | __u8 state; |
| 127 | __u16 flags; |
| 128 | __u8 mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | __u8 count; |
| 130 | __u8 pkt_id; |
| 131 | __u32 serial_num; |
| 132 | struct timer_list timer; |
| 133 | struct usb_serial_port *port; |
| 134 | int seq_counter; |
| 135 | int insize; |
| 136 | int outsize; |
| 137 | __u8 inbuffer [GPS_IN_BUFSIZ]; /* tty -> usb */ |
| 138 | __u8 outbuffer[GPS_OUT_BUFSIZ]; /* usb -> tty */ |
| 139 | __u8 privpkt[4*6]; |
| 140 | spinlock_t lock; |
| 141 | struct list_head pktlist; |
| 142 | }; |
| 143 | |
| 144 | |
| 145 | #define STATE_NEW 0 |
| 146 | #define STATE_INITIAL_DELAY 1 |
| 147 | #define STATE_TIMEOUT 2 |
| 148 | #define STATE_SESSION_REQ1 3 |
| 149 | #define STATE_SESSION_REQ2 4 |
| 150 | #define STATE_ACTIVE 5 |
| 151 | |
| 152 | #define STATE_RESET 8 |
| 153 | #define STATE_DISCONNECTED 9 |
| 154 | #define STATE_WAIT_TTY_ACK 10 |
| 155 | #define STATE_GSP_WAIT_DATA 11 |
| 156 | |
| 157 | #define MODE_NATIVE 0 |
| 158 | #define MODE_GARMIN_SERIAL 1 |
| 159 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 160 | /* Flags used in garmin_data.flags: */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | #define FLAGS_SESSION_REPLY_MASK 0x00C0 |
| 162 | #define FLAGS_SESSION_REPLY1_SEEN 0x0080 |
| 163 | #define FLAGS_SESSION_REPLY2_SEEN 0x0040 |
| 164 | #define FLAGS_BULK_IN_ACTIVE 0x0020 |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 165 | #define FLAGS_BULK_IN_RESTART 0x0010 |
| 166 | #define FLAGS_THROTTLED 0x0008 |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 167 | #define APP_REQ_SEEN 0x0004 |
| 168 | #define APP_RESP_SEEN 0x0002 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | #define CLEAR_HALT_REQUIRED 0x0001 |
| 170 | |
| 171 | #define FLAGS_QUEUING 0x0100 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | #define FLAGS_DROP_DATA 0x0800 |
| 173 | |
| 174 | #define FLAGS_GSP_SKIP 0x1000 |
| 175 | #define FLAGS_GSP_DLESEEN 0x2000 |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | /* function prototypes */ |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 183 | static int gsp_next_packet(struct garmin_data *garmin_data_p); |
| 184 | static int garmin_write_bulk(struct usb_serial_port *port, |
Hermann Kneissel | 468d136 | 2007-08-03 20:20:33 +0200 | [diff] [blame] | 185 | const unsigned char *buf, int count, |
| 186 | int dismiss_ack); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | /* some special packets to be send or received */ |
| 189 | static unsigned char const GARMIN_START_SESSION_REQ[] |
| 190 | = { 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | static unsigned char const GARMIN_START_SESSION_REPLY[] |
| 192 | = { 0, 0, 0, 0, 6, 0, 0, 0, 4, 0, 0, 0 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | static unsigned char const GARMIN_BULK_IN_AVAIL_REPLY[] |
| 194 | = { 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0 }; |
| 195 | static unsigned char const GARMIN_APP_LAYER_REPLY[] |
| 196 | = { 0x14, 0, 0, 0 }; |
| 197 | static unsigned char const GARMIN_START_PVT_REQ[] |
| 198 | = { 20, 0, 0, 0, 10, 0, 0, 0, 2, 0, 0, 0, 49, 0 }; |
| 199 | static unsigned char const GARMIN_STOP_PVT_REQ[] |
| 200 | = { 20, 0, 0, 0, 10, 0, 0, 0, 2, 0, 0, 0, 50, 0 }; |
| 201 | static unsigned char const GARMIN_STOP_TRANSFER_REQ[] |
| 202 | = { 20, 0, 0, 0, 10, 0, 0, 0, 2, 0, 0, 0, 0, 0 }; |
| 203 | static unsigned char const GARMIN_STOP_TRANSFER_REQ_V2[] |
| 204 | = { 20, 0, 0, 0, 10, 0, 0, 0, 1, 0, 0, 0, 0 }; |
| 205 | static unsigned char const PRIVATE_REQ[] |
| 206 | = { 0x4B, 0x6E, 0x10, 0x01, 0xFF, 0, 0, 0, 0xFF, 0, 0, 0 }; |
| 207 | |
| 208 | |
| 209 | |
Németh Márton | 7d40d7e | 2010-01-10 15:34:24 +0100 | [diff] [blame] | 210 | static const struct usb_device_id id_table[] = { |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 211 | /* the same device id seems to be used by all |
| 212 | usb enabled GPS devices */ |
| 213 | { USB_DEVICE(GARMIN_VENDOR_ID, 3) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { } /* Terminating entry */ |
| 215 | }; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 216 | MODULE_DEVICE_TABLE(usb, id_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | static inline int getLayerId(const __u8 *usbPacket) |
| 220 | { |
| 221 | return __le32_to_cpup((__le32 *)(usbPacket)); |
| 222 | } |
| 223 | |
| 224 | static inline int getPacketId(const __u8 *usbPacket) |
| 225 | { |
| 226 | return __le32_to_cpup((__le32 *)(usbPacket+4)); |
| 227 | } |
| 228 | |
| 229 | static inline int getDataLength(const __u8 *usbPacket) |
| 230 | { |
| 231 | return __le32_to_cpup((__le32 *)(usbPacket+8)); |
| 232 | } |
| 233 | |
| 234 | |
| 235 | /* |
| 236 | * check if the usb-packet in buf contains an abort-transfer command. |
| 237 | * (if yes, all queued data will be dropped) |
| 238 | */ |
| 239 | static inline int isAbortTrfCmnd(const unsigned char *buf) |
| 240 | { |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 241 | if (0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ, |
| 242 | sizeof(GARMIN_STOP_TRANSFER_REQ)) || |
| 243 | 0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ_V2, |
| 244 | sizeof(GARMIN_STOP_TRANSFER_REQ_V2))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | return 1; |
| 246 | else |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | |
| 251 | |
| 252 | static void send_to_tty(struct usb_serial_port *port, |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 253 | char *data, unsigned int actual_length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 255 | if (actual_length) { |
Greg Kroah-Hartman | 59d33f2 | 2012-09-18 09:58:57 +0100 | [diff] [blame] | 256 | usb_serial_debug_data(&port->dev, __func__, actual_length, data); |
Jiri Slaby | 05c7cd3 | 2013-01-03 15:53:04 +0100 | [diff] [blame] | 257 | tty_insert_flip_string(&port->port, data, actual_length); |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 258 | tty_flip_buffer_push(&port->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
| 262 | |
| 263 | /****************************************************************************** |
| 264 | * packet queue handling |
| 265 | ******************************************************************************/ |
| 266 | |
| 267 | /* |
| 268 | * queue a received (usb-)packet for later processing |
| 269 | */ |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 270 | static int pkt_add(struct garmin_data *garmin_data_p, |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 271 | unsigned char *data, unsigned int data_length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | { |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 273 | int state = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | int result = 0; |
| 275 | unsigned long flags; |
| 276 | struct garmin_packet *pkt; |
| 277 | |
| 278 | /* process only packets containg data ... */ |
| 279 | if (data_length) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | pkt = kmalloc(sizeof(struct garmin_packet)+data_length, |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 281 | GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | if (pkt == NULL) { |
| 283 | dev_err(&garmin_data_p->port->dev, "out of memory\n"); |
| 284 | return 0; |
| 285 | } |
| 286 | pkt->size = data_length; |
| 287 | memcpy(pkt->data, data, data_length); |
| 288 | |
| 289 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 290 | garmin_data_p->flags |= FLAGS_QUEUING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | result = list_empty(&garmin_data_p->pktlist); |
| 292 | pkt->seq = garmin_data_p->seq_counter++; |
| 293 | list_add_tail(&pkt->list, &garmin_data_p->pktlist); |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 294 | state = garmin_data_p->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
| 296 | |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 297 | dev_dbg(&garmin_data_p->port->dev, |
| 298 | "%s - added: pkt: %d - %d bytes\n", __func__, |
| 299 | pkt->seq, data_length); |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | /* in serial mode, if someone is waiting for data from |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 302 | the device, convert and send the next packet to tty. */ |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 303 | if (result && (state == STATE_GSP_WAIT_DATA)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | gsp_next_packet(garmin_data_p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
| 306 | return result; |
| 307 | } |
| 308 | |
| 309 | |
| 310 | /* get the next pending packet */ |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 311 | static struct garmin_packet *pkt_pop(struct garmin_data *garmin_data_p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
| 313 | unsigned long flags; |
| 314 | struct garmin_packet *result = NULL; |
| 315 | |
| 316 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
| 317 | if (!list_empty(&garmin_data_p->pktlist)) { |
| 318 | result = (struct garmin_packet *)garmin_data_p->pktlist.next; |
| 319 | list_del(&result->list); |
| 320 | } |
| 321 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
| 322 | return result; |
| 323 | } |
| 324 | |
| 325 | |
| 326 | /* free up all queued data */ |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 327 | static void pkt_clear(struct garmin_data *garmin_data_p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | { |
| 329 | unsigned long flags; |
| 330 | struct garmin_packet *result = NULL; |
| 331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
| 333 | while (!list_empty(&garmin_data_p->pktlist)) { |
| 334 | result = (struct garmin_packet *)garmin_data_p->pktlist.next; |
| 335 | list_del(&result->list); |
| 336 | kfree(result); |
| 337 | } |
| 338 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
| 339 | } |
| 340 | |
| 341 | |
| 342 | /****************************************************************************** |
| 343 | * garmin serial protocol handling handling |
| 344 | ******************************************************************************/ |
| 345 | |
| 346 | /* send an ack packet back to the tty */ |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 347 | static int gsp_send_ack(struct garmin_data *garmin_data_p, __u8 pkt_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { |
| 349 | __u8 pkt[10]; |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 350 | __u8 cksum = 0; |
| 351 | __u8 *ptr = pkt; |
| 352 | unsigned l = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 354 | dev_dbg(&garmin_data_p->port->dev, "%s - pkt-id: 0x%X.\n", __func__, |
| 355 | 0xFF & pkt_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | *ptr++ = DLE; |
| 358 | *ptr++ = ACK; |
| 359 | cksum += ACK; |
| 360 | |
| 361 | *ptr++ = 2; |
| 362 | cksum += 2; |
| 363 | |
| 364 | *ptr++ = pkt_id; |
| 365 | cksum += pkt_id; |
| 366 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 367 | if (pkt_id == DLE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | *ptr++ = DLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | *ptr++ = 0; |
| 371 | *ptr++ = 0xFF & (-cksum); |
| 372 | *ptr++ = DLE; |
| 373 | *ptr++ = ETX; |
| 374 | |
| 375 | l = ptr-pkt; |
| 376 | |
| 377 | send_to_tty(garmin_data_p->port, pkt, l); |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | |
| 382 | |
| 383 | /* |
| 384 | * called for a complete packet received from tty layer |
| 385 | * |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 386 | * the complete packet (pktid ... cksum) is in garmin_data_p->inbuf starting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | * at GSP_INITIAL_OFFSET. |
| 388 | * |
| 389 | * count - number of bytes in the input buffer including space reserved for |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 390 | * the usb header: GSP_INITIAL_OFFSET + number of bytes in packet |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | * (including pkt-id, data-length a. cksum) |
| 392 | */ |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 393 | static int gsp_rec_packet(struct garmin_data *garmin_data_p, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | { |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 395 | struct device *dev = &garmin_data_p->port->dev; |
Hermann Kneissel | b4026c4 | 2011-04-29 08:58:43 +0200 | [diff] [blame] | 396 | unsigned long flags; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 397 | const __u8 *recpkt = garmin_data_p->inbuffer+GSP_INITIAL_OFFSET; |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 398 | __le32 *usbdata = (__le32 *) garmin_data_p->inbuffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | int cksum = 0; |
| 400 | int n = 0; |
| 401 | int pktid = recpkt[0]; |
| 402 | int size = recpkt[1]; |
| 403 | |
Greg Kroah-Hartman | 59d33f2 | 2012-09-18 09:58:57 +0100 | [diff] [blame] | 404 | usb_serial_debug_data(&garmin_data_p->port->dev, __func__, |
| 405 | count-GSP_INITIAL_OFFSET, recpkt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
| 407 | if (size != (count-GSP_INITIAL_OFFSET-3)) { |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 408 | dev_dbg(dev, "%s - invalid size, expected %d bytes, got %d\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 409 | __func__, size, (count-GSP_INITIAL_OFFSET-3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | return -EINVPKT; |
| 411 | } |
| 412 | |
| 413 | cksum += *recpkt++; |
| 414 | cksum += *recpkt++; |
| 415 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 416 | /* sanity check, remove after test ... */ |
| 417 | if ((__u8 *)&(usbdata[3]) != recpkt) { |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 418 | dev_dbg(dev, "%s - ptr mismatch %p - %p\n", __func__, |
| 419 | &(usbdata[4]), recpkt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | return -EINVPKT; |
| 421 | } |
| 422 | |
| 423 | while (n < size) { |
| 424 | cksum += *recpkt++; |
| 425 | n++; |
| 426 | } |
| 427 | |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 428 | if ((0xff & (cksum + *recpkt)) != 0) { |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 429 | dev_dbg(dev, "%s - invalid checksum, expected %02x, got %02x\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 430 | __func__, 0xff & -cksum, 0xff & *recpkt); |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 431 | return -EINVPKT; |
| 432 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
| 434 | usbdata[0] = __cpu_to_le32(GARMIN_LAYERID_APPL); |
| 435 | usbdata[1] = __cpu_to_le32(pktid); |
| 436 | usbdata[2] = __cpu_to_le32(size); |
| 437 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 438 | garmin_write_bulk(garmin_data_p->port, garmin_data_p->inbuffer, |
Hermann Kneissel | 468d136 | 2007-08-03 20:20:33 +0200 | [diff] [blame] | 439 | GARMIN_PKTHDR_LENGTH+size, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
| 441 | /* if this was an abort-transfer command, flush all |
| 442 | queued data. */ |
| 443 | if (isAbortTrfCmnd(garmin_data_p->inbuffer)) { |
Hermann Kneissel | b4026c4 | 2011-04-29 08:58:43 +0200 | [diff] [blame] | 444 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | garmin_data_p->flags |= FLAGS_DROP_DATA; |
Hermann Kneissel | b4026c4 | 2011-04-29 08:58:43 +0200 | [diff] [blame] | 446 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | pkt_clear(garmin_data_p); |
| 448 | } |
| 449 | |
| 450 | return count; |
| 451 | } |
| 452 | |
| 453 | |
| 454 | |
| 455 | /* |
| 456 | * Called for data received from tty |
| 457 | * |
| 458 | * buf contains the data read, it may span more than one packet or even |
| 459 | * incomplete packets |
| 460 | * |
| 461 | * input record should be a serial-record, but it may not be complete. |
| 462 | * Copy it into our local buffer, until an etx is seen (or an error |
| 463 | * occurs). |
| 464 | * Once the record is complete, convert into a usb packet and send it |
| 465 | * to the bulk pipe, send an ack back to the tty. |
| 466 | * |
| 467 | * If the input is an ack, just send the last queued packet to the |
| 468 | * tty layer. |
| 469 | * |
| 470 | * if the input is an abort command, drop all queued data. |
| 471 | */ |
| 472 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 473 | static int gsp_receive(struct garmin_data *garmin_data_p, |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 474 | const unsigned char *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | { |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 476 | struct device *dev = &garmin_data_p->port->dev; |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 477 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | int offs = 0; |
| 479 | int ack_or_nak_seen = 0; |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 480 | __u8 *dest; |
| 481 | int size; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 482 | /* dleSeen: set if last byte read was a DLE */ |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 483 | int dleSeen; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 484 | /* skip: if set, skip incoming data until possible start of |
| 485 | * new packet |
| 486 | */ |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 487 | int skip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | __u8 data; |
| 489 | |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 490 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
| 491 | dest = garmin_data_p->inbuffer; |
| 492 | size = garmin_data_p->insize; |
| 493 | dleSeen = garmin_data_p->flags & FLAGS_GSP_DLESEEN; |
| 494 | skip = garmin_data_p->flags & FLAGS_GSP_SKIP; |
| 495 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
| 496 | |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 497 | /* dev_dbg(dev, "%s - dle=%d skip=%d size=%d count=%d\n", |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 498 | __func__, dleSeen, skip, size, count); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 500 | if (size == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | size = GSP_INITIAL_OFFSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
| 503 | while (offs < count) { |
| 504 | |
| 505 | data = *(buf+offs); |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 506 | offs++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
| 508 | if (data == DLE) { |
| 509 | if (skip) { /* start of a new pkt */ |
| 510 | skip = 0; |
| 511 | size = GSP_INITIAL_OFFSET; |
| 512 | dleSeen = 1; |
| 513 | } else if (dleSeen) { |
| 514 | dest[size++] = data; |
| 515 | dleSeen = 0; |
| 516 | } else { |
| 517 | dleSeen = 1; |
| 518 | } |
| 519 | } else if (data == ETX) { |
| 520 | if (dleSeen) { |
| 521 | /* packet complete */ |
| 522 | |
| 523 | data = dest[GSP_INITIAL_OFFSET]; |
| 524 | |
| 525 | if (data == ACK) { |
| 526 | ack_or_nak_seen = ACK; |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 527 | dev_dbg(dev, "ACK packet complete.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | } else if (data == NAK) { |
| 529 | ack_or_nak_seen = NAK; |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 530 | dev_dbg(dev, "NAK packet complete.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | } else { |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 532 | dev_dbg(dev, "packet complete - id=0x%X.\n", |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 533 | 0xFF & data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | gsp_rec_packet(garmin_data_p, size); |
| 535 | } |
| 536 | |
| 537 | skip = 1; |
| 538 | size = GSP_INITIAL_OFFSET; |
| 539 | dleSeen = 0; |
| 540 | } else { |
| 541 | dest[size++] = data; |
| 542 | } |
| 543 | } else if (!skip) { |
| 544 | |
| 545 | if (dleSeen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | size = GSP_INITIAL_OFFSET; |
| 547 | dleSeen = 0; |
| 548 | } |
| 549 | |
| 550 | dest[size++] = data; |
| 551 | } |
| 552 | |
| 553 | if (size >= GPS_IN_BUFSIZ) { |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 554 | dev_dbg(dev, "%s - packet too large.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | skip = 1; |
| 556 | size = GSP_INITIAL_OFFSET; |
| 557 | dleSeen = 0; |
| 558 | } |
| 559 | } |
| 560 | |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 561 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
| 562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | garmin_data_p->insize = size; |
| 564 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 565 | /* copy flags back to structure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | if (skip) |
| 567 | garmin_data_p->flags |= FLAGS_GSP_SKIP; |
| 568 | else |
| 569 | garmin_data_p->flags &= ~FLAGS_GSP_SKIP; |
| 570 | |
| 571 | if (dleSeen) |
| 572 | garmin_data_p->flags |= FLAGS_GSP_DLESEEN; |
| 573 | else |
| 574 | garmin_data_p->flags &= ~FLAGS_GSP_DLESEEN; |
| 575 | |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 576 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
| 577 | |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 578 | if (ack_or_nak_seen) { |
| 579 | if (gsp_next_packet(garmin_data_p) > 0) |
| 580 | garmin_data_p->state = STATE_ACTIVE; |
| 581 | else |
| 582 | garmin_data_p->state = STATE_GSP_WAIT_DATA; |
| 583 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | return count; |
| 585 | } |
| 586 | |
| 587 | |
| 588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | /* |
| 590 | * Sends a usb packet to the tty |
| 591 | * |
| 592 | * Assumes, that all packages and at an usb-packet boundary. |
| 593 | * |
| 594 | * return <0 on error, 0 if packet is incomplete or > 0 if packet was sent |
| 595 | */ |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 596 | static int gsp_send(struct garmin_data *garmin_data_p, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | const unsigned char *buf, int count) |
| 598 | { |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 599 | struct device *dev = &garmin_data_p->port->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | const unsigned char *src; |
| 601 | unsigned char *dst; |
| 602 | int pktid = 0; |
| 603 | int datalen = 0; |
| 604 | int cksum = 0; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 605 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | int k; |
| 607 | |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 608 | dev_dbg(dev, "%s - state %d - %d bytes.\n", __func__, |
| 609 | garmin_data_p->state, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
| 611 | k = garmin_data_p->outsize; |
| 612 | if ((k+count) > GPS_OUT_BUFSIZ) { |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 613 | dev_dbg(dev, "packet too large\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | garmin_data_p->outsize = 0; |
| 615 | return -4; |
| 616 | } |
| 617 | |
| 618 | memcpy(garmin_data_p->outbuffer+k, buf, count); |
| 619 | k += count; |
| 620 | garmin_data_p->outsize = k; |
| 621 | |
| 622 | if (k >= GARMIN_PKTHDR_LENGTH) { |
| 623 | pktid = getPacketId(garmin_data_p->outbuffer); |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 624 | datalen = getDataLength(garmin_data_p->outbuffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | i = GARMIN_PKTHDR_LENGTH + datalen; |
| 626 | if (k < i) |
| 627 | return 0; |
| 628 | } else { |
| 629 | return 0; |
| 630 | } |
| 631 | |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 632 | dev_dbg(dev, "%s - %d bytes in buffer, %d bytes in pkt.\n", __func__, k, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
| 634 | /* garmin_data_p->outbuffer now contains a complete packet */ |
| 635 | |
Greg Kroah-Hartman | 59d33f2 | 2012-09-18 09:58:57 +0100 | [diff] [blame] | 636 | usb_serial_debug_data(&garmin_data_p->port->dev, __func__, k, |
| 637 | garmin_data_p->outbuffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | |
| 639 | garmin_data_p->outsize = 0; |
| 640 | |
| 641 | if (GARMIN_LAYERID_APPL != getLayerId(garmin_data_p->outbuffer)) { |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 642 | dev_dbg(dev, "not an application packet (%d)\n", |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 643 | getLayerId(garmin_data_p->outbuffer)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | return -1; |
| 645 | } |
| 646 | |
| 647 | if (pktid > 255) { |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 648 | dev_dbg(dev, "packet-id %d too large\n", pktid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | return -2; |
| 650 | } |
| 651 | |
| 652 | if (datalen > 255) { |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 653 | dev_dbg(dev, "packet-size %d too large\n", datalen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | return -3; |
| 655 | } |
| 656 | |
| 657 | /* the serial protocol should be able to handle this packet */ |
| 658 | |
| 659 | k = 0; |
| 660 | src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 661 | for (i = 0; i < datalen; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | if (*src++ == DLE) |
| 663 | k++; |
| 664 | } |
| 665 | |
| 666 | src = garmin_data_p->outbuffer+GARMIN_PKTHDR_LENGTH; |
| 667 | if (k > (GARMIN_PKTHDR_LENGTH-2)) { |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 668 | /* can't add stuffing DLEs in place, move data to end |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 669 | of buffer ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | dst = garmin_data_p->outbuffer+GPS_OUT_BUFSIZ-datalen; |
| 671 | memcpy(dst, src, datalen); |
| 672 | src = dst; |
| 673 | } |
| 674 | |
| 675 | dst = garmin_data_p->outbuffer; |
| 676 | |
| 677 | *dst++ = DLE; |
| 678 | *dst++ = pktid; |
| 679 | cksum += pktid; |
| 680 | *dst++ = datalen; |
| 681 | cksum += datalen; |
| 682 | if (datalen == DLE) |
| 683 | *dst++ = DLE; |
| 684 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 685 | for (i = 0; i < datalen; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | __u8 c = *src++; |
| 687 | *dst++ = c; |
| 688 | cksum += c; |
| 689 | if (c == DLE) |
| 690 | *dst++ = DLE; |
| 691 | } |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 692 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | cksum = 0xFF & -cksum; |
| 694 | *dst++ = cksum; |
| 695 | if (cksum == DLE) |
| 696 | *dst++ = DLE; |
| 697 | *dst++ = DLE; |
| 698 | *dst++ = ETX; |
| 699 | |
| 700 | i = dst-garmin_data_p->outbuffer; |
| 701 | |
| 702 | send_to_tty(garmin_data_p->port, garmin_data_p->outbuffer, i); |
| 703 | |
| 704 | garmin_data_p->pkt_id = pktid; |
| 705 | garmin_data_p->state = STATE_WAIT_TTY_ACK; |
| 706 | |
| 707 | return i; |
| 708 | } |
| 709 | |
| 710 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | /* |
| 712 | * Process the next pending data packet - if there is one |
| 713 | */ |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 714 | static int gsp_next_packet(struct garmin_data *garmin_data_p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | { |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 716 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | struct garmin_packet *pkt = NULL; |
| 718 | |
| 719 | while ((pkt = pkt_pop(garmin_data_p)) != NULL) { |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 720 | dev_dbg(&garmin_data_p->port->dev, "%s - next pkt: %d\n", __func__, pkt->seq); |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 721 | result = gsp_send(garmin_data_p, pkt->data, pkt->size); |
| 722 | if (result > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | kfree(pkt); |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 724 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | } |
| 726 | kfree(pkt); |
| 727 | } |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 728 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | |
| 732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | /****************************************************************************** |
| 734 | * garmin native mode |
| 735 | ******************************************************************************/ |
| 736 | |
| 737 | |
| 738 | /* |
| 739 | * Called for data received from tty |
| 740 | * |
| 741 | * The input data is expected to be in garmin usb-packet format. |
| 742 | * |
| 743 | * buf contains the data read, it may span more than one packet |
| 744 | * or even incomplete packets |
| 745 | */ |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 746 | static int nat_receive(struct garmin_data *garmin_data_p, |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 747 | const unsigned char *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | { |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 749 | unsigned long flags; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 750 | __u8 *dest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | int offs = 0; |
| 752 | int result = count; |
| 753 | int len; |
| 754 | |
| 755 | while (offs < count) { |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 756 | /* if buffer contains header, copy rest of data */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | if (garmin_data_p->insize >= GARMIN_PKTHDR_LENGTH) |
| 758 | len = GARMIN_PKTHDR_LENGTH |
| 759 | +getDataLength(garmin_data_p->inbuffer); |
| 760 | else |
| 761 | len = GARMIN_PKTHDR_LENGTH; |
| 762 | |
| 763 | if (len >= GPS_IN_BUFSIZ) { |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 764 | /* seems to be an invalid packet, ignore rest |
| 765 | of input */ |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 766 | dev_dbg(&garmin_data_p->port->dev, |
| 767 | "%s - packet size too large: %d\n", |
| 768 | __func__, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | garmin_data_p->insize = 0; |
| 770 | count = 0; |
| 771 | result = -EINVPKT; |
| 772 | } else { |
| 773 | len -= garmin_data_p->insize; |
| 774 | if (len > (count-offs)) |
| 775 | len = (count-offs); |
| 776 | if (len > 0) { |
| 777 | dest = garmin_data_p->inbuffer |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 778 | + garmin_data_p->insize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | memcpy(dest, buf+offs, len); |
| 780 | garmin_data_p->insize += len; |
| 781 | offs += len; |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | /* do we have a complete packet ? */ |
| 786 | if (garmin_data_p->insize >= GARMIN_PKTHDR_LENGTH) { |
| 787 | len = GARMIN_PKTHDR_LENGTH+ |
| 788 | getDataLength(garmin_data_p->inbuffer); |
| 789 | if (garmin_data_p->insize >= len) { |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 790 | garmin_write_bulk(garmin_data_p->port, |
| 791 | garmin_data_p->inbuffer, |
| 792 | len, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | garmin_data_p->insize = 0; |
| 794 | |
| 795 | /* if this was an abort-transfer command, |
| 796 | flush all queued data. */ |
| 797 | if (isAbortTrfCmnd(garmin_data_p->inbuffer)) { |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 798 | spin_lock_irqsave(&garmin_data_p->lock, |
| 799 | flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | garmin_data_p->flags |= FLAGS_DROP_DATA; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 801 | spin_unlock_irqrestore( |
| 802 | &garmin_data_p->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | pkt_clear(garmin_data_p); |
| 804 | } |
| 805 | } |
| 806 | } |
| 807 | } |
| 808 | return result; |
| 809 | } |
| 810 | |
| 811 | |
| 812 | /****************************************************************************** |
| 813 | * private packets |
| 814 | ******************************************************************************/ |
| 815 | |
| 816 | static void priv_status_resp(struct usb_serial_port *port) |
| 817 | { |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 818 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | __le32 *pkt = (__le32 *)garmin_data_p->privpkt; |
| 820 | |
| 821 | pkt[0] = __cpu_to_le32(GARMIN_LAYERID_PRIVATE); |
| 822 | pkt[1] = __cpu_to_le32(PRIV_PKTID_INFO_RESP); |
| 823 | pkt[2] = __cpu_to_le32(12); |
| 824 | pkt[3] = __cpu_to_le32(VERSION_MAJOR << 16 | VERSION_MINOR); |
| 825 | pkt[4] = __cpu_to_le32(garmin_data_p->mode); |
| 826 | pkt[5] = __cpu_to_le32(garmin_data_p->serial_num); |
| 827 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 828 | send_to_tty(port, (__u8 *)pkt, 6 * 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | |
| 832 | /****************************************************************************** |
| 833 | * Garmin specific driver functions |
| 834 | ******************************************************************************/ |
| 835 | |
| 836 | static int process_resetdev_request(struct usb_serial_port *port) |
| 837 | { |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 838 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | int status; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 840 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 842 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | garmin_data_p->flags &= ~(CLEAR_HALT_REQUIRED); |
| 844 | garmin_data_p->state = STATE_RESET; |
| 845 | garmin_data_p->serial_num = 0; |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 846 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 848 | usb_kill_urb(port->interrupt_in_urb); |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 849 | dev_dbg(&port->dev, "%s - usb_reset_device\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | status = usb_reset_device(port->serial->dev); |
| 851 | if (status) |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 852 | dev_dbg(&port->dev, "%s - usb_reset_device failed: %d\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 853 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | return status; |
| 855 | } |
| 856 | |
| 857 | |
| 858 | |
| 859 | /* |
| 860 | * clear all cached data |
| 861 | */ |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 862 | static int garmin_clear(struct garmin_data *garmin_data_p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | { |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 864 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | int status = 0; |
| 866 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | /* flush all queued data */ |
| 868 | pkt_clear(garmin_data_p); |
| 869 | |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 870 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | garmin_data_p->insize = 0; |
| 872 | garmin_data_p->outsize = 0; |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 873 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | |
| 875 | return status; |
| 876 | } |
| 877 | |
| 878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | static int garmin_init_session(struct usb_serial_port *port) |
| 880 | { |
| 881 | struct usb_serial *serial = port->serial; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 882 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | int status = 0; |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 884 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | |
| 886 | if (status == 0) { |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 887 | usb_kill_urb(port->interrupt_in_urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 889 | dev_dbg(&serial->dev->dev, "%s - adding interrupt input\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | status = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
| 891 | if (status) |
| 892 | dev_err(&serial->dev->dev, |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 893 | "%s - failed submitting interrupt urb, error %d\n", |
| 894 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | } |
| 896 | |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 897 | /* |
| 898 | * using the initialization method from gpsbabel. See comments in |
| 899 | * gpsbabel/jeeps/gpslibusb.c gusb_reset_toggles() |
| 900 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | if (status == 0) { |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 902 | dev_dbg(&serial->dev->dev, "%s - starting session ...\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | garmin_data_p->state = STATE_ACTIVE; |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 904 | |
| 905 | for (i = 0; i < 3; i++) { |
| 906 | status = garmin_write_bulk(port, |
| 907 | GARMIN_START_SESSION_REQ, |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 908 | sizeof(GARMIN_START_SESSION_REQ), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 910 | if (status < 0) |
| 911 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | } |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 913 | |
| 914 | if (status > 0) |
| 915 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | return status; |
| 919 | } |
| 920 | |
| 921 | |
| 922 | |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 923 | static int garmin_open(struct tty_struct *tty, struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | { |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 925 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | int status = 0; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 927 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 929 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | garmin_data_p->mode = initial_mode; |
| 931 | garmin_data_p->count = 0; |
Hermann Kneissel | b4026c4 | 2011-04-29 08:58:43 +0200 | [diff] [blame] | 932 | garmin_data_p->flags &= FLAGS_SESSION_REPLY1_SEEN; |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 933 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | |
| 935 | /* shutdown any bulk reads that might be going on */ |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 936 | usb_kill_urb(port->write_urb); |
| 937 | usb_kill_urb(port->read_urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 939 | if (garmin_data_p->state == STATE_RESET) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | status = garmin_init_session(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | |
| 942 | garmin_data_p->state = STATE_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | return status; |
| 944 | } |
| 945 | |
| 946 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 947 | static void garmin_close(struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | { |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 949 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | |
Greg Kroah-Hartman | 1143832 | 2013-06-06 10:32:00 -0700 | [diff] [blame] | 951 | dev_dbg(&port->dev, "%s - mode=%d state=%d flags=0x%X\n", |
| 952 | __func__, garmin_data_p->mode, garmin_data_p->state, |
| 953 | garmin_data_p->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
Johan Hovold | 618aa10 | 2013-03-19 09:21:07 +0100 | [diff] [blame] | 955 | garmin_clear(garmin_data_p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | |
| 957 | /* shutdown our urbs */ |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 958 | usb_kill_urb(port->read_urb); |
| 959 | usb_kill_urb(port->write_urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 961 | /* keep reset state so we know that we must start a new session */ |
| 962 | if (garmin_data_p->state != STATE_RESET) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | garmin_data_p->state = STATE_DISCONNECTED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | } |
| 965 | |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 966 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 967 | static void garmin_write_bulk_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 969 | struct usb_serial_port *port = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | |
Hermann Kneissel | 468d136 | 2007-08-03 20:20:33 +0200 | [diff] [blame] | 971 | if (port) { |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 972 | struct garmin_data *garmin_data_p = |
| 973 | usb_get_serial_port_data(port); |
Hermann Kneissel | 468d136 | 2007-08-03 20:20:33 +0200 | [diff] [blame] | 974 | |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 975 | if (GARMIN_LAYERID_APPL == getLayerId(urb->transfer_buffer)) { |
| 976 | |
| 977 | if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { |
| 978 | gsp_send_ack(garmin_data_p, |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 979 | ((__u8 *)urb->transfer_buffer)[4]); |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 980 | } |
Hermann Kneissel | 468d136 | 2007-08-03 20:20:33 +0200 | [diff] [blame] | 981 | } |
Hermann Kneissel | 468d136 | 2007-08-03 20:20:33 +0200 | [diff] [blame] | 982 | usb_serial_port_softint(port); |
| 983 | } |
| 984 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 985 | /* Ignore errors that resulted from garmin_write_bulk with |
| 986 | dismiss_ack = 1 */ |
Hermann Kneissel | 468d136 | 2007-08-03 20:20:33 +0200 | [diff] [blame] | 987 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | /* free up the transfer buffer, as usb_free_urb() does not do this */ |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 989 | kfree(urb->transfer_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 993 | static int garmin_write_bulk(struct usb_serial_port *port, |
Hermann Kneissel | 468d136 | 2007-08-03 20:20:33 +0200 | [diff] [blame] | 994 | const unsigned char *buf, int count, |
| 995 | int dismiss_ack) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | { |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 997 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | struct usb_serial *serial = port->serial; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 999 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | struct urb *urb; |
| 1001 | unsigned char *buffer; |
| 1002 | int status; |
| 1003 | |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1004 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | garmin_data_p->flags &= ~FLAGS_DROP_DATA; |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1006 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1008 | buffer = kmalloc(count, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | if (!buffer) { |
| 1010 | dev_err(&port->dev, "out of memory\n"); |
| 1011 | return -ENOMEM; |
| 1012 | } |
| 1013 | |
| 1014 | urb = usb_alloc_urb(0, GFP_ATOMIC); |
| 1015 | if (!urb) { |
| 1016 | dev_err(&port->dev, "no more free urbs\n"); |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1017 | kfree(buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | return -ENOMEM; |
| 1019 | } |
| 1020 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1021 | memcpy(buffer, buf, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | |
Greg Kroah-Hartman | 59d33f2 | 2012-09-18 09:58:57 +0100 | [diff] [blame] | 1023 | usb_serial_debug_data(&port->dev, __func__, count, buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1025 | usb_fill_bulk_urb(urb, serial->dev, |
| 1026 | usb_sndbulkpipe(serial->dev, |
| 1027 | port->bulk_out_endpointAddress), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | buffer, count, |
Hermann Kneissel | 468d136 | 2007-08-03 20:20:33 +0200 | [diff] [blame] | 1029 | garmin_write_bulk_callback, |
| 1030 | dismiss_ack ? NULL : port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | urb->transfer_flags |= URB_ZERO_PACKET; |
| 1032 | |
| 1033 | if (GARMIN_LAYERID_APPL == getLayerId(buffer)) { |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 1034 | |
| 1035 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
| 1036 | garmin_data_p->flags |= APP_REQ_SEEN; |
| 1037 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
| 1038 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { |
| 1040 | pkt_clear(garmin_data_p); |
| 1041 | garmin_data_p->state = STATE_GSP_WAIT_DATA; |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | /* send it down the pipe */ |
| 1046 | status = usb_submit_urb(urb, GFP_ATOMIC); |
| 1047 | if (status) { |
| 1048 | dev_err(&port->dev, |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1049 | "%s - usb_submit_urb(write bulk) failed with status = %d\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1050 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | count = status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | /* we are done with this urb, so let the host driver |
| 1055 | * really free it when it is finished with it */ |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1056 | usb_free_urb(urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | |
| 1058 | return count; |
| 1059 | } |
| 1060 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1061 | static int garmin_write(struct tty_struct *tty, struct usb_serial_port *port, |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1062 | const unsigned char *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | { |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 1064 | struct device *dev = &port->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | int pktid, pktsiz, len; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1066 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | __le32 *privpkt = (__le32 *)garmin_data_p->privpkt; |
| 1068 | |
Greg Kroah-Hartman | 59d33f2 | 2012-09-18 09:58:57 +0100 | [diff] [blame] | 1069 | usb_serial_debug_data(dev, __func__, count, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 1071 | if (garmin_data_p->state == STATE_RESET) |
| 1072 | return -EIO; |
| 1073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | /* check for our private packets */ |
| 1075 | if (count >= GARMIN_PKTHDR_LENGTH) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | len = PRIVPKTSIZ; |
| 1077 | if (count < len) |
| 1078 | len = count; |
| 1079 | |
| 1080 | memcpy(garmin_data_p->privpkt, buf, len); |
| 1081 | |
| 1082 | pktsiz = getDataLength(garmin_data_p->privpkt); |
| 1083 | pktid = getPacketId(garmin_data_p->privpkt); |
| 1084 | |
| 1085 | if (count == (GARMIN_PKTHDR_LENGTH+pktsiz) |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1086 | && GARMIN_LAYERID_PRIVATE == |
| 1087 | getLayerId(garmin_data_p->privpkt)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 1089 | dev_dbg(dev, "%s - processing private request %d\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1090 | __func__, pktid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1092 | /* drop all unfinished transfers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | garmin_clear(garmin_data_p); |
| 1094 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1095 | switch (pktid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | case PRIV_PKTID_SET_MODE: |
| 1097 | if (pktsiz != 4) |
| 1098 | return -EINVPKT; |
| 1099 | garmin_data_p->mode = __le32_to_cpu(privpkt[3]); |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 1100 | dev_dbg(dev, "%s - mode set to %d\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1101 | __func__, garmin_data_p->mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | break; |
| 1103 | |
| 1104 | case PRIV_PKTID_INFO_REQ: |
| 1105 | priv_status_resp(port); |
| 1106 | break; |
| 1107 | |
| 1108 | case PRIV_PKTID_RESET_REQ: |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 1109 | process_resetdev_request(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | break; |
| 1111 | |
| 1112 | case PRIV_PKTID_SET_DEF_MODE: |
| 1113 | if (pktsiz != 4) |
| 1114 | return -EINVPKT; |
| 1115 | initial_mode = __le32_to_cpu(privpkt[3]); |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 1116 | dev_dbg(dev, "%s - initial_mode set to %d\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1117 | __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | garmin_data_p->mode); |
| 1119 | break; |
| 1120 | } |
| 1121 | return count; |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { |
| 1126 | return gsp_receive(garmin_data_p, buf, count); |
| 1127 | } else { /* MODE_NATIVE */ |
| 1128 | return nat_receive(garmin_data_p, buf, count); |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1133 | static int garmin_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1135 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | /* |
| 1137 | * Report back the bytes currently available in the output buffer. |
| 1138 | */ |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1139 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | return GPS_OUT_BUFSIZ-garmin_data_p->outsize; |
| 1141 | } |
| 1142 | |
| 1143 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1144 | static void garmin_read_process(struct garmin_data *garmin_data_p, |
Hermann Kneissel | b4026c4 | 2011-04-29 08:58:43 +0200 | [diff] [blame] | 1145 | unsigned char *data, unsigned data_length, |
| 1146 | int bulk_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | { |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 1148 | unsigned long flags; |
| 1149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | if (garmin_data_p->flags & FLAGS_DROP_DATA) { |
| 1151 | /* abort-transfer cmd is actice */ |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 1152 | dev_dbg(&garmin_data_p->port->dev, "%s - pkt dropped\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | } else if (garmin_data_p->state != STATE_DISCONNECTED && |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1154 | garmin_data_p->state != STATE_RESET) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | /* if throttling is active or postprecessing is required |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1157 | put the received data in the input queue, otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | send it directly to the tty port */ |
| 1159 | if (garmin_data_p->flags & FLAGS_QUEUING) { |
| 1160 | pkt_add(garmin_data_p, data, data_length); |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 1161 | } else if (bulk_data || |
Hermann Kneissel | b4026c4 | 2011-04-29 08:58:43 +0200 | [diff] [blame] | 1162 | getLayerId(data) == GARMIN_LAYERID_APPL) { |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 1163 | |
| 1164 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
| 1165 | garmin_data_p->flags |= APP_RESP_SEEN; |
| 1166 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
| 1167 | |
| 1168 | if (garmin_data_p->mode == MODE_GARMIN_SERIAL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | pkt_add(garmin_data_p, data, data_length); |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 1170 | } else { |
| 1171 | send_to_tty(garmin_data_p->port, data, |
| 1172 | data_length); |
| 1173 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | } |
Hermann Kneissel | b4072f4 | 2009-04-26 22:42:04 +0200 | [diff] [blame] | 1175 | /* ignore system layer packets ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1180 | static void garmin_read_bulk_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | { |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1182 | unsigned long flags; |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 1183 | struct usb_serial_port *port = urb->context; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1184 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | unsigned char *data = urb->transfer_buffer; |
Greg Kroah-Hartman | f9feb51 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1186 | int status = urb->status; |
| 1187 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | |
Greg Kroah-Hartman | f9feb51 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1189 | if (status) { |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 1190 | dev_dbg(&urb->dev->dev, "%s - nonzero read bulk status received: %d\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1191 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | return; |
| 1193 | } |
| 1194 | |
Greg Kroah-Hartman | 59d33f2 | 2012-09-18 09:58:57 +0100 | [diff] [blame] | 1195 | usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | |
Hermann Kneissel | b4026c4 | 2011-04-29 08:58:43 +0200 | [diff] [blame] | 1197 | garmin_read_process(garmin_data_p, data, urb->actual_length, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1199 | if (urb->actual_length == 0 && |
| 1200 | 0 != (garmin_data_p->flags & FLAGS_BULK_IN_RESTART)) { |
| 1201 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
| 1202 | garmin_data_p->flags &= ~FLAGS_BULK_IN_RESTART; |
| 1203 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
Greg Kroah-Hartman | f9feb51 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1204 | retval = usb_submit_urb(port->read_urb, GFP_ATOMIC); |
| 1205 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | dev_err(&port->dev, |
| 1207 | "%s - failed resubmitting read urb, error %d\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1208 | __func__, retval); |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1209 | } else if (urb->actual_length > 0) { |
| 1210 | /* Continue trying to read until nothing more is received */ |
| 1211 | if (0 == (garmin_data_p->flags & FLAGS_THROTTLED)) { |
Greg Kroah-Hartman | f9feb51 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1212 | retval = usb_submit_urb(port->read_urb, GFP_ATOMIC); |
| 1213 | if (retval) |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1214 | dev_err(&port->dev, |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 1215 | "%s - failed resubmitting read urb, error %d\n", |
| 1216 | __func__, retval); |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1217 | } |
| 1218 | } else { |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 1219 | dev_dbg(&port->dev, "%s - end of bulk data\n", __func__); |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1220 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
| 1221 | garmin_data_p->flags &= ~FLAGS_BULK_IN_ACTIVE; |
| 1222 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1227 | static void garmin_read_int_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | { |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1229 | unsigned long flags; |
Greg Kroah-Hartman | f9feb51 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1230 | int retval; |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 1231 | struct usb_serial_port *port = urb->context; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1232 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | unsigned char *data = urb->transfer_buffer; |
Greg Kroah-Hartman | f9feb51 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1234 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | |
Greg Kroah-Hartman | f9feb51 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1236 | switch (status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | case 0: |
| 1238 | /* success */ |
| 1239 | break; |
| 1240 | case -ECONNRESET: |
| 1241 | case -ENOENT: |
| 1242 | case -ESHUTDOWN: |
| 1243 | /* this urb is terminated, clean up */ |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 1244 | dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1245 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | return; |
| 1247 | default: |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 1248 | dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1249 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | return; |
| 1251 | } |
| 1252 | |
Greg Kroah-Hartman | 59d33f2 | 2012-09-18 09:58:57 +0100 | [diff] [blame] | 1253 | usb_serial_debug_data(&port->dev, __func__, urb->actual_length, |
| 1254 | urb->transfer_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | |
| 1256 | if (urb->actual_length == sizeof(GARMIN_BULK_IN_AVAIL_REPLY) && |
| 1257 | 0 == memcmp(data, GARMIN_BULK_IN_AVAIL_REPLY, |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1258 | sizeof(GARMIN_BULK_IN_AVAIL_REPLY))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 1260 | dev_dbg(&port->dev, "%s - bulk data available.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1262 | if (0 == (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) { |
| 1263 | |
| 1264 | /* bulk data available */ |
Greg Kroah-Hartman | f9feb51 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1265 | retval = usb_submit_urb(port->read_urb, GFP_ATOMIC); |
| 1266 | if (retval) { |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1267 | dev_err(&port->dev, |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1268 | "%s - failed submitting read urb, error %d\n", |
| 1269 | __func__, retval); |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1270 | } else { |
| 1271 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
| 1272 | garmin_data_p->flags |= FLAGS_BULK_IN_ACTIVE; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1273 | spin_unlock_irqrestore(&garmin_data_p->lock, |
| 1274 | flags); |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1275 | } |
| 1276 | } else { |
| 1277 | /* bulk-in transfer still active */ |
| 1278 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
| 1279 | garmin_data_p->flags |= FLAGS_BULK_IN_RESTART; |
| 1280 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | } else if (urb->actual_length == (4+sizeof(GARMIN_START_SESSION_REPLY)) |
| 1284 | && 0 == memcmp(data, GARMIN_START_SESSION_REPLY, |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1285 | sizeof(GARMIN_START_SESSION_REPLY))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1287 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | garmin_data_p->flags |= FLAGS_SESSION_REPLY1_SEEN; |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1289 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | |
| 1291 | /* save the serial number */ |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1292 | garmin_data_p->serial_num = __le32_to_cpup( |
| 1293 | (__le32 *)(data+GARMIN_PKTHDR_LENGTH)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | |
Greg Kroah-Hartman | 7065e82 | 2012-09-14 11:50:30 -0700 | [diff] [blame] | 1295 | dev_dbg(&port->dev, "%s - start-of-session reply seen - serial %u.\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1296 | __func__, garmin_data_p->serial_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | } |
| 1298 | |
Hermann Kneissel | b4026c4 | 2011-04-29 08:58:43 +0200 | [diff] [blame] | 1299 | garmin_read_process(garmin_data_p, data, urb->actual_length, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1301 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
Greg Kroah-Hartman | f9feb51 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 1302 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | dev_err(&urb->dev->dev, |
| 1304 | "%s - Error %d submitting interrupt urb\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1305 | __func__, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | |
| 1309 | /* |
| 1310 | * Sends the next queued packt to the tty port (garmin native mode only) |
| 1311 | * and then sets a timer to call itself again until all queued data |
| 1312 | * is sent. |
| 1313 | */ |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1314 | static int garmin_flush_queue(struct garmin_data *garmin_data_p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | { |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1316 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | struct garmin_packet *pkt; |
| 1318 | |
| 1319 | if ((garmin_data_p->flags & FLAGS_THROTTLED) == 0) { |
| 1320 | pkt = pkt_pop(garmin_data_p); |
| 1321 | if (pkt != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | send_to_tty(garmin_data_p->port, pkt->data, pkt->size); |
| 1323 | kfree(pkt); |
| 1324 | mod_timer(&garmin_data_p->timer, (1)+jiffies); |
| 1325 | |
| 1326 | } else { |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1327 | spin_lock_irqsave(&garmin_data_p->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | garmin_data_p->flags &= ~FLAGS_QUEUING; |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1329 | spin_unlock_irqrestore(&garmin_data_p->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | } |
| 1331 | } |
| 1332 | return 0; |
| 1333 | } |
| 1334 | |
| 1335 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1336 | static void garmin_throttle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1338 | struct usb_serial_port *port = tty->driver_data; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1339 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | /* set flag, data received will be put into a queue |
| 1342 | for later processing */ |
Oliver Neukum | 6383251 | 2009-10-07 10:50:23 +0200 | [diff] [blame] | 1343 | spin_lock_irq(&garmin_data_p->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | garmin_data_p->flags |= FLAGS_QUEUING|FLAGS_THROTTLED; |
Oliver Neukum | 6383251 | 2009-10-07 10:50:23 +0200 | [diff] [blame] | 1345 | spin_unlock_irq(&garmin_data_p->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1349 | static void garmin_unthrottle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1351 | struct usb_serial_port *port = tty->driver_data; |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1352 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1353 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | |
Oliver Neukum | 6383251 | 2009-10-07 10:50:23 +0200 | [diff] [blame] | 1355 | spin_lock_irq(&garmin_data_p->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | garmin_data_p->flags &= ~FLAGS_THROTTLED; |
Oliver Neukum | 6383251 | 2009-10-07 10:50:23 +0200 | [diff] [blame] | 1357 | spin_unlock_irq(&garmin_data_p->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | |
| 1359 | /* in native mode send queued data to tty, in |
| 1360 | serial mode nothing needs to be done here */ |
| 1361 | if (garmin_data_p->mode == MODE_NATIVE) |
| 1362 | garmin_flush_queue(garmin_data_p); |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1363 | |
| 1364 | if (0 != (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) { |
Oliver Neukum | 6383251 | 2009-10-07 10:50:23 +0200 | [diff] [blame] | 1365 | status = usb_submit_urb(port->read_urb, GFP_KERNEL); |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1366 | if (status) |
| 1367 | dev_err(&port->dev, |
| 1368 | "%s - failed resubmitting read urb, error %d\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1369 | __func__, status); |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1370 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | /* |
| 1374 | * The timer is currently only used to send queued packets to |
| 1375 | * the tty in cases where the protocol provides no own handshaking |
| 1376 | * to initiate the transfer. |
| 1377 | */ |
| 1378 | static void timeout_handler(unsigned long data) |
| 1379 | { |
| 1380 | struct garmin_data *garmin_data_p = (struct garmin_data *) data; |
| 1381 | |
| 1382 | /* send the next queued packet to the tty port */ |
| 1383 | if (garmin_data_p->mode == MODE_NATIVE) |
| 1384 | if (garmin_data_p->flags & FLAGS_QUEUING) |
| 1385 | garmin_flush_queue(garmin_data_p); |
| 1386 | } |
| 1387 | |
| 1388 | |
| 1389 | |
Alan Stern | db5c8b5 | 2012-10-10 14:10:21 -0400 | [diff] [blame] | 1390 | static int garmin_port_probe(struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | { |
Alan Stern | db5c8b5 | 2012-10-10 14:10:21 -0400 | [diff] [blame] | 1392 | int status; |
| 1393 | struct garmin_data *garmin_data_p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | |
Burman Yan | 7ac9da1 | 2006-11-22 20:54:38 +0200 | [diff] [blame] | 1395 | garmin_data_p = kzalloc(sizeof(struct garmin_data), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | if (garmin_data_p == NULL) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1397 | dev_err(&port->dev, "%s - Out of memory\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | return -ENOMEM; |
| 1399 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | init_timer(&garmin_data_p->timer); |
| 1401 | spin_lock_init(&garmin_data_p->lock); |
| 1402 | INIT_LIST_HEAD(&garmin_data_p->pktlist); |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1403 | /* garmin_data_p->timer.expires = jiffies + session_timeout; */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | garmin_data_p->timer.data = (unsigned long)garmin_data_p; |
| 1405 | garmin_data_p->timer.function = timeout_handler; |
| 1406 | garmin_data_p->port = port; |
| 1407 | garmin_data_p->state = 0; |
Hermann Kneissel | b4026c4 | 2011-04-29 08:58:43 +0200 | [diff] [blame] | 1408 | garmin_data_p->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | garmin_data_p->count = 0; |
| 1410 | usb_set_serial_port_data(port, garmin_data_p); |
| 1411 | |
| 1412 | status = garmin_init_session(port); |
| 1413 | |
| 1414 | return status; |
| 1415 | } |
| 1416 | |
| 1417 | |
Alan Stern | db5c8b5 | 2012-10-10 14:10:21 -0400 | [diff] [blame] | 1418 | static int garmin_port_remove(struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | { |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1420 | struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1422 | usb_kill_urb(port->interrupt_in_urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | del_timer_sync(&garmin_data_p->timer); |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1424 | kfree(garmin_data_p); |
Alan Stern | db5c8b5 | 2012-10-10 14:10:21 -0400 | [diff] [blame] | 1425 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | /* All of the device info needed */ |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 1430 | static struct usb_serial_driver garmin_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 1431 | .driver = { |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1432 | .owner = THIS_MODULE, |
| 1433 | .name = "garmin_gps", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 1434 | }, |
Hermann Kneissel | eb6d8c2 | 2006-07-11 19:41:33 +0200 | [diff] [blame] | 1435 | .description = "Garmin GPS usb/tty", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | .id_table = id_table, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | .num_ports = 1, |
| 1438 | .open = garmin_open, |
| 1439 | .close = garmin_close, |
| 1440 | .throttle = garmin_throttle, |
| 1441 | .unthrottle = garmin_unthrottle, |
Alan Stern | db5c8b5 | 2012-10-10 14:10:21 -0400 | [diff] [blame] | 1442 | .port_probe = garmin_port_probe, |
| 1443 | .port_remove = garmin_port_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | .write = garmin_write, |
| 1445 | .write_room = garmin_write_room, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | .write_bulk_callback = garmin_write_bulk_callback, |
| 1447 | .read_bulk_callback = garmin_read_bulk_callback, |
| 1448 | .read_int_callback = garmin_read_int_callback, |
| 1449 | }; |
| 1450 | |
Alan Stern | 97b6b6d | 2012-02-23 14:56:32 -0500 | [diff] [blame] | 1451 | static struct usb_serial_driver * const serial_drivers[] = { |
| 1452 | &garmin_device, NULL |
| 1453 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | |
Greg Kroah-Hartman | 68e2411 | 2012-05-08 15:46:14 -0700 | [diff] [blame] | 1455 | module_usb_serial_driver(serial_drivers, id_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | |
Alan Cox | af6d780 | 2008-07-22 11:11:44 +0100 | [diff] [blame] | 1457 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 1458 | MODULE_DESCRIPTION(DRIVER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | MODULE_LICENSE("GPL"); |
| 1460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | module_param(initial_mode, int, S_IRUGO); |
| 1462 | MODULE_PARM_DESC(initial_mode, "Initial mode"); |