diff options
Diffstat (limited to 'drivers/usb/serial/iuu_phoenix.c')
-rw-r--r-- | drivers/usb/serial/iuu_phoenix.c | 218 |
1 files changed, 96 insertions, 122 deletions
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c index 22b1eb5040b7..cd5533e81de7 100644 --- a/drivers/usb/serial/iuu_phoenix.c +++ b/drivers/usb/serial/iuu_phoenix.c @@ -32,13 +32,6 @@ #include "iuu_phoenix.h" #include <linux/random.h> - -#ifdef CONFIG_USB_SERIAL_DEBUG -static bool debug = 1; -#else -static bool debug; -#endif - /* * Version Information */ @@ -60,6 +53,8 @@ static int iuu_cardout; static bool xmas; static int vcc_default = 5; +static int iuu_create_sysfs_attrs(struct usb_serial_port *port); +static int iuu_remove_sysfs_attrs(struct usb_serial_port *port); static void read_rxcmd_callback(struct urb *urb); struct iuu_private { @@ -72,7 +67,6 @@ struct iuu_private { u8 *writebuf; /* buffer for writing to device */ int writelen; /* num of byte to write to device */ u8 *buf; /* used for initialize speed */ - u8 *dbgbuf; /* debug buffer */ u8 len; int vcc; /* vcc (either 3 or 5 V) */ u32 baud; @@ -80,64 +74,55 @@ struct iuu_private { u32 clk; }; - -static void iuu_free_buf(struct iuu_private *priv) +static int iuu_port_probe(struct usb_serial_port *port) { - kfree(priv->buf); - kfree(priv->dbgbuf); - kfree(priv->writebuf); -} + struct iuu_private *priv; + int ret; + + priv = kzalloc(sizeof(struct iuu_private), GFP_KERNEL); + if (!priv) + return -ENOMEM; -static int iuu_alloc_buf(struct iuu_private *priv) -{ priv->buf = kzalloc(256, GFP_KERNEL); - priv->dbgbuf = kzalloc(256, GFP_KERNEL); - priv->writebuf = kzalloc(256, GFP_KERNEL); - if (!priv->buf || !priv->dbgbuf || !priv->writebuf) { - iuu_free_buf(priv); - dbg("%s problem allocation buffer", __func__); + if (!priv->buf) { + kfree(priv); return -ENOMEM; } - dbg("%s - Privates buffers allocation success", __func__); - return 0; -} -static int iuu_startup(struct usb_serial *serial) -{ - struct iuu_private *priv; - priv = kzalloc(sizeof(struct iuu_private), GFP_KERNEL); - dbg("%s- priv allocation success", __func__); - if (!priv) - return -ENOMEM; - if (iuu_alloc_buf(priv)) { + priv->writebuf = kzalloc(256, GFP_KERNEL); + if (!priv->writebuf) { + kfree(priv->buf); kfree(priv); return -ENOMEM; } + priv->vcc = vcc_default; spin_lock_init(&priv->lock); init_waitqueue_head(&priv->delta_msr_wait); - usb_set_serial_port_data(serial->port[0], priv); + + usb_set_serial_port_data(port, priv); + + ret = iuu_create_sysfs_attrs(port); + if (ret) { + kfree(priv->writebuf); + kfree(priv->buf); + kfree(priv); + return ret; + } + return 0; } -/* Release function */ -static void iuu_release(struct usb_serial *serial) +static int iuu_port_remove(struct usb_serial_port *port) { - struct usb_serial_port *port = serial->port[0]; struct iuu_private *priv = usb_get_serial_port_data(port); - if (!port) - return; - - if (priv) { - iuu_free_buf(priv); - dbg("%s - I will free all", __func__); - usb_set_serial_port_data(port, NULL); - dbg("%s - priv is not anymore in port structure", __func__); - kfree(priv); + iuu_remove_sysfs_attrs(port); + kfree(priv->writebuf); + kfree(priv->buf); + kfree(priv); - dbg("%s priv is now kfree", __func__); - } + return 0; } static int iuu_tiocmset(struct tty_struct *tty, @@ -148,13 +133,13 @@ static int iuu_tiocmset(struct tty_struct *tty, unsigned long flags; /* FIXME: locking on tiomstatus */ - dbg("%s (%d) msg : SET = 0x%04x, CLEAR = 0x%04x ", __func__, - port->number, set, clear); + dev_dbg(&port->dev, "%s msg : SET = 0x%04x, CLEAR = 0x%04x\n", + __func__, set, clear); spin_lock_irqsave(&priv->lock, flags); if ((set & TIOCM_RTS) && !(priv->tiostatus == TIOCM_RTS)) { - dbg("%s TIOCMSET RESET called !!!", __func__); + dev_dbg(&port->dev, "%s TIOCMSET RESET called !!!\n", __func__); priv->reset = 1; } if (set & TIOCM_RTS) @@ -190,7 +175,7 @@ static void iuu_rxcmd(struct urb *urb) int status = urb->status; if (status) { - dbg("%s - status = %d", __func__, status); + dev_dbg(&port->dev, "%s - status = %d\n", __func__, status); /* error stop all */ return; } @@ -244,13 +229,13 @@ static void iuu_update_status_callback(struct urb *urb) int status = urb->status; if (status) { - dbg("%s - status = %d", __func__, status); + dev_dbg(&port->dev, "%s - status = %d\n", __func__, status); /* error stop all */ return; } st = urb->transfer_buffer; - dbg("%s - enter", __func__); + dev_dbg(&port->dev, "%s - enter\n", __func__); if (urb->actual_length == 1) { switch (st[0]) { case 0x1: @@ -272,7 +257,7 @@ static void iuu_status_callback(struct urb *urb) int result; int status = urb->status; - dbg("%s - status = %d", __func__, status); + dev_dbg(&port->dev, "%s - status = %d\n", __func__, status); usb_fill_bulk_urb(port->read_urb, port->serial->dev, usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress), @@ -311,9 +296,9 @@ static int bulk_immediate(struct usb_serial_port *port, u8 *buf, u8 count) count, &actual, HZ * 1); if (status != IUU_OPERATION_OK) - dbg("%s - error = %2x", __func__, status); + dev_dbg(&port->dev, "%s - error = %2x\n", __func__, status); else - dbg("%s - write OK !", __func__); + dev_dbg(&port->dev, "%s - write OK !\n", __func__); return status; } @@ -331,9 +316,9 @@ static int read_immediate(struct usb_serial_port *port, u8 *buf, u8 count) count, &actual, HZ * 1); if (status != IUU_OPERATION_OK) - dbg("%s - error = %2x", __func__, status); + dev_dbg(&port->dev, "%s - error = %2x\n", __func__, status); else - dbg("%s - read OK !", __func__); + dev_dbg(&port->dev, "%s - read OK !\n", __func__); return status; } @@ -357,9 +342,9 @@ static int iuu_led(struct usb_serial_port *port, unsigned int R, status = bulk_immediate(port, buf, 8); kfree(buf); if (status != IUU_OPERATION_OK) - dbg("%s - led error status = %2x", __func__, status); + dev_dbg(&port->dev, "%s - led error status = %2x\n", __func__, status); else - dbg("%s - led OK !", __func__); + dev_dbg(&port->dev, "%s - led OK !\n", __func__); return IUU_OPERATION_OK; } @@ -445,7 +430,7 @@ static int iuu_clk(struct usb_serial_port *port, int dwFrq) status = bulk_immediate(port, (u8 *) priv->buf, Count); if (status != 0) { - dbg("%s - write error ", __func__); + dev_dbg(&port->dev, "%s - write error\n", __func__); return status; } } else if (frq == 3579000) { @@ -554,12 +539,13 @@ static int iuu_clk(struct usb_serial_port *port, int dwFrq) status = bulk_immediate(port, (u8 *) priv->buf, Count); if (status != IUU_OPERATION_OK) - dbg("%s - write error ", __func__); + dev_dbg(&port->dev, "%s - write error\n", __func__); return status; } static int iuu_uart_flush(struct usb_serial_port *port) { + struct device *dev = &port->dev; int i; int status; u8 rxcmd = IUU_UART_RX; @@ -571,27 +557,26 @@ static int iuu_uart_flush(struct usb_serial_port *port) for (i = 0; i < 2; i++) { status = bulk_immediate(port, &rxcmd, 1); if (status != IUU_OPERATION_OK) { - dbg("%s - uart_flush_write error", __func__); + dev_dbg(dev, "%s - uart_flush_write error\n", __func__); return status; } status = read_immediate(port, &priv->len, 1); if (status != IUU_OPERATION_OK) { - dbg("%s - uart_flush_read error", __func__); + dev_dbg(dev, "%s - uart_flush_read error\n", __func__); return status; } if (priv->len > 0) { - dbg("%s - uart_flush datalen is : %i ", __func__, - priv->len); + dev_dbg(dev, "%s - uart_flush datalen is : %i\n", __func__, priv->len); status = read_immediate(port, priv->buf, priv->len); if (status != IUU_OPERATION_OK) { - dbg("%s - uart_flush_read error", __func__); + dev_dbg(dev, "%s - uart_flush_read error\n", __func__); return status; } } } - dbg("%s - uart_flush_read OK!", __func__); + dev_dbg(dev, "%s - uart_flush_read OK!\n", __func__); iuu_led(port, 0, 0xF000, 0, 0xFF); return status; } @@ -610,10 +595,10 @@ static void read_buf_callback(struct urb *urb) return; } - dbg("%s - %i chars to write", __func__, urb->actual_length); + dev_dbg(&port->dev, "%s - %i chars to write\n", __func__, urb->actual_length); tty = tty_port_tty_get(&port->port); if (data == NULL) - dbg("%s - data is NULL !!!", __func__); + dev_dbg(&port->dev, "%s - data is NULL !!!\n", __func__); if (tty && urb->actual_length && data) { tty_insert_flip_string(tty, data, urb->actual_length); tty_flip_buffer_push(tty); @@ -627,7 +612,6 @@ static int iuu_bulk_write(struct usb_serial_port *port) struct iuu_private *priv = usb_get_serial_port_data(port); unsigned long flags; int result; - int i; int buf_len; char *buf_ptr = port->write_urb->transfer_buffer; @@ -640,14 +624,8 @@ static int iuu_bulk_write(struct usb_serial_port *port) buf_len = priv->writelen; priv->writelen = 0; spin_unlock_irqrestore(&priv->lock, flags); - if (debug == 1) { - for (i = 0; i < buf_len; i++) - sprintf(priv->dbgbuf + i*2 , - "%02X", priv->writebuf[i]); - priv->dbgbuf[buf_len+i*2] = 0; - dbg("%s - writing %i chars : %s", __func__, - buf_len, priv->dbgbuf); - } + dev_dbg(&port->dev, "%s - writing %i chars : %*ph\n", __func__, + buf_len, buf_len, buf_ptr); usb_fill_bulk_urb(port->write_urb, port->serial->dev, usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress), @@ -683,18 +661,18 @@ static void iuu_uart_read_callback(struct urb *urb) priv->poll++; if (status) { - dbg("%s - status = %d", __func__, status); + dev_dbg(&port->dev, "%s - status = %d\n", __func__, status); /* error stop all */ return; } if (data == NULL) - dbg("%s - data is NULL !!!", __func__); + dev_dbg(&port->dev, "%s - data is NULL !!!\n", __func__); if (urb->actual_length == 1 && data != NULL) len = (int) data[0]; if (urb->actual_length > 1) { - dbg("%s - urb->actual_length = %i", __func__, + dev_dbg(&port->dev, "%s - urb->actual_length = %i\n", __func__, urb->actual_length); error = 1; return; @@ -702,7 +680,7 @@ static void iuu_uart_read_callback(struct urb *urb) /* if len > 0 call readbuf */ if (len > 0 && error == 0) { - dbg("%s - call read buf - len to read is %i ", + dev_dbg(&port->dev, "%s - call read buf - len to read is %i\n", __func__, len); status = iuu_read_buf(port, len); return; @@ -729,7 +707,7 @@ static void iuu_uart_read_callback(struct urb *urb) } spin_unlock_irqrestore(&priv->lock, flags); /* if nothing to write call again rxcmd */ - dbg("%s - rxcmd recall", __func__); + dev_dbg(&port->dev, "%s - rxcmd recall\n", __func__); iuu_led_activity_off(urb); } @@ -769,7 +747,7 @@ static void read_rxcmd_callback(struct urb *urb) port->read_urb->transfer_buffer, 256, iuu_uart_read_callback, port); result = usb_submit_urb(port->read_urb, GFP_ATOMIC); - dbg("%s - submit result = %d", __func__, result); + dev_dbg(&port->dev, "%s - submit result = %d\n", __func__, result); } static int iuu_uart_on(struct usb_serial_port *port) @@ -789,13 +767,13 @@ static int iuu_uart_on(struct usb_serial_port *port) status = bulk_immediate(port, buf, 4); if (status != IUU_OPERATION_OK) { - dbg("%s - uart_on error", __func__); + dev_dbg(&port->dev, "%s - uart_on error\n", __func__); goto uart_enable_failed; } /* iuu_reset() the card after iuu_uart_on() */ status = iuu_uart_flush(port); if (status != IUU_OPERATION_OK) - dbg("%s - uart_flush error", __func__); + dev_dbg(&port->dev, "%s - uart_flush error\n", __func__); uart_enable_failed: kfree(buf); return status; @@ -813,7 +791,7 @@ static int iuu_uart_off(struct usb_serial_port *port) status = bulk_immediate(port, buf, 1); if (status != IUU_OPERATION_OK) - dbg("%s - uart_off error", __func__); + dev_dbg(&port->dev, "%s - uart_off error\n", __func__); kfree(buf); return status; @@ -830,7 +808,7 @@ static int iuu_uart_baud(struct usb_serial_port *port, u32 baud_base, u8 T1reload = 0; unsigned int T1FrekvensHZ = 0; - dbg("%s - enter baud_base=%d", __func__, baud_base); + dev_dbg(&port->dev, "%s - enter baud_base=%d\n", __func__, baud_base); dataout = kmalloc(sizeof(u8) * 5, GFP_KERNEL); if (!dataout) @@ -911,7 +889,7 @@ static int iuu_uart_baud(struct usb_serial_port *port, u32 baud_base, status = bulk_immediate(port, dataout, DataCount); if (status != IUU_OPERATION_OK) - dbg("%s - uart_off error", __func__); + dev_dbg(&port->dev, "%s - uart_off error\n", __func__); kfree(dataout); return status; } @@ -921,7 +899,7 @@ static void iuu_set_termios(struct tty_struct *tty, { const u32 supported_mask = CMSPAR|PARENB|PARODD; struct iuu_private *priv = usb_get_serial_port_data(port); - unsigned int cflag = tty->termios->c_cflag; + unsigned int cflag = tty->termios.c_cflag; int status; u32 actual; u32 parity; @@ -930,9 +908,9 @@ static void iuu_set_termios(struct tty_struct *tty, u32 newval = cflag & supported_mask; /* Just use the ospeed. ispeed should be the same. */ - baud = tty->termios->c_ospeed; + baud = tty->termios.c_ospeed; - dbg("%s - enter c_ospeed or baud=%d", __func__, baud); + dev_dbg(&port->dev, "%s - enter c_ospeed or baud=%d\n", __func__, baud); /* compute the parity parameter */ parity = 0; @@ -961,13 +939,13 @@ static void iuu_set_termios(struct tty_struct *tty, * settings back over and then adjust them */ if (old_termios) - tty_termios_copy_hw(tty->termios, old_termios); + tty_termios_copy_hw(&tty->termios, old_termios); if (status != 0) /* Set failed - return old bits */ return; /* Re-encode speed, parity and csize */ tty_encode_baud_rate(tty, baud, baud); - tty->termios->c_cflag &= ~(supported_mask|CSIZE); - tty->termios->c_cflag |= newval | csize; + tty->termios.c_cflag &= ~(supported_mask|CSIZE); + tty->termios.c_cflag |= newval | csize; } static void iuu_close(struct usb_serial_port *port) @@ -983,7 +961,7 @@ static void iuu_close(struct usb_serial_port *port) if (serial->dev) { /* free writebuf */ /* shutdown our urbs */ - dbg("%s - shutting down urbs", __func__); + dev_dbg(&port->dev, "%s - shutting down urbs\n", __func__); usb_kill_urb(port->write_urb); usb_kill_urb(port->read_urb); usb_kill_urb(port->interrupt_in_urb); @@ -993,31 +971,32 @@ static void iuu_close(struct usb_serial_port *port) static void iuu_init_termios(struct tty_struct *tty) { - *(tty->termios) = tty_std_termios; - tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600 + tty->termios = tty_std_termios; + tty->termios.c_cflag = CLOCAL | CREAD | CS8 | B9600 | TIOCM_CTS | CSTOPB | PARENB; - tty->termios->c_ispeed = 9600; - tty->termios->c_ospeed = 9600; - tty->termios->c_lflag = 0; - tty->termios->c_oflag = 0; - tty->termios->c_iflag = 0; + tty->termios.c_ispeed = 9600; + tty->termios.c_ospeed = 9600; + tty->termios.c_lflag = 0; + tty->termios.c_oflag = 0; + tty->termios.c_iflag = 0; } static int iuu_open(struct tty_struct *tty, struct usb_serial_port *port) { struct usb_serial *serial = port->serial; + struct device *dev = &port->dev; u8 *buf; int result; int baud; u32 actual; struct iuu_private *priv = usb_get_serial_port_data(port); - baud = tty->termios->c_ospeed; - tty->termios->c_ispeed = baud; + baud = tty->termios.c_ospeed; + tty->termios.c_ispeed = baud; /* Re-encode speed */ tty_encode_baud_rate(tty, baud, baud); - dbg("%s - port %d, baud %d", __func__, port->number, baud); + dev_dbg(dev, "%s - baud %d\n", __func__, baud); usb_clear_halt(serial->dev, port->write_urb->pipe); usb_clear_halt(serial->dev, port->read_urb->pipe); @@ -1032,14 +1011,14 @@ static int iuu_open(struct tty_struct *tty, struct usb_serial_port *port) result = usb_control_msg(port->serial->dev, \ usb_rcvctrlpipe(port->serial->dev, 0), \ b, a, c, d, buf, 1, 1000); \ - dbg("0x%x:0x%x:0x%x:0x%x %d - %x", a, b, c, d, result, \ + dev_dbg(dev, "0x%x:0x%x:0x%x:0x%x %d - %x\n", a, b, c, d, result, \ buf[0]); } while (0); #define SOUP(a, b, c, d) do { \ result = usb_control_msg(port->serial->dev, \ usb_sndctrlpipe(port->serial->dev, 0), \ b, a, c, d, NULL, 0, 1000); \ - dbg("0x%x:0x%x:0x%x:0x%x %d", a, b, c, d, result); } while (0) + dev_dbg(dev, "0x%x:0x%x:0x%x:0x%x %d\n", a, b, c, d, result); } while (0) /* This is not UART related but IUU USB driver related or something */ /* like that. Basically no IUU will accept any commands from the USB */ @@ -1119,7 +1098,7 @@ static int iuu_open(struct tty_struct *tty, struct usb_serial_port *port) iuu_uart_flush(port); - dbg("%s - initialization done", __func__); + dev_dbg(dev, "%s - initialization done\n", __func__); memset(port->write_urb->transfer_buffer, IUU_UART_RX, 1); usb_fill_bulk_urb(port->write_urb, port->serial->dev, @@ -1129,11 +1108,10 @@ static int iuu_open(struct tty_struct *tty, struct usb_serial_port *port) read_rxcmd_callback, port); result = usb_submit_urb(port->write_urb, GFP_KERNEL); if (result) { - dev_err(&port->dev, "%s - failed submitting read urb," - " error %d\n", __func__, result); + dev_err(dev, "%s - failed submitting read urb, error %d\n", __func__, result); iuu_close(port); } else { - dbg("%s - rxcmd OK", __func__); + dev_dbg(dev, "%s - rxcmd OK\n", __func__); } return result; @@ -1159,9 +1137,9 @@ static int iuu_vcc_set(struct usb_serial_port *port, unsigned int vcc) kfree(buf); if (status != IUU_OPERATION_OK) - dbg("%s - vcc error status = %2x", __func__, status); + dev_dbg(&port->dev, "%s - vcc error status = %2x\n", __func__, status); else - dbg("%s - vcc OK !", __func__); + dev_dbg(&port->dev, "%s - vcc OK !\n", __func__); return status; } @@ -1192,7 +1170,7 @@ static ssize_t store_vcc_mode(struct device *dev, goto fail_store_vcc_mode; } - dbg("%s: setting vcc_mode = %ld", __func__, v); + dev_dbg(dev, "%s: setting vcc_mode = %ld", __func__, v); if ((v != 3) && (v != 5)) { dev_err(dev, "%s - vcc_mode %ld is invalid\n", __func__, v); @@ -1231,8 +1209,6 @@ static struct usb_serial_driver iuu_device = { .num_ports = 1, .bulk_in_size = 512, .bulk_out_size = 512, - .port_probe = iuu_create_sysfs_attrs, - .port_remove = iuu_remove_sysfs_attrs, .open = iuu_open, .close = iuu_close, .write = iuu_uart_write, @@ -1241,8 +1217,8 @@ static struct usb_serial_driver iuu_device = { .tiocmset = iuu_tiocmset, .set_termios = iuu_set_termios, .init_termios = iuu_init_termios, - .attach = iuu_startup, - .release = iuu_release, + .port_probe = iuu_port_probe, + .port_remove = iuu_port_remove, }; static struct usb_serial_driver * const serial_drivers[] = { @@ -1257,8 +1233,6 @@ MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL"); MODULE_VERSION(DRIVER_VERSION); -module_param(debug, bool, S_IRUGO | S_IWUSR); -MODULE_PARM_DESC(debug, "Debug enabled or not"); module_param(xmas, bool, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(xmas, "Xmas colors enabled or not"); |