USB: replace remaining __FUNCTION__ occurrences
[linux-2.6.git] / drivers / usb / serial / pl2303.c
index fd8c09f..2b4ab37 100644 (file)
@@ -55,6 +55,7 @@ static struct usb_device_id id_table [] = {
        { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_DCU11) },
        { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ3) },
        { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_PHAROS) },
+       { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_ALDIGA) },
        { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) },
        { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID_RSAQ5) },
        { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID) },
@@ -99,7 +100,10 @@ static struct usb_driver pl2303_driver = {
        .probe =        usb_serial_probe,
        .disconnect =   usb_serial_disconnect,
        .id_table =     id_table,
+       .suspend =      usb_serial_suspend,
+       .resume =       usb_serial_resume,
        .no_dynamic_id =        1,
+       .supports_autosuspend = 1,
 };
 
 #define SET_LINE_REQUEST_TYPE          0x21
@@ -338,8 +342,13 @@ static int pl2303_startup(struct usb_serial *serial)
 {
        struct pl2303_private *priv;
        enum pl2303_type type = type_0;
+       unsigned char *buf;
        int i;
 
+       buf = kmalloc(10, GFP_KERNEL);
+       if (buf == NULL)
+               return -ENOMEM;
+
        if (serial->dev->descriptor.bDeviceClass == 0x02)
                type = type_0;
        else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40)
@@ -364,9 +373,27 @@ static int pl2303_startup(struct usb_serial *serial)
                priv->type = type;
                usb_set_serial_port_data(serial->port[i], priv);
        }
+
+       pl2303_vendor_read(0x8484, 0, serial, buf);
+       pl2303_vendor_write(0x0404, 0, serial);
+       pl2303_vendor_read(0x8484, 0, serial, buf);
+       pl2303_vendor_read(0x8383, 0, serial, buf);
+       pl2303_vendor_read(0x8484, 0, serial, buf);
+       pl2303_vendor_write(0x0404, 1, serial);
+       pl2303_vendor_read(0x8484, 0, serial, buf);
+       pl2303_vendor_read(0x8383, 0, serial, buf);
+       pl2303_vendor_write(0, 1, serial);
+       pl2303_vendor_write(1, 0, serial);
+       if (type == HX)
+               pl2303_vendor_write(2, 0x44, serial);
+       else
+               pl2303_vendor_write(2, 0x24, serial);
+
+       kfree(buf);
        return 0;
 
 cleanup:
+       kfree(buf);
        for (--i; i>=0; --i) {
                priv = usb_get_serial_port_data(serial->port[i]);
                pl2303_buf_free(priv->buf);
@@ -383,7 +410,7 @@ static int set_control_lines(struct usb_device *dev, u8 value)
        retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
                                 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE,
                                 value, 0, NULL, 0, 100);
-       dbg("%s - value = %d, retval = %d", __FUNCTION__, value, retval);
+       dbg("%s - value = %d, retval = %d", __func__, value, retval);
        return retval;
 }
 
@@ -393,7 +420,7 @@ static void pl2303_send(struct usb_serial_port *port)
        struct pl2303_private *priv = usb_get_serial_port_data(port);
        unsigned long flags;
 
-       dbg("%s - port %d", __FUNCTION__, port->number);
+       dbg("%s - port %d", __func__, port->number);
 
        spin_lock_irqsave(&priv->lock, flags);
 
@@ -414,7 +441,7 @@ static void pl2303_send(struct usb_serial_port *port)
 
        spin_unlock_irqrestore(&priv->lock, flags);
 
-       usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count,
+       usb_serial_debug_data(debug, &port->dev, __func__, count,
                              port->write_urb->transfer_buffer);
 
        port->write_urb->transfer_buffer_length = count;
@@ -422,7 +449,7 @@ static void pl2303_send(struct usb_serial_port *port)
        result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
        if (result) {
                dev_err(&port->dev, "%s - failed submitting write urb,"
-                       " error %d\n", __FUNCTION__, result);
+                       " error %d\n", __func__, result);
                priv->write_urb_in_use = 0;
                // TODO: reschedule pl2303_send
        }
