1 From b625854c2a6f08942d798f4dfd83c5e0a945c0b8 Mon Sep 17 00:00:00 2001
2 From: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
3 Date: Tue, 23 May 2006 22:32:35 -0300
4 Subject: [PATCH 1/11] usbserial: Introduces new debug macro.
6 This new dbg() macro has the following features:
8 o Adds a '[USBSERIAL]' prefix to every debug message, that way usbserial
9 debug messages are not mixed up with other debug messages like kernel
12 o Also prints the function name (__FUNCTION__), that way dbg() calls
13 doesn't need to pass __FUNCTION__ as a parameter
15 Aditionally, the usb-serial and pl2303 drivers are ported to the new
18 Signed-off-by: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
20 drivers/usb/serial/pl2303.c | 88 ++++++++++++++++++++-------------------
21 drivers/usb/serial/usb-serial.c | 64 ++++++++++++++--------------
22 drivers/usb/serial/usb-serial.h | 8 ++--
23 3 files changed, 81 insertions(+), 79 deletions(-)
25 diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
26 index c96714b..f9300b8 100644
27 --- a/drivers/usb/serial/pl2303.c
28 +++ b/drivers/usb/serial/pl2303.c
29 @@ -253,7 +253,7 @@ static int set_control_lines (struct usb
30 retval = usb_control_msg (dev, usb_sndctrlpipe (dev, 0),
31 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE,
32 value, 0, NULL, 0, 100);
33 - dbg("%s - value = %d, retval = %d", __FUNCTION__, value, retval);
34 + dbg("value = %d, retval = %d", value, retval);
38 @@ -262,7 +262,7 @@ static int pl2303_write (struct usb_seri
39 struct pl2303_private *priv = usb_get_serial_port_data(port);
42 - dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count);
43 + dbg("port %d, %d bytes", port->number, count);
47 @@ -282,7 +282,7 @@ static void pl2303_send(struct usb_seria
48 struct pl2303_private *priv = usb_get_serial_port_data(port);
51 - dbg("%s - port %d", __FUNCTION__, port->number);
52 + dbg("port %d", port->number);
54 spin_lock_irqsave(&priv->lock, flags);
56 @@ -323,13 +323,13 @@ static int pl2303_write_room(struct usb_
60 - dbg("%s - port %d", __FUNCTION__, port->number);
61 + dbg("port %d", port->number);
63 spin_lock_irqsave(&priv->lock, flags);
64 room = pl2303_buf_space_avail(priv->buf);
65 spin_unlock_irqrestore(&priv->lock, flags);
67 - dbg("%s - returns %d", __FUNCTION__, room);
68 + dbg("returns %d", room);
72 @@ -339,13 +339,13 @@ static int pl2303_chars_in_buffer(struct
76 - dbg("%s - port %d", __FUNCTION__, port->number);
77 + dbg("port %d", port->number);
79 spin_lock_irqsave(&priv->lock, flags);
80 chars = pl2303_buf_data_avail(priv->buf);
81 spin_unlock_irqrestore(&priv->lock, flags);
83 - dbg("%s - returns %d", __FUNCTION__, chars);
84 + dbg("returns %d", chars);
88 @@ -360,10 +360,10 @@ static void pl2303_set_termios (struct u
92 - dbg("%s - port %d", __FUNCTION__, port->number);
93 + dbg("port %d", port->number);
95 if ((!port->tty) || (!port->tty->termios)) {
96 - dbg("%s - no tty structures", __FUNCTION__);
97 + dbg("no tty structures");
101 @@ -380,7 +380,7 @@ static void pl2303_set_termios (struct u
103 if ((cflag == old_termios->c_cflag) &&
104 (RELEVANT_IFLAG(port->tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) {
105 - dbg("%s - nothing to change...", __FUNCTION__);
106 + dbg("nothing to change...");
110 @@ -406,7 +406,7 @@ static void pl2303_set_termios (struct u
112 case CS8: buf[6] = 8; break;
114 - dbg("%s - data bits = %d", __FUNCTION__, buf[6]);
115 + dbg("data bits = %d", buf[6]);
119 @@ -431,7 +431,7 @@ static void pl2303_set_termios (struct u
120 dev_err(&port->dev, "pl2303 driver does not support the baudrate requested (fix it)\n");
123 - dbg("%s - baud = %d", __FUNCTION__, baud);
124 + dbg("baud = %d", baud);
126 buf[0] = baud & 0xff;
127 buf[1] = (baud >> 8) & 0xff;
128 @@ -444,10 +444,10 @@ static void pl2303_set_termios (struct u
129 /* For reference buf[4]=2 is 2 stop bits */
130 if (cflag & CSTOPB) {
132 - dbg("%s - stop bits = 2", __FUNCTION__);
133 + dbg("stop bits = 2");
136 - dbg("%s - stop bits = 1", __FUNCTION__);
137 + dbg("stop bits = 1");
140 if (cflag & PARENB) {
141 @@ -458,14 +458,14 @@ static void pl2303_set_termios (struct u
142 /* For reference buf[5]=4 is space parity */
143 if (cflag & PARODD) {
145 - dbg("%s - parity = odd", __FUNCTION__);
146 + dbg("parity = odd");
149 - dbg("%s - parity = even", __FUNCTION__);
150 + dbg("parity = even");
154 - dbg("%s - parity = none", __FUNCTION__);
155 + dbg("parity = none");
158 i = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0),
159 @@ -521,7 +521,7 @@ static int pl2303_open (struct usb_seria
163 - dbg("%s - port %d", __FUNCTION__, port->number);
164 + dbg("port %d", port->number);
166 if (priv->type != HX) {
167 usb_clear_halt(serial->dev, port->write_urb->pipe);
168 @@ -572,7 +572,7 @@ #define SOUP(a,b,c,d) \
170 //FIXME: need to assert RTS and DTR if CRTSCTS off
172 - dbg("%s - submitting read urb", __FUNCTION__);
173 + dbg("submitting read urb");
174 port->read_urb->dev = serial->dev;
175 result = usb_submit_urb (port->read_urb, GFP_KERNEL);
177 @@ -581,7 +581,7 @@ #define SOUP(a,b,c,d) \
181 - dbg("%s - submitting interrupt urb", __FUNCTION__);
182 + dbg("submitting interrupt urb");
183 port->interrupt_in_urb->dev = serial->dev;
184 result = usb_submit_urb (port->interrupt_in_urb, GFP_KERNEL);
186 @@ -602,7 +602,7 @@ static void pl2303_close (struct usb_ser
190 - dbg("%s - port %d", __FUNCTION__, port->number);
191 + dbg("port %d", port->number);
193 /* wait for data to drain from the buffer */
194 spin_lock_irqsave(&priv->lock, flags);
195 @@ -640,7 +640,7 @@ static void pl2303_close (struct usb_ser
196 schedule_timeout_interruptible(timeout);
198 /* shutdown our urbs */
199 - dbg("%s - shutting down urbs", __FUNCTION__);
200 + dbg("shutting down urbs");
201 usb_kill_urb(port->write_urb);
202 usb_kill_urb(port->read_urb);
203 usb_kill_urb(port->interrupt_in_urb);
204 @@ -690,7 +690,7 @@ static int pl2303_tiocmget (struct usb_s
208 - dbg("%s (%d)", __FUNCTION__, port->number);
209 + dbg("(%d)", port->number);
211 if (!usb_get_intfdata(port->serial->interface))
213 @@ -707,7 +707,7 @@ static int pl2303_tiocmget (struct usb_s
214 | ((status & UART_RING) ? TIOCM_RI : 0)
215 | ((status & UART_DCD) ? TIOCM_CD : 0);
217 - dbg("%s - result = %x", __FUNCTION__, result);
218 + dbg("result = %x", result);
222 @@ -750,15 +750,15 @@ static int wait_modem_info(struct usb_se
224 static int pl2303_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg)
226 - dbg("%s (%d) cmd = 0x%04x", __FUNCTION__, port->number, cmd);
227 + dbg("(%d) cmd = 0x%04x", port->number, cmd);
231 - dbg("%s (%d) TIOCMIWAIT", __FUNCTION__, port->number);
232 + dbg("(%d) TIOCMIWAIT", port->number);
233 return wait_modem_info(port, arg);
236 - dbg("%s not supported = 0x%04x", __FUNCTION__, cmd);
237 + dbg("not supported = 0x%04x", cmd);
241 @@ -771,19 +771,19 @@ static void pl2303_break_ctl (struct usb
245 - dbg("%s - port %d", __FUNCTION__, port->number);
246 + dbg("port %d", port->number);
248 if (break_state == 0)
252 - dbg("%s - turning break %s", __FUNCTION__, state==BREAK_OFF ? "off" : "on");
253 + dbg("turning break %s", state==BREAK_OFF ? "off" : "on");
255 result = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0),
256 BREAK_REQUEST, BREAK_REQUEST_TYPE, state,
259 - dbg("%s - error sending break = %d", __FUNCTION__, result);
260 + dbg("error sending break = %d", result);
264 @@ -792,7 +792,7 @@ static void pl2303_shutdown (struct usb_
266 struct pl2303_private *priv;
268 - dbg("%s", __FUNCTION__);
271 for (i = 0; i < serial->num_ports; ++i) {
272 priv = usb_get_serial_port_data(serial->port[i]);
273 @@ -842,7 +842,7 @@ static void pl2303_read_int_callback (st
274 unsigned int actual_length = urb->actual_length;
277 - dbg("%s (%d)", __FUNCTION__, port->number);
278 + dbg("(%d)", port->number);
280 switch (urb->status) {
282 @@ -852,10 +852,10 @@ static void pl2303_read_int_callback (st
285 /* this urb is terminated, clean up */
286 - dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
287 + dbg("urb shutting down with status: %d", urb->status);
290 - dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
291 + dbg("nonzero urb status received: %d", urb->status);
295 @@ -882,17 +882,17 @@ static void pl2303_read_bulk_callback (s
299 - dbg("%s - port %d", __FUNCTION__, port->number);
300 + dbg("port %d", port->number);
303 - dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
304 + dbg("urb->status = %d", urb->status);
305 if (!port->open_count) {
306 - dbg("%s - port is closed, exiting.", __FUNCTION__);
307 + dbg("port is closed, exiting.");
310 if (urb->status == -EPROTO) {
311 /* PL2303 mysteriously fails with -EPROTO reschedule the read */
312 - dbg("%s - caught -EPROTO, resubmitting the urb", __FUNCTION__);
313 + dbg("caught -EPROTO, resubmitting the urb");
315 urb->dev = port->serial->dev;
316 result = usb_submit_urb(urb, GFP_ATOMIC);
317 @@ -900,7 +900,7 @@ static void pl2303_read_bulk_callback (s
318 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
321 - dbg("%s - unable to handle the error, exiting.", __FUNCTION__);
322 + dbg("unable to handle the error, exiting.");
326 @@ -923,7 +923,7 @@ static void pl2303_read_bulk_callback (s
327 tty_flag = TTY_PARITY;
328 else if (status & UART_FRAME_ERROR)
329 tty_flag = TTY_FRAME;
330 - dbg("%s - tty_flag = %d", __FUNCTION__, tty_flag);
331 + dbg("tty_flag = %d", tty_flag);
334 if (tty && urb->actual_length) {
335 @@ -955,7 +955,7 @@ static void pl2303_write_bulk_callback (
336 struct pl2303_private *priv = usb_get_serial_port_data(port);
339 - dbg("%s - port %d", __FUNCTION__, port->number);
340 + dbg("port %d", port->number);
342 switch (urb->status) {
344 @@ -965,13 +965,13 @@ static void pl2303_write_bulk_callback (
347 /* this urb is terminated, clean up */
348 - dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
349 + dbg("urb shutting down with status: %d", urb->status);
350 priv->write_urb_in_use = 0;
353 /* error in the urb, so we have to resubmit it */
354 - dbg("%s - Overflow in write", __FUNCTION__);
355 - dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
356 + dbg("Overflow in write");
357 + dbg("nonzero write bulk status received: %d", urb->status);
358 port->write_urb->transfer_buffer_length = 1;
359 port->write_urb->dev = port->serial->dev;
360 result = usb_submit_urb (port->write_urb, GFP_ATOMIC);
361 diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
362 index 9c36f0e..9fa08c9 100644
363 --- a/drivers/usb/serial/usb-serial.c
364 +++ b/drivers/usb/serial/usb-serial.c
365 @@ -74,7 +74,7 @@ static struct usb_serial *get_free_seria
369 - dbg("%s %d", __FUNCTION__, num_ports);
370 + dbg("%d", num_ports);
373 for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
374 @@ -92,7 +92,7 @@ static struct usb_serial *get_free_seria
378 - dbg("%s - minor base = %d", __FUNCTION__, *minor);
379 + dbg("minor base = %d", *minor);
380 for (i = *minor; (i < (*minor + num_ports)) && (i < SERIAL_TTY_MINORS); ++i)
381 serial_table[i] = serial;
383 @@ -104,7 +104,7 @@ static void return_serial(struct usb_ser
387 - dbg("%s", __FUNCTION__);
392 @@ -122,7 +122,7 @@ static void destroy_serial(struct kref *
394 serial = to_usb_serial(kref);
396 - dbg("%s - %s", __FUNCTION__, serial->type->description);
397 + dbg("%s", serial->type->description);
399 serial->type->shutdown(serial);
401 @@ -178,7 +178,7 @@ static int serial_open (struct tty_struc
402 unsigned int portNumber;
405 - dbg("%s", __FUNCTION__);
408 /* get the serial object associated with this tty pointer */
409 serial = usb_serial_get_by_index(tty->index);
410 @@ -243,7 +243,7 @@ static void serial_close(struct tty_stru
414 - dbg("%s - port %d", __FUNCTION__, port->number);
415 + dbg("port %d", port->number);
417 mutex_lock(&port->mutex);
419 @@ -279,10 +279,10 @@ static int serial_write (struct tty_stru
423 - dbg("%s - port %d, %d byte(s)", __FUNCTION__, port->number, count);
424 + dbg("port %d, %d byte(s)", port->number, count);
426 if (!port->open_count) {
427 - dbg("%s - port not opened", __FUNCTION__);
428 + dbg("port not opened");
432 @@ -301,10 +301,10 @@ static int serial_write_room (struct tty
436 - dbg("%s - port %d", __FUNCTION__, port->number);
437 + dbg("port %d", port->number);
439 if (!port->open_count) {
440 - dbg("%s - port not open", __FUNCTION__);
441 + dbg("port not open");
445 @@ -323,10 +323,10 @@ static int serial_chars_in_buffer (struc
449 - dbg("%s = port %d", __FUNCTION__, port->number);
450 + dbg("port %d", port->number);
452 if (!port->open_count) {
453 - dbg("%s - port not open", __FUNCTION__);
454 + dbg("port not open");
458 @@ -344,10 +344,10 @@ static void serial_throttle (struct tty_
462 - dbg("%s - port %d", __FUNCTION__, port->number);
463 + dbg("port %d", port->number);
465 if (!port->open_count) {
466 - dbg ("%s - port not open", __FUNCTION__);
467 + dbg ("port not open");
471 @@ -363,10 +363,10 @@ static void serial_unthrottle (struct tt
475 - dbg("%s - port %d", __FUNCTION__, port->number);
476 + dbg("port %d", port->number);
478 if (!port->open_count) {
479 - dbg("%s - port not open", __FUNCTION__);
480 + dbg("port not open");
484 @@ -383,10 +383,10 @@ static int serial_ioctl (struct tty_stru
488 - dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd);
489 + dbg("port %d, cmd 0x%.4x", port->number, cmd);
491 if (!port->open_count) {
492 - dbg ("%s - port not open", __FUNCTION__);
493 + dbg ("port not open");
497 @@ -407,10 +407,10 @@ static void serial_set_termios (struct t
501 - dbg("%s - port %d", __FUNCTION__, port->number);
502 + dbg("port %d", port->number);
504 if (!port->open_count) {
505 - dbg("%s - port not open", __FUNCTION__);
506 + dbg("port not open");
510 @@ -426,10 +426,10 @@ static void serial_break (struct tty_str
514 - dbg("%s - port %d", __FUNCTION__, port->number);
515 + dbg("port %d", port->number);
517 if (!port->open_count) {
518 - dbg("%s - port not open", __FUNCTION__);
519 + dbg("port not open");
523 @@ -446,7 +446,7 @@ static int serial_read_proc (char *page,
527 - dbg("%s", __FUNCTION__);
529 length += sprintf (page, "usbserinfo:1.0 driver:2.0\n");
530 for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) {
531 serial = usb_serial_get_by_index(i);
532 @@ -490,10 +490,10 @@ static int serial_tiocmget (struct tty_s
536 - dbg("%s - port %d", __FUNCTION__, port->number);
537 + dbg("port %d", port->number);
539 if (!port->open_count) {
540 - dbg("%s - port not open", __FUNCTION__);
541 + dbg("port not open");
545 @@ -512,10 +512,10 @@ static int serial_tiocmset (struct tty_s
549 - dbg("%s - port %d", __FUNCTION__, port->number);
550 + dbg("port %d", port->number);
552 if (!port->open_count) {
553 - dbg("%s - port not open", __FUNCTION__);
554 + dbg("port not open");
558 @@ -531,7 +531,7 @@ void usb_serial_port_softint(void *priva
559 struct usb_serial_port *port = private;
560 struct tty_struct *tty;
562 - dbg("%s - port %d", __FUNCTION__, port->number);
563 + dbg("port %d", port->number);
567 @@ -547,7 +547,7 @@ static void port_release(struct device *
569 struct usb_serial_port *port = to_usb_serial_port(dev);
571 - dbg ("%s - %s", __FUNCTION__, dev->bus_id);
572 + dbg ("%s", dev->bus_id);
573 usb_kill_urb(port->read_urb);
574 usb_free_urb(port->read_urb);
575 usb_kill_urb(port->write_urb);
576 @@ -780,7 +780,7 @@ #endif
577 max_endpoints = max(max_endpoints, num_interrupt_out);
578 max_endpoints = max(max_endpoints, (int)serial->num_ports);
579 serial->num_port_pointers = max_endpoints;
580 - dbg("%s - setting up %d port structures for this device", __FUNCTION__, max_endpoints);
581 + dbg("setting up %d port structures for this device", max_endpoints);
582 for (i = 0; i < max_endpoints; ++i) {
583 port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL);
585 @@ -923,7 +923,7 @@ #endif
586 port->dev.release = &port_release;
588 snprintf (&port->dev.bus_id[0], sizeof(port->dev.bus_id), "ttyUSB%d", port->number);
589 - dbg ("%s - registering %s", __FUNCTION__, port->dev.bus_id);
590 + dbg ("registering %s", port->dev.bus_id);
591 device_register (&port->dev);
594 @@ -985,7 +985,7 @@ void usb_serial_disconnect(struct usb_in
595 struct device *dev = &interface->dev;
596 struct usb_serial_port *port;
598 - dbg ("%s", __FUNCTION__);
601 usb_set_intfdata (interface, NULL);
603 diff --git a/drivers/usb/serial/usb-serial.h b/drivers/usb/serial/usb-serial.h
604 index dc89d87..af58879 100644
605 --- a/drivers/usb/serial/usb-serial.h
606 +++ b/drivers/usb/serial/usb-serial.h
607 @@ -290,9 +290,11 @@ static inline void usb_serial_debug_data
609 /* Use our own dbg macro */
611 -#define dbg(format, arg...) do { if (debug) printk(KERN_DEBUG "%s: " format "\n" , __FILE__ , ## arg); } while (0)
614 +#define dbg(format, arg...) do { \
616 + printk(KERN_DEBUG "[USBSERIAL] %s: " format "\n", \
617 + __FUNCTION__, ##arg); \
620 #endif /* ifdef __LINUX_USB_SERIAL_H */