diff options
Diffstat (limited to 'drivers/usb/serial/garmin_gps.c')
-rw-r--r-- | drivers/usb/serial/garmin_gps.c | 129 |
1 files changed, 59 insertions, 70 deletions
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c index 346c15a5106..3ee92648c02 100644 --- a/drivers/usb/serial/garmin_gps.c +++ b/drivers/usb/serial/garmin_gps.c @@ -41,9 +41,6 @@ /* the mode to be set when the port ist opened */ static int initial_mode = 1; -/* debug flag */ -static bool debug; - #define GARMIN_VENDOR_ID 0x091E /* @@ -258,10 +255,7 @@ static void send_to_tty(struct usb_serial_port *port, struct tty_struct *tty = tty_port_tty_get(&port->port); if (tty && actual_length) { - - usb_serial_debug_data(debug, &port->dev, - __func__, actual_length, data); - + usb_serial_debug_data(&port->dev, __func__, actual_length, data); tty_insert_flip_string(tty, data, actual_length); tty_flip_buffer_push(tty); } @@ -303,8 +297,9 @@ static int pkt_add(struct garmin_data *garmin_data_p, state = garmin_data_p->state; spin_unlock_irqrestore(&garmin_data_p->lock, flags); - dbg("%s - added: pkt: %d - %d bytes", - __func__, pkt->seq, data_length); + dev_dbg(&garmin_data_p->port->dev, + "%s - added: pkt: %d - %d bytes\n", __func__, + pkt->seq, data_length); /* in serial mode, if someone is waiting for data from the device, convert and send the next packet to tty. */ @@ -359,7 +354,8 @@ static int gsp_send_ack(struct garmin_data *garmin_data_p, __u8 pkt_id) __u8 *ptr = pkt; unsigned l = 0; - dbg("%s - pkt-id: 0x%X.", __func__, 0xFF & pkt_id); + dev_dbg(&garmin_data_p->port->dev, "%s - pkt-id: 0x%X.\n", __func__, + 0xFF & pkt_id); *ptr++ = DLE; *ptr++ = ACK; @@ -399,20 +395,20 @@ static int gsp_send_ack(struct garmin_data *garmin_data_p, __u8 pkt_id) */ static int gsp_rec_packet(struct garmin_data *garmin_data_p, int count) { + struct device *dev = &garmin_data_p->port->dev; unsigned long flags; const __u8 *recpkt = garmin_data_p->inbuffer+GSP_INITIAL_OFFSET; __le32 *usbdata = (__le32 *) garmin_data_p->inbuffer; - int cksum = 0; int n = 0; int pktid = recpkt[0]; int size = recpkt[1]; - usb_serial_debug_data(debug, &garmin_data_p->port->dev, - __func__, count-GSP_INITIAL_OFFSET, recpkt); + usb_serial_debug_data(&garmin_data_p->port->dev, __func__, + count-GSP_INITIAL_OFFSET, recpkt); if (size != (count-GSP_INITIAL_OFFSET-3)) { - dbg("%s - invalid size, expected %d bytes, got %d", + dev_dbg(dev, "%s - invalid size, expected %d bytes, got %d\n", __func__, size, (count-GSP_INITIAL_OFFSET-3)); return -EINVPKT; } @@ -422,8 +418,8 @@ static int gsp_rec_packet(struct garmin_data *garmin_data_p, int count) /* sanity check, remove after test ... */ if ((__u8 *)&(usbdata[3]) != recpkt) { - dbg("%s - ptr mismatch %p - %p", - __func__, &(usbdata[4]), recpkt); + dev_dbg(dev, "%s - ptr mismatch %p - %p\n", __func__, + &(usbdata[4]), recpkt); return -EINVPKT; } @@ -433,7 +429,7 @@ static int gsp_rec_packet(struct garmin_data *garmin_data_p, int count) } if ((0xff & (cksum + *recpkt)) != 0) { - dbg("%s - invalid checksum, expected %02x, got %02x", + dev_dbg(dev, "%s - invalid checksum, expected %02x, got %02x\n", __func__, 0xff & -cksum, 0xff & *recpkt); return -EINVPKT; } @@ -480,6 +476,7 @@ static int gsp_rec_packet(struct garmin_data *garmin_data_p, int count) static int gsp_receive(struct garmin_data *garmin_data_p, const unsigned char *buf, int count) { + struct device *dev = &garmin_data_p->port->dev; unsigned long flags; int offs = 0; int ack_or_nak_seen = 0; @@ -500,7 +497,7 @@ static int gsp_receive(struct garmin_data *garmin_data_p, skip = garmin_data_p->flags & FLAGS_GSP_SKIP; spin_unlock_irqrestore(&garmin_data_p->lock, flags); - /* dbg("%s - dle=%d skip=%d size=%d count=%d", + /* dev_dbg(dev, "%s - dle=%d skip=%d size=%d count=%d\n", __func__, dleSeen, skip, size, count); */ if (size == 0) @@ -530,12 +527,12 @@ static int gsp_receive(struct garmin_data *garmin_data_p, if (data == ACK) { ack_or_nak_seen = ACK; - dbg("ACK packet complete."); + dev_dbg(dev, "ACK packet complete.\n"); } else if (data == NAK) { ack_or_nak_seen = NAK; - dbg("NAK packet complete."); + dev_dbg(dev, "NAK packet complete.\n"); } else { - dbg("packet complete - id=0x%X.", + dev_dbg(dev, "packet complete - id=0x%X.\n", 0xFF & data); gsp_rec_packet(garmin_data_p, size); } @@ -557,7 +554,7 @@ static int gsp_receive(struct garmin_data *garmin_data_p, } if (size >= GPS_IN_BUFSIZ) { - dbg("%s - packet too large.", __func__); + dev_dbg(dev, "%s - packet too large.\n", __func__); skip = 1; size = GSP_INITIAL_OFFSET; dleSeen = 0; @@ -602,6 +599,7 @@ static int gsp_receive(struct garmin_data *garmin_data_p, static int gsp_send(struct garmin_data *garmin_data_p, const unsigned char *buf, int count) { + struct device *dev = &garmin_data_p->port->dev; const unsigned char *src; unsigned char *dst; int pktid = 0; @@ -610,12 +608,12 @@ static int gsp_send(struct garmin_data *garmin_data_p, int i = 0; int k; - dbg("%s - state %d - %d bytes.", __func__, - garmin_data_p->state, count); + dev_dbg(dev, "%s - state %d - %d bytes.\n", __func__, + garmin_data_p->state, count); k = garmin_data_p->outsize; if ((k+count) > GPS_OUT_BUFSIZ) { - dbg("packet too large"); + dev_dbg(dev, "packet too large\n"); garmin_data_p->outsize = 0; return -4; } @@ -634,28 +632,28 @@ static int gsp_send(struct garmin_data *garmin_data_p, return 0; } - dbg("%s - %d bytes in buffer, %d bytes in pkt.", __func__, k, i); + dev_dbg(dev, "%s - %d bytes in buffer, %d bytes in pkt.\n", __func__, k, i); /* garmin_data_p->outbuffer now contains a complete packet */ - usb_serial_debug_data(debug, &garmin_data_p->port->dev, - __func__, k, garmin_data_p->outbuffer); + usb_serial_debug_data(&garmin_data_p->port->dev, __func__, k, + garmin_data_p->outbuffer); garmin_data_p->outsize = 0; if (GARMIN_LAYERID_APPL != getLayerId(garmin_data_p->outbuffer)) { - dbg("not an application packet (%d)", + dev_dbg(dev, "not an application packet (%d)\n", getLayerId(garmin_data_p->outbuffer)); return -1; } if (pktid > 255) { - dbg("packet-id %d too large", pktid); + dev_dbg(dev, "packet-id %d too large\n", pktid); return -2; } if (datalen > 255) { - dbg("packet-size %d too large", datalen); + dev_dbg(dev, "packet-size %d too large\n", datalen); return -3; } @@ -722,7 +720,7 @@ static int gsp_next_packet(struct garmin_data *garmin_data_p) struct garmin_packet *pkt = NULL; while ((pkt = pkt_pop(garmin_data_p)) != NULL) { - dbg("%s - next pkt: %d", __func__, pkt->seq); + dev_dbg(&garmin_data_p->port->dev, "%s - next pkt: %d\n", __func__, pkt->seq); result = gsp_send(garmin_data_p, pkt->data, pkt->size); if (result > 0) { kfree(pkt); @@ -768,7 +766,9 @@ static int nat_receive(struct garmin_data *garmin_data_p, if (len >= GPS_IN_BUFSIZ) { /* seems to be an invalid packet, ignore rest of input */ - dbg("%s - packet size too large: %d", __func__, len); + dev_dbg(&garmin_data_p->port->dev, + "%s - packet size too large: %d\n", + __func__, len); garmin_data_p->insize = 0; count = 0; result = -EINVPKT; @@ -849,10 +849,10 @@ static int process_resetdev_request(struct usb_serial_port *port) spin_unlock_irqrestore(&garmin_data_p->lock, flags); usb_kill_urb(port->interrupt_in_urb); - dbg("%s - usb_reset_device", __func__); + dev_dbg(&port->dev, "%s - usb_reset_device\n", __func__); status = usb_reset_device(port->serial->dev); if (status) - dbg("%s - usb_reset_device failed: %d", + dev_dbg(&port->dev, "%s - usb_reset_device failed: %d\n", __func__, status); return status; } @@ -889,7 +889,7 @@ static int garmin_init_session(struct usb_serial_port *port) if (status == 0) { usb_kill_urb(port->interrupt_in_urb); - dbg("%s - adding interrupt input", __func__); + dev_dbg(&serial->dev->dev, "%s - adding interrupt input\n", __func__); status = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); if (status) dev_err(&serial->dev->dev, @@ -902,7 +902,7 @@ static int garmin_init_session(struct usb_serial_port *port) * gpsbabel/jeeps/gpslibusb.c gusb_reset_toggles() */ if (status == 0) { - dbg("%s - starting session ...", __func__); + dev_dbg(&serial->dev->dev, "%s - starting session ...\n", __func__); garmin_data_p->state = STATE_ACTIVE; for (i = 0; i < 3; i++) { @@ -952,8 +952,8 @@ static void garmin_close(struct usb_serial_port *port) struct usb_serial *serial = port->serial; struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); - dbg("%s - port %d - mode=%d state=%d flags=0x%X", __func__, - port->number, garmin_data_p->mode, + dev_dbg(&port->dev, "%s - port %d - mode=%d state=%d flags=0x%X\n", + __func__, port->number, garmin_data_p->mode, garmin_data_p->state, garmin_data_p->flags); if (!serial) @@ -1032,7 +1032,7 @@ static int garmin_write_bulk(struct usb_serial_port *port, memcpy(buffer, buf, count); - usb_serial_debug_data(debug, &port->dev, __func__, count, buffer); + usb_serial_debug_data(&port->dev, __func__, count, buffer); usb_fill_bulk_urb(urb, serial->dev, usb_sndbulkpipe(serial->dev, @@ -1073,11 +1073,12 @@ static int garmin_write_bulk(struct usb_serial_port *port, static int garmin_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count) { + struct device *dev = &port->dev; int pktid, pktsiz, len; struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); __le32 *privpkt = (__le32 *)garmin_data_p->privpkt; - usb_serial_debug_data(debug, &port->dev, __func__, count, buf); + usb_serial_debug_data(dev, __func__, count, buf); if (garmin_data_p->state == STATE_RESET) return -EIO; @@ -1097,27 +1098,18 @@ static int garmin_write(struct tty_struct *tty, struct usb_serial_port *port, && GARMIN_LAYERID_PRIVATE == getLayerId(garmin_data_p->privpkt)) { - dbg("%s - processing private request %d", + dev_dbg(dev, "%s - processing private request %d\n", __func__, pktid); /* drop all unfinished transfers */ garmin_clear(garmin_data_p); switch (pktid) { - - case PRIV_PKTID_SET_DEBUG: - if (pktsiz != 4) - return -EINVPKT; - debug = __le32_to_cpu(privpkt[3]); - dbg("%s - debug level set to 0x%X", - __func__, debug); - break; - case PRIV_PKTID_SET_MODE: if (pktsiz != 4) return -EINVPKT; garmin_data_p->mode = __le32_to_cpu(privpkt[3]); - dbg("%s - mode set to %d", + dev_dbg(dev, "%s - mode set to %d\n", __func__, garmin_data_p->mode); break; @@ -1133,7 +1125,7 @@ static int garmin_write(struct tty_struct *tty, struct usb_serial_port *port, if (pktsiz != 4) return -EINVPKT; initial_mode = __le32_to_cpu(privpkt[3]); - dbg("%s - initial_mode set to %d", + dev_dbg(dev, "%s - initial_mode set to %d\n", __func__, garmin_data_p->mode); break; @@ -1169,7 +1161,7 @@ static void garmin_read_process(struct garmin_data *garmin_data_p, if (garmin_data_p->flags & FLAGS_DROP_DATA) { /* abort-transfer cmd is actice */ - dbg("%s - pkt dropped", __func__); + dev_dbg(&garmin_data_p->port->dev, "%s - pkt dropped\n", __func__); } else if (garmin_data_p->state != STATE_DISCONNECTED && garmin_data_p->state != STATE_RESET) { @@ -1178,7 +1170,7 @@ static void garmin_read_process(struct garmin_data *garmin_data_p, send it directly to the tty port */ if (garmin_data_p->flags & FLAGS_QUEUING) { pkt_add(garmin_data_p, data, data_length); - } else if (bulk_data || + } else if (bulk_data || getLayerId(data) == GARMIN_LAYERID_APPL) { spin_lock_irqsave(&garmin_data_p->lock, flags); @@ -1208,18 +1200,17 @@ static void garmin_read_bulk_callback(struct urb *urb) int retval; if (!serial) { - dbg("%s - bad serial pointer, exiting", __func__); + dev_dbg(&urb->dev->dev, "%s - bad serial pointer, exiting\n", __func__); return; } if (status) { - dbg("%s - nonzero read bulk status received: %d", + dev_dbg(&urb->dev->dev, "%s - nonzero read bulk status received: %d\n", __func__, status); return; } - usb_serial_debug_data(debug, &port->dev, - __func__, urb->actual_length, data); + usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data); garmin_read_process(garmin_data_p, data, urb->actual_length, 1); @@ -1239,11 +1230,11 @@ static void garmin_read_bulk_callback(struct urb *urb) retval = usb_submit_urb(port->read_urb, GFP_ATOMIC); if (retval) dev_err(&port->dev, - "%s - failed resubmitting read urb, " - "error %d\n", __func__, retval); + "%s - failed resubmitting read urb, error %d\n", + __func__, retval); } } else { - dbg("%s - end of bulk data", __func__); + dev_dbg(&port->dev, "%s - end of bulk data\n", __func__); spin_lock_irqsave(&garmin_data_p->lock, flags); garmin_data_p->flags &= ~FLAGS_BULK_IN_ACTIVE; spin_unlock_irqrestore(&garmin_data_p->lock, flags); @@ -1268,23 +1259,23 @@ static void garmin_read_int_callback(struct urb *urb) case -ENOENT: case -ESHUTDOWN: /* this urb is terminated, clean up */ - dbg("%s - urb shutting down with status: %d", + dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n", __func__, status); return; default: - dbg("%s - nonzero urb status received: %d", + dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n", __func__, status); return; } - usb_serial_debug_data(debug, &port->dev, __func__, - urb->actual_length, urb->transfer_buffer); + usb_serial_debug_data(&port->dev, __func__, urb->actual_length, + urb->transfer_buffer); if (urb->actual_length == sizeof(GARMIN_BULK_IN_AVAIL_REPLY) && 0 == memcmp(data, GARMIN_BULK_IN_AVAIL_REPLY, sizeof(GARMIN_BULK_IN_AVAIL_REPLY))) { - dbg("%s - bulk data available.", __func__); + dev_dbg(&port->dev, "%s - bulk data available.\n", __func__); if (0 == (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) { @@ -1319,7 +1310,7 @@ static void garmin_read_int_callback(struct urb *urb) garmin_data_p->serial_num = __le32_to_cpup( (__le32 *)(data+GARMIN_PKTHDR_LENGTH)); - dbg("%s - start-of-session reply seen - serial %u.", + dev_dbg(&port->dev, "%s - start-of-session reply seen - serial %u.\n", __func__, garmin_data_p->serial_num); } @@ -1495,7 +1486,5 @@ MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL"); -module_param(debug, bool, S_IWUSR | S_IRUGO); -MODULE_PARM_DESC(debug, "Debug enabled or not"); module_param(initial_mode, int, S_IRUGO); MODULE_PARM_DESC(initial_mode, "Initial mode"); |