@@ -436,7 +463,7 @@ static int pl2303_write(struct usb_serial_port *port, const unsigned char *buf,
        struct pl2303_private *priv = usb_get_serial_port_data(port);
        unsigned long flags;
 
-       dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count);
+       dbg("%s - port %d, %d bytes", __func__, port->number, count);
 
        if (!count)
                return count;
@@ -456,13 +483,13 @@ static int pl2303_write_room(struct usb_serial_port *port)
        int room = 0;
        unsigned long flags;
 
-       dbg("%s - port %d", __FUNCTION__, port->number);
+       dbg("%s - port %d", __func__, port->number);
 
        spin_lock_irqsave(&priv->lock, flags);
        room = pl2303_buf_space_avail(priv->buf);
        spin_unlock_irqrestore(&priv->lock, flags);
 
-       dbg("%s - returns %d", __FUNCTION__, room);
+       dbg("%s - returns %d", __func__, room);
        return room;
 }
 
@@ -472,13 +499,13 @@ static int pl2303_chars_in_buffer(struct usb_serial_port *port)
        int chars = 0;
        unsigned long flags;
 
-       dbg("%s - port %d", __FUNCTION__, port->number);
+       dbg("%s - port %d", __func__, port->number);
 
        spin_lock_irqsave(&priv->lock, flags);
        chars = pl2303_buf_data_avail(priv->buf);
        spin_unlock_irqrestore(&priv->lock, flags);
 
-       dbg("%s - returns %d", __FUNCTION__, chars);
+       dbg("%s - returns %d", __func__, chars);
        return chars;
 }
 
@@ -494,7 +521,7 @@ static void pl2303_set_termios(struct usb_serial_port *port,
        int i;
        u8 control;
 
-       dbg("%s -  port %d", __FUNCTION__, port->number);
+       dbg("%s -  port %d", __func__, port->number);
 
        spin_lock_irqsave(&priv->lock, flags);
        if (!priv->termios_initialized) {
@@ -518,7 +545,7 @@ static void pl2303_set_termios(struct usb_serial_port *port,
 
        buf = kzalloc(7, GFP_KERNEL);
        if (!buf) {
-               dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__);
+               dev_err(&port->dev, "%s - out of memory.\n", __func__);
                return;
        }
 
@@ -536,11 +563,11 @@ static void pl2303_set_termios(struct usb_serial_port *port,
                        default:
                        case CS8:       buf[6] = 8;     break;
                }
-               dbg("%s - data bits = %d", __FUNCTION__, buf[6]);
+               dbg("%s - data bits = %d", __func__, buf[6]);
        }
 
        baud = tty_get_baud_rate(port->tty);;
-       dbg("%s - baud = %d", __FUNCTION__, baud);
+       dbg("%s - baud = %d", __func__, baud);
        if (baud) {
                buf[0] = baud & 0xff;
                buf[1] = (baud >> 8) & 0xff;
@@ -553,10 +580,10 @@ static void pl2303_set_termios(struct usb_serial_port *port,
        /* For reference buf[4]=2 is 2 stop bits */
        if (cflag & CSTOPB) {
                buf[4] = 2;
-               dbg("%s - stop bits = 2", __FUNCTION__);
+               dbg("%s - stop bits = 2", __func__);
        } else {
                buf[4] = 0;
-               dbg("%s - stop bits = 1", __FUNCTION__);
+               dbg("%s - stop bits = 1", __func__);
        }
 
        if (cflag & PARENB) {
@@ -567,14 +594,14 @@ static void pl2303_set_termios(struct usb_serial_port *port,
                /* For reference buf[5]=4 is space parity */
                if (cflag & PARODD) {
                        buf[5] = 1;
-                       dbg("%s - parity = odd", __FUNCTION__);
+                       dbg("%s - parity = odd", __func__);
                } else {
                        buf[5] = 2;
-                       dbg("%s - parity = even", __FUNCTION__);
+                       dbg("%s - parity = even", __func__);
                }
        } else {
                buf[5] = 0;
-               dbg("%s - parity = none", __FUNCTION__);
+               dbg("%s - parity = none", __func__);
        }
 
        i = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
@@ -630,7 +657,7 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
        long timeout;
        wait_queue_t wait;
 
-       dbg("%s - port %d", __FUNCTION__, port->number);
+       dbg("%s - port %d", __func__, port->number);
 
        /* wait for data to drain from the buffer */
        spin_lock_irqsave(&priv->lock, flags);
@@ -641,7 +668,7 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
                set_current_state(TASK_INTERRUPTIBLE);
                if (pl2303_buf_data_avail(priv->buf) == 0 ||
                    timeout == 0 || signal_pending(current) ||
-                   !usb_get_intfdata(port->serial->interface)) /* disconnect */
+                   port->serial->disconnected)
                        break;
                spin_unlock_irqrestore(&priv->lock, flags);
                timeout = schedule_timeout(timeout);
@@ -668,7 +695,7 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
        schedule_timeout_interruptible(timeout);
 
        /* shutdown our urbs */
-       dbg("%s - shutting down urbs", __FUNCTION__);
+       dbg("%s - shutting down urbs", __func__);
        usb_kill_urb(port->write_urb);
        usb_kill_urb(port->read_urb);
        usb_kill_urb(port->interrupt_in_urb);
@@ -690,43 +717,19 @@ static int pl2303_open(struct usb_serial_port *port, struct file *filp)
        struct ktermios tmp_termios;
        struct usb_serial *serial = port->serial;
        struct pl2303_private *priv = usb_get_serial_port_data(port);
-       unsigned char *buf;
        int result;
 
-       dbg("%s -  port %d", __FUNCTION__, port->number);
+       dbg("%s -  port %d", __func__, port->number);
 
        if (priv->type != HX) {
                usb_clear_halt(serial->dev, port->write_urb->pipe);
                usb_clear_halt(serial->dev, port->read_urb->pipe);
-       }
-
-       buf = kmalloc(10, GFP_KERNEL);
-       if (buf==NULL)
-               return -ENOMEM;
-
-       pl2303_vendor_read(0x8484, 0, serial, buf);
-       pl2303_vendor_write(0x0404, 0, serial);
-       pl2303_vendor_read(0x8484, 0, serial, buf);
-       pl2303_vendor_read(0x8383, 0, serial, buf);
-       pl2303_vendor_read(0x8484, 0, serial, buf);
-       pl2303_vendor_write(0x0404, 1, serial);
-       pl2303_vendor_read(0x8484, 0, serial, buf);
-       pl2303_vendor_read(0x8383, 0, serial, buf);
-       pl2303_vendor_write(0, 1, serial);
-       pl2303_vendor_write(1, 0, serial);
-
-       if (priv->type == HX) {
-               /* HX chip */
-               pl2303_vendor_write(2, 0x44, serial);
+       } else {
                /* reset upstream data pipes */
                pl2303_vendor_write(8, 0, serial);
                pl2303_vendor_write(9, 0, serial);
-       } else {
-               pl2303_vendor_write(2, 0x24, serial);
        }
 
-       kfree(buf);
-
        /* Setup termios */
        if (port->tty) {
                pl2303_set_termios(port, &tmp_termios);
@@ -734,22 +737,22 @@ static int pl2303_open(struct usb_serial_port *port, struct file *filp)
 
        //FIXME: need to assert RTS and DTR if CRTSCTS off
 
-       dbg("%s - submitting read urb", __FUNCTION__);
+       dbg("%s - submitting read urb", __func__);
        port->read_urb->dev = serial->dev;
        result = usb_submit_urb(port->read_urb, GFP_KERNEL);
        if (result) {
                dev_err(&port->dev, "%s - failed submitting read urb,"
-                       " error %d\n", __FUNCTION__, result);
+                       " error %d\n", __func__, result);
                pl2303_close(port, NULL);
                return -EPROTO;
        }
 
-       dbg("%s - submitting interrupt urb", __FUNCTION__);
+       dbg("%s - submitting interrupt urb", __func__);
        port->interrupt_in_urb->dev = serial->dev;
        result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
        if (result) {
                dev_err(&port->dev, "%s - failed submitting interrupt urb,"
-                       " error %d\n", __FUNCTION__, result);
+                       " error %d\n", __func__, result);
                pl2303_close(port, NULL);
                return -EPROTO;
        }
@@ -789,7 +792,7 @@ static int pl2303_tiocmget(struct usb_serial_port *port, struct file *file)
        unsigned int status;
        unsigned int result;
 
-       dbg("%s (%d)", __FUNCTION__, port->number);
+       dbg("%s (%d)", __func__, port->number);
 
        if (!usb_get_intfdata(port->serial->interface))
                return -ENODEV;
@@ -806,7 +809,7 @@ static int pl2303_tiocmget(struct usb_serial_port *port, struct file *file)
                  | ((status & UART_RING)       ? TIOCM_RI  : 0)
                  | ((status & UART_DCD)        ? TIOCM_CD  : 0);
 
-       dbg("%s - result = %x", __FUNCTION__, result);
+       dbg("%s - result = %x", __func__, result);
 
        return result;
 }
@@ -850,15 +853,15 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
 static int pl2303_ioctl(struct usb_serial_port *port, struct file *file,
                        unsigned int cmd, unsigned long arg)
 {
-       dbg("%s (%d) cmd = 0x%04x", __FUNCTION__, port->number, cmd);
+       dbg("%s (%d) cmd = 0x%04x", __func__, port->number, cmd);
 
        switch (cmd) {
                case TIOCMIWAIT:
-                       dbg("%s (%d) TIOCMIWAIT", __FUNCTION__,  port->number);
+                       dbg("%s (%d) TIOCMIWAIT", __func__,  port->number);
                        return wait_modem_info(port, arg);
 
                default:
-                       dbg("%s not supported = 0x%04x", __FUNCTION__, cmd);
+                       dbg("%s not supported = 0x%04x", __func__, cmd);
                        break;
        }
 
@@ -871,19 +874,19 @@ static void pl2303_break_ctl(struct usb_serial_port *port, int break_state)
        u16 state;
        int result;
 
-       dbg("%s - port %d", __FUNCTION__, port->number);
+       dbg("%s - port %d", __func__, port->number);
 
        if (break_state == 0)
                state = BREAK_OFF;
        else
                state = BREAK_ON;
-       dbg("%s - turning break %s", __FUNCTION__, state==BREAK_OFF ? "off" : "on");
+       dbg("%s - turning break %s", __func__, state==BREAK_OFF ? "off" : "on");
 
        result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
                                 BREAK_REQUEST, BREAK_REQUEST_TYPE, state,
                                 0, NULL, 0, 100);
        if (result)
-               dbg("%s - error sending break = %d", __FUNCTION__, result);
+               dbg("%s - error sending break = %d", __func__, result);
 }
 
 static void pl2303_shutdown(struct usb_serial *serial)
@@ -891,7 +894,7 @@ static void pl2303_shutdown(struct usb_serial *serial)
        int i;
        struct pl2303_private *priv;
 
-       dbg("%s", __FUNCTION__);
+       dbg("%s", __func__);
 
        for (i = 0; i < serial->num_ports; ++i) {
                priv = usb_get_serial_port_data(serial->port[i]);
@@ -946,7 +949,7 @@ static void pl2303_read_int_callback(struct urb *urb)
        int status = urb->status;
        int retval;
 
-       dbg("%s (%d)", __FUNCTION__, port->number);
+       dbg("%s (%d)", __func__, port->number);
 
        switch (status) {
        case 0:
@@ -956,16 +959,16 @@ static void pl2303_read_int_callback(struct urb *urb)
        case -ENOENT:
        case -ESHUTDOWN:
                /* this urb is terminated, clean up */
-               dbg("%s - urb shutting down with status: %d", __FUNCTION__,
+               dbg("%s - urb shutting down with status: %d", __func__,
                    status);
                return;
        default:
-               dbg("%s - nonzero urb status received: %d", __FUNCTION__,
+               dbg("%s - nonzero urb status received: %d", __func__,
                    status);
                goto exit;
        }
 
-       usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
+       usb_serial_debug_data(debug, &port->dev, __func__,
                              urb->actual_length, urb->transfer_buffer);
 
        pl2303_update_line_status(port, data, actual_length);
@@ -975,7 +978,7 @@ exit:
        if (retval)
                dev_err(&urb->dev->dev,
                        "%s - usb_submit_urb failed with result %d\n",
-                       __FUNCTION__, retval);
+                       __func__, retval);
 }
 
 static void pl2303_read_bulk_callback(struct urb *urb)
@@ -991,32 +994,32 @@ static void pl2303_read_bulk_callback(struct urb *urb)
        u8 line_status;
        char tty_flag;
 
-       dbg("%s - port %d", __FUNCTION__, port->number);
+       dbg("%s - port %d", __func__, port->number);
 
        if (status) {
-               dbg("%s - urb status = %d", __FUNCTION__, status);
+               dbg("%s - urb status = %d", __func__, status);
                if (!port->open_count) {
-                       dbg("%s - port is closed, exiting.", __FUNCTION__);
+                       dbg("%s - port is closed, exiting.", __func__);
                        return;
                }
                if (status == -EPROTO) {
                        /* PL2303 mysteriously fails with -EPROTO reschedule
                         * the read */
                        dbg("%s - caught -EPROTO, resubmitting the urb",
-                           __FUNCTION__);
+                           __func__);
                        urb->dev = port->serial->dev;
                        result = usb_submit_urb(urb, GFP_ATOMIC);
                        if (result)
                                dev_err(&urb->dev->dev, "%s - failed"
                                        " resubmitting read urb, error %d\n",
-                                       __FUNCTION__, result);
+                                       __func__, result);
                        return;
                }
-               dbg("%s - unable to handle the error, exiting.", __FUNCTION__);
+               dbg("%s - unable to handle the error, exiting.", __func__);
                return;
        }
 
-       usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
+       usb_serial_debug_data(debug, &port->dev, __func__,
                              urb->actual_length, data);
 
        /* get tty_flag from status */
@@ -1036,7 +1039,7 @@ static void pl2303_read_bulk_callback(struct urb *urb)
                tty_flag = TTY_PARITY;
        else if (line_status & UART_FRAME_ERROR)
                tty_flag = TTY_FRAME;
-       dbg("%s - tty_flag = %d", __FUNCTION__, tty_flag);
+       dbg("%s - tty_flag = %d", __func__, tty_flag);
 
        tty = port->tty;
        if (tty && urb->actual_length) {
@@ -1055,7 +1058,7 @@ static void pl2303_read_bulk_callback(struct urb *urb)
                result = usb_submit_urb(urb, GFP_ATOMIC);
                if (result)
                        dev_err(&urb->dev->dev, "%s - failed resubmitting"
-                               " read urb, error %d\n", __FUNCTION__, result);
+                               " read urb, error %d\n", __func__, result);
        }
 
        return;
@@ -1068,7 +1071,7 @@ static void pl2303_write_bulk_callback(struct urb *urb)
        int result;
        int status = urb->status;
 
-       dbg("%s - port %d", __FUNCTION__, port->number);
+       dbg("%s - port %d", __func__, port->number);
 
        switch (status) {
        case 0:
@@ -1078,21 +1081,21 @@ static void pl2303_write_bulk_callback(struct urb *urb)
        case -ENOENT:
        case -ESHUTDOWN:
                /* this urb is terminated, clean up */
-               dbg("%s - urb shutting down with status: %d", __FUNCTION__,
+               dbg("%s - urb shutting down with status: %d", __func__,
                    status);
                priv->write_urb_in_use = 0;
                return;
        default:
                /* error in the urb, so we have to resubmit it */
-               dbg("%s - Overflow in write", __FUNCTION__);
-               dbg("%s - nonzero write bulk status received: %d", __FUNCTION__,
+               dbg("%s - Overflow in write", __func__);
+               dbg("%s - nonzero write bulk status received: %d", __func__,
                    status);
                port->write_urb->transfer_buffer_length = 1;
                port->write_urb->dev = port->serial->dev;
                result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
                if (result)
                        dev_err(&urb->dev->dev, "%s - failed resubmitting write"
-                               " urb, error %d\n", __FUNCTION__, result);
+                               " urb, error %d\n", __func__, result);
                else
                        return;
        }
@@ -1111,9 +1114,6 @@ static struct usb_serial_driver pl2303_device = {
        },
        .id_table =             id_table,
        .usb_driver =           &pl2303_driver,
-       .num_interrupt_in =     NUM_DONT_CARE,
-       .num_bulk_in =          1,
-       .num_bulk_out =         1,
        .num_ports =            1,
        .open =                 pl2303_open,
        .close =                pl2303_close,