diff options
Diffstat (limited to 'drivers/usb/serial/pl2303.c')
| -rw-r--r-- | drivers/usb/serial/pl2303.c | 827 |
1 files changed, 397 insertions, 430 deletions
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index 65e4d046951a..1036d436ed23 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c | |||
| @@ -81,10 +81,11 @@ static struct usb_device_id id_table [] = { | |||
| 81 | { USB_DEVICE(SPEEDDRAGON_VENDOR_ID, SPEEDDRAGON_PRODUCT_ID) }, | 81 | { USB_DEVICE(SPEEDDRAGON_VENDOR_ID, SPEEDDRAGON_PRODUCT_ID) }, |
| 82 | { USB_DEVICE(DATAPILOT_U2_VENDOR_ID, DATAPILOT_U2_PRODUCT_ID) }, | 82 | { USB_DEVICE(DATAPILOT_U2_VENDOR_ID, DATAPILOT_U2_PRODUCT_ID) }, |
| 83 | { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) }, | 83 | { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) }, |
| 84 | { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) }, | ||
| 84 | { } /* Terminating entry */ | 85 | { } /* Terminating entry */ |
| 85 | }; | 86 | }; |
| 86 | 87 | ||
| 87 | MODULE_DEVICE_TABLE (usb, id_table); | 88 | MODULE_DEVICE_TABLE(usb, id_table); |
| 88 | 89 | ||
| 89 | static struct usb_driver pl2303_driver = { | 90 | static struct usb_driver pl2303_driver = { |
| 90 | .name = "pl2303", | 91 | .name = "pl2303", |
| @@ -127,65 +128,6 @@ static struct usb_driver pl2303_driver = { | |||
| 127 | #define UART_OVERRUN_ERROR 0x40 | 128 | #define UART_OVERRUN_ERROR 0x40 |
| 128 | #define UART_CTS 0x80 | 129 | #define UART_CTS 0x80 |
| 129 | 130 | ||
| 130 | /* function prototypes for a PL2303 serial converter */ | ||
| 131 | static int pl2303_open (struct usb_serial_port *port, struct file *filp); | ||
| 132 | static void pl2303_close (struct usb_serial_port *port, struct file *filp); | ||
| 133 | static void pl2303_set_termios (struct usb_serial_port *port, | ||
| 134 | struct termios *old); | ||
| 135 | static int pl2303_ioctl (struct usb_serial_port *port, struct file *file, | ||
| 136 | unsigned int cmd, unsigned long arg); | ||
| 137 | static void pl2303_read_int_callback (struct urb *urb, struct pt_regs *regs); | ||
| 138 | static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs); | ||
| 139 | static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs); | ||
| 140 | static int pl2303_write (struct usb_serial_port *port, | ||
| 141 | const unsigned char *buf, int count); | ||
| 142 | static void pl2303_send (struct usb_serial_port *port); | ||
| 143 | static int pl2303_write_room(struct usb_serial_port *port); | ||
| 144 | static int pl2303_chars_in_buffer(struct usb_serial_port *port); | ||
| 145 | static void pl2303_break_ctl(struct usb_serial_port *port,int break_state); | ||
| 146 | static int pl2303_tiocmget (struct usb_serial_port *port, struct file *file); | ||
| 147 | static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file, | ||
| 148 | unsigned int set, unsigned int clear); | ||
| 149 | static int pl2303_startup (struct usb_serial *serial); | ||
| 150 | static void pl2303_shutdown (struct usb_serial *serial); | ||
| 151 | static struct pl2303_buf *pl2303_buf_alloc(unsigned int size); | ||
| 152 | static void pl2303_buf_free(struct pl2303_buf *pb); | ||
| 153 | static void pl2303_buf_clear(struct pl2303_buf *pb); | ||
| 154 | static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb); | ||
| 155 | static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb); | ||
| 156 | static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf, | ||
| 157 | unsigned int count); | ||
| 158 | static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf, | ||
| 159 | unsigned int count); | ||
| 160 | |||
| 161 | |||
| 162 | /* All of the device info needed for the PL2303 SIO serial converter */ | ||
| 163 | static struct usb_serial_driver pl2303_device = { | ||
| 164 | .driver = { | ||
| 165 | .owner = THIS_MODULE, | ||
| 166 | .name = "pl2303", | ||
| 167 | }, | ||
| 168 | .id_table = id_table, | ||
| 169 | .num_interrupt_in = NUM_DONT_CARE, | ||
| 170 | .num_bulk_in = 1, | ||
| 171 | .num_bulk_out = 1, | ||
| 172 | .num_ports = 1, | ||
| 173 | .open = pl2303_open, | ||
| 174 | .close = pl2303_close, | ||
| 175 | .write = pl2303_write, | ||
| 176 | .ioctl = pl2303_ioctl, | ||
| 177 | .break_ctl = pl2303_break_ctl, | ||
| 178 | .set_termios = pl2303_set_termios, | ||
| 179 | .tiocmget = pl2303_tiocmget, | ||
| 180 | .tiocmset = pl2303_tiocmset, | ||
| 181 | .read_bulk_callback = pl2303_read_bulk_callback, | ||
| 182 | .read_int_callback = pl2303_read_int_callback, | ||
| 183 | .write_bulk_callback = pl2303_write_bulk_callback, | ||
| 184 | .write_room = pl2303_write_room, | ||
| 185 | .chars_in_buffer = pl2303_chars_in_buffer, | ||
| 186 | .attach = pl2303_startup, | ||
| 187 | .shutdown = pl2303_shutdown, | ||
| 188 | }; | ||
| 189 | 131 | ||
| 190 | enum pl2303_type { | 132 | enum pl2303_type { |
| 191 | type_0, /* don't know the difference between type 0 and */ | 133 | type_0, /* don't know the difference between type 0 and */ |
| @@ -204,8 +146,166 @@ struct pl2303_private { | |||
| 204 | enum pl2303_type type; | 146 | enum pl2303_type type; |
| 205 | }; | 147 | }; |
| 206 | 148 | ||
| 149 | /* | ||
| 150 | * pl2303_buf_alloc | ||
| 151 | * | ||
| 152 | * Allocate a circular buffer and all associated memory. | ||
| 153 | */ | ||
| 154 | static struct pl2303_buf *pl2303_buf_alloc(unsigned int size) | ||
| 155 | { | ||
| 156 | struct pl2303_buf *pb; | ||
| 157 | |||
| 158 | if (size == 0) | ||
| 159 | return NULL; | ||
| 160 | |||
| 161 | pb = (struct pl2303_buf *)kmalloc(sizeof(struct pl2303_buf), GFP_KERNEL); | ||
| 162 | if (pb == NULL) | ||
| 163 | return NULL; | ||
| 164 | |||
| 165 | pb->buf_buf = kmalloc(size, GFP_KERNEL); | ||
| 166 | if (pb->buf_buf == NULL) { | ||
| 167 | kfree(pb); | ||
| 168 | return NULL; | ||
| 169 | } | ||
| 170 | |||
| 171 | pb->buf_size = size; | ||
| 172 | pb->buf_get = pb->buf_put = pb->buf_buf; | ||
| 207 | 173 | ||
| 208 | static int pl2303_startup (struct usb_serial *serial) | 174 | return pb; |
| 175 | } | ||
| 176 | |||
| 177 | /* | ||
| 178 | * pl2303_buf_free | ||
| 179 | * | ||
| 180 | * Free the buffer and all associated memory. | ||
| 181 | */ | ||
| 182 | static void pl2303_buf_free(struct pl2303_buf *pb) | ||
| 183 | { | ||
| 184 | if (pb) { | ||
| 185 | kfree(pb->buf_buf); | ||
| 186 | kfree(pb); | ||
| 187 | } | ||
| 188 | } | ||
| 189 | |||
| 190 | /* | ||
| 191 | * pl2303_buf_clear | ||
| 192 | * | ||
| 193 | * Clear out all data in the circular buffer. | ||
| 194 | */ | ||
| 195 | static void pl2303_buf_clear(struct pl2303_buf *pb) | ||
| 196 | { | ||
| 197 | if (pb != NULL) | ||
| 198 | pb->buf_get = pb->buf_put; | ||
| 199 | /* equivalent to a get of all data available */ | ||
| 200 | } | ||
| 201 | |||
| 202 | /* | ||
| 203 | * pl2303_buf_data_avail | ||
| 204 | * | ||
| 205 | * Return the number of bytes of data available in the circular | ||
| 206 | * buffer. | ||
| 207 | */ | ||
| 208 | static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb) | ||
| 209 | { | ||
| 210 | if (pb == NULL) | ||
| 211 | return 0; | ||
| 212 | |||
| 213 | return ((pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size); | ||
| 214 | } | ||
| 215 | |||
| 216 | /* | ||
| 217 | * pl2303_buf_space_avail | ||
| 218 | * | ||
| 219 | * Return the number of bytes of space available in the circular | ||
| 220 | * buffer. | ||
| 221 | */ | ||
| 222 | static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb) | ||
| 223 | { | ||
| 224 | if (pb == NULL) | ||
| 225 | return 0; | ||
| 226 | |||
| 227 | return ((pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size); | ||
| 228 | } | ||
| 229 | |||
| 230 | /* | ||
| 231 | * pl2303_buf_put | ||
| 232 | * | ||
| 233 | * Copy data data from a user buffer and put it into the circular buffer. | ||
| 234 | * Restrict to the amount of space available. | ||
| 235 | * | ||
| 236 | * Return the number of bytes copied. | ||
| 237 | */ | ||
| 238 | static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf, | ||
| 239 | unsigned int count) | ||
| 240 | { | ||
| 241 | unsigned int len; | ||
| 242 | |||
| 243 | if (pb == NULL) | ||
| 244 | return 0; | ||
| 245 | |||
| 246 | len = pl2303_buf_space_avail(pb); | ||
| 247 | if (count > len) | ||
| 248 | count = len; | ||
| 249 | |||
| 250 | if (count == 0) | ||
| 251 | return 0; | ||
| 252 | |||
| 253 | len = pb->buf_buf + pb->buf_size - pb->buf_put; | ||
| 254 | if (count > len) { | ||
| 255 | memcpy(pb->buf_put, buf, len); | ||
| 256 | memcpy(pb->buf_buf, buf+len, count - len); | ||
| 257 | pb->buf_put = pb->buf_buf + count - len; | ||
| 258 | } else { | ||
| 259 | memcpy(pb->buf_put, buf, count); | ||
| 260 | if (count < len) | ||
| 261 | pb->buf_put += count; | ||
| 262 | else /* count == len */ | ||
| 263 | pb->buf_put = pb->buf_buf; | ||
| 264 | } | ||
| 265 | |||
| 266 | return count; | ||
| 267 | } | ||
| 268 | |||
| 269 | /* | ||
| 270 | * pl2303_buf_get | ||
| 271 | * | ||
| 272 | * Get data from the circular buffer and copy to the given buffer. | ||
| 273 | * Restrict to the amount of data available. | ||
| 274 | * | ||
| 275 | * Return the number of bytes copied. | ||
| 276 | */ | ||
| 277 | static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf, | ||
| 278 | unsigned int count) | ||
| 279 | { | ||
| 280 | unsigned int len; | ||
| 281 | |||
| 282 | if (pb == NULL) | ||
| 283 | return 0; | ||
| 284 | |||
| 285 | len = pl2303_buf_data_avail(pb); | ||
| 286 | if (count > len) | ||
| 287 | count = len; | ||
| 288 | |||
| 289 | if (count == 0) | ||
| 290 | return 0; | ||
| 291 | |||
| 292 | len = pb->buf_buf + pb->buf_size - pb->buf_get; | ||
| 293 | if (count > len) { | ||
| 294 | memcpy(buf, pb->buf_get, len); | ||
| 295 | memcpy(buf+len, pb->buf_buf, count - len); | ||
| 296 | pb->buf_get = pb->buf_buf + count - len; | ||
| 297 | } else { | ||
| 298 | memcpy(buf, pb->buf_get, count); | ||
| 299 | if (count < len) | ||
| 300 | pb->buf_get += count; | ||
| 301 | else /* count == len */ | ||
| 302 | pb->buf_get = pb->buf_buf; | ||
| 303 | } | ||
| 304 | |||
| 305 | return count; | ||
| 306 | } | ||
| 307 | |||
| 308 | static int pl2303_startup(struct usb_serial *serial) | ||
| 209 | { | 309 | { |
| 210 | struct pl2303_private *priv; | 310 | struct pl2303_private *priv; |
| 211 | enum pl2303_type type = type_0; | 311 | enum pl2303_type type = type_0; |
| @@ -247,36 +347,17 @@ cleanup: | |||
| 247 | return -ENOMEM; | 347 | return -ENOMEM; |
| 248 | } | 348 | } |
| 249 | 349 | ||
| 250 | static int set_control_lines (struct usb_device *dev, u8 value) | 350 | static int set_control_lines(struct usb_device *dev, u8 value) |
| 251 | { | 351 | { |
| 252 | int retval; | 352 | int retval; |
| 253 | 353 | ||
| 254 | retval = usb_control_msg (dev, usb_sndctrlpipe (dev, 0), | 354 | retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
| 255 | SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE, | 355 | SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE, |
| 256 | value, 0, NULL, 0, 100); | 356 | value, 0, NULL, 0, 100); |
| 257 | dbg("%s - value = %d, retval = %d", __FUNCTION__, value, retval); | 357 | dbg("%s - value = %d, retval = %d", __FUNCTION__, value, retval); |
| 258 | return retval; | 358 | return retval; |
| 259 | } | 359 | } |
| 260 | 360 | ||
| 261 | static int pl2303_write (struct usb_serial_port *port, const unsigned char *buf, int count) | ||
| 262 | { | ||
| 263 | struct pl2303_private *priv = usb_get_serial_port_data(port); | ||
| 264 | unsigned long flags; | ||
| 265 | |||
| 266 | dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count); | ||
| 267 | |||
| 268 | if (!count) | ||
| 269 | return count; | ||
| 270 | |||
| 271 | spin_lock_irqsave(&priv->lock, flags); | ||
| 272 | count = pl2303_buf_put(priv->buf, buf, count); | ||
| 273 | spin_unlock_irqrestore(&priv->lock, flags); | ||
| 274 | |||
| 275 | pl2303_send(port); | ||
| 276 | |||
| 277 | return count; | ||
| 278 | } | ||
| 279 | |||
| 280 | static void pl2303_send(struct usb_serial_port *port) | 361 | static void pl2303_send(struct usb_serial_port *port) |
| 281 | { | 362 | { |
| 282 | int count, result; | 363 | int count, result; |
| @@ -293,7 +374,7 @@ static void pl2303_send(struct usb_serial_port *port) | |||
| 293 | } | 374 | } |
| 294 | 375 | ||
| 295 | count = pl2303_buf_get(priv->buf, port->write_urb->transfer_buffer, | 376 | count = pl2303_buf_get(priv->buf, port->write_urb->transfer_buffer, |
| 296 | port->bulk_out_size); | 377 | port->bulk_out_size); |
| 297 | 378 | ||
| 298 | if (count == 0) { | 379 | if (count == 0) { |
| 299 | spin_unlock_irqrestore(&priv->lock, flags); | 380 | spin_unlock_irqrestore(&priv->lock, flags); |
| @@ -304,13 +385,15 @@ static void pl2303_send(struct usb_serial_port *port) | |||
| 304 | 385 | ||
| 305 | spin_unlock_irqrestore(&priv->lock, flags); | 386 | spin_unlock_irqrestore(&priv->lock, flags); |
| 306 | 387 | ||
| 307 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, port->write_urb->transfer_buffer); | 388 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, |
| 389 | port->write_urb->transfer_buffer); | ||
| 308 | 390 | ||
| 309 | port->write_urb->transfer_buffer_length = count; | 391 | port->write_urb->transfer_buffer_length = count; |
| 310 | port->write_urb->dev = port->serial->dev; | 392 | port->write_urb->dev = port->serial->dev; |
| 311 | result = usb_submit_urb (port->write_urb, GFP_ATOMIC); | 393 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); |
| 312 | if (result) { | 394 | if (result) { |
| 313 | dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result); | 395 | dev_err(&port->dev, "%s - failed submitting write urb," |
| 396 | " error %d\n", __FUNCTION__, result); | ||
| 314 | priv->write_urb_in_use = 0; | 397 | priv->write_urb_in_use = 0; |
| 315 | // TODO: reschedule pl2303_send | 398 | // TODO: reschedule pl2303_send |
| 316 | } | 399 | } |
| @@ -318,6 +401,26 @@ static void pl2303_send(struct usb_serial_port *port) | |||
| 318 | usb_serial_port_softint(port); | 401 | usb_serial_port_softint(port); |
| 319 | } | 402 | } |
| 320 | 403 | ||
| 404 | static int pl2303_write(struct usb_serial_port *port, const unsigned char *buf, | ||
| 405 | int count) | ||
| 406 | { | ||
| 407 | struct pl2303_private *priv = usb_get_serial_port_data(port); | ||
| 408 | unsigned long flags; | ||
| 409 | |||
| 410 | dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count); | ||
| 411 | |||
| 412 | if (!count) | ||
| 413 | return count; | ||
| 414 | |||
| 415 | spin_lock_irqsave(&priv->lock, flags); | ||
| 416 | count = pl2303_buf_put(priv->buf, buf, count); | ||
| 417 | spin_unlock_irqrestore(&priv->lock, flags); | ||
| 418 | |||
| 419 | pl2303_send(port); | ||
| 420 | |||
| 421 | return count; | ||
| 422 | } | ||
| 423 | |||
| 321 | static int pl2303_write_room(struct usb_serial_port *port) | 424 | static int pl2303_write_room(struct usb_serial_port *port) |
| 322 | { | 425 | { |
| 323 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 426 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
| @@ -350,7 +453,8 @@ static int pl2303_chars_in_buffer(struct usb_serial_port *port) | |||
| 350 | return chars; | 453 | return chars; |
| 351 | } | 454 | } |
| 352 | 455 | ||
| 353 | static void pl2303_set_termios (struct usb_serial_port *port, struct termios *old_termios) | 456 | static void pl2303_set_termios(struct usb_serial_port *port, |
| 457 | struct termios *old_termios) | ||
| 354 | { | 458 | { |
| 355 | struct usb_serial *serial = port->serial; | 459 | struct usb_serial *serial = port->serial; |
| 356 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 460 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
| @@ -371,7 +475,8 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol | |||
| 371 | spin_lock_irqsave(&priv->lock, flags); | 475 | spin_lock_irqsave(&priv->lock, flags); |
| 372 | if (!priv->termios_initialized) { | 476 | if (!priv->termios_initialized) { |
| 373 | *(port->tty->termios) = tty_std_termios; | 477 | *(port->tty->termios) = tty_std_termios; |
| 374 | port->tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; | 478 | port->tty->termios->c_cflag = B9600 | CS8 | CREAD | |
| 479 | HUPCL | CLOCAL; | ||
| 375 | priv->termios_initialized = 1; | 480 | priv->termios_initialized = 1; |
| 376 | } | 481 | } |
| 377 | spin_unlock_irqrestore(&priv->lock, flags); | 482 | spin_unlock_irqrestore(&priv->lock, flags); |
| @@ -380,24 +485,24 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol | |||
| 380 | /* check that they really want us to change something */ | 485 | /* check that they really want us to change something */ |
| 381 | if (old_termios) { | 486 | if (old_termios) { |
| 382 | if ((cflag == old_termios->c_cflag) && | 487 | if ((cflag == old_termios->c_cflag) && |
| 383 | (RELEVANT_IFLAG(port->tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) { | 488 | (RELEVANT_IFLAG(port->tty->termios->c_iflag) == |
| 384 | dbg("%s - nothing to change...", __FUNCTION__); | 489 | RELEVANT_IFLAG(old_termios->c_iflag))) { |
| 385 | return; | 490 | dbg("%s - nothing to change...", __FUNCTION__); |
| 491 | return; | ||
| 386 | } | 492 | } |
| 387 | } | 493 | } |
| 388 | 494 | ||
| 389 | buf = kzalloc (7, GFP_KERNEL); | 495 | buf = kzalloc(7, GFP_KERNEL); |
| 390 | if (!buf) { | 496 | if (!buf) { |
| 391 | dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__); | 497 | dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__); |
| 392 | return; | 498 | return; |
| 393 | } | 499 | } |
| 394 | |||
| 395 | i = usb_control_msg (serial->dev, usb_rcvctrlpipe (serial->dev, 0), | ||
| 396 | GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, | ||
| 397 | 0, 0, buf, 7, 100); | ||
| 398 | dbg ("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i, | ||
| 399 | buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); | ||
| 400 | 500 | ||
| 501 | i = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | ||
| 502 | GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, | ||
| 503 | 0, 0, buf, 7, 100); | ||
| 504 | dbg("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i, | ||
| 505 | buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); | ||
| 401 | 506 | ||
| 402 | if (cflag & CSIZE) { | 507 | if (cflag & CSIZE) { |
| 403 | switch (cflag & CSIZE) { | 508 | switch (cflag & CSIZE) { |
| @@ -429,7 +534,8 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol | |||
| 429 | case B230400: baud = 230400; break; | 534 | case B230400: baud = 230400; break; |
| 430 | case B460800: baud = 460800; break; | 535 | case B460800: baud = 460800; break; |
| 431 | default: | 536 | default: |
| 432 | dev_err(&port->dev, "pl2303 driver does not support the baudrate requested (fix it)\n"); | 537 | dev_err(&port->dev, "pl2303 driver does not support" |
| 538 | " the baudrate requested (fix it)\n"); | ||
| 433 | break; | 539 | break; |
| 434 | } | 540 | } |
| 435 | dbg("%s - baud = %d", __FUNCTION__, baud); | 541 | dbg("%s - baud = %d", __FUNCTION__, baud); |
| @@ -469,10 +575,10 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol | |||
| 469 | dbg("%s - parity = none", __FUNCTION__); | 575 | dbg("%s - parity = none", __FUNCTION__); |
| 470 | } | 576 | } |
| 471 | 577 | ||
| 472 | i = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0), | 578 | i = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
| 473 | SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE, | 579 | SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE, |
| 474 | 0, 0, buf, 7, 100); | 580 | 0, 0, buf, 7, 100); |
| 475 | dbg ("0x21:0x20:0:0 %d", i); | 581 | dbg("0x21:0x20:0:0 %d", i); |
| 476 | 582 | ||
| 477 | /* change control lines if we are switching to or from B0 */ | 583 | /* change control lines if we are switching to or from B0 */ |
| 478 | spin_lock_irqsave(&priv->lock, flags); | 584 | spin_lock_irqsave(&priv->lock, flags); |
| @@ -488,13 +594,13 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol | |||
| 488 | } else { | 594 | } else { |
| 489 | spin_unlock_irqrestore(&priv->lock, flags); | 595 | spin_unlock_irqrestore(&priv->lock, flags); |
| 490 | } | 596 | } |
| 491 | 597 | ||
| 492 | buf[0] = buf[1] = buf[2] = buf[3] = buf[4] = buf[5] = buf[6] = 0; | 598 | buf[0] = buf[1] = buf[2] = buf[3] = buf[4] = buf[5] = buf[6] = 0; |
| 493 | 599 | ||
| 494 | i = usb_control_msg (serial->dev, usb_rcvctrlpipe (serial->dev, 0), | 600 | i = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), |
| 495 | GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, | 601 | GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, |
| 496 | 0, 0, buf, 7, 100); | 602 | 0, 0, buf, 7, 100); |
| 497 | dbg ("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i, | 603 | dbg("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i, |
| 498 | buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); | 604 | buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); |
| 499 | 605 | ||
| 500 | if (cflag & CRTSCTS) { | 606 | if (cflag & CRTSCTS) { |
| @@ -503,18 +609,82 @@ static void pl2303_set_termios (struct usb_serial_port *port, struct termios *ol | |||
| 503 | index = 0x61; | 609 | index = 0x61; |
| 504 | else | 610 | else |
| 505 | index = 0x41; | 611 | index = 0x41; |
| 506 | i = usb_control_msg(serial->dev, | 612 | i = usb_control_msg(serial->dev, |
| 507 | usb_sndctrlpipe(serial->dev, 0), | 613 | usb_sndctrlpipe(serial->dev, 0), |
| 508 | VENDOR_WRITE_REQUEST, | 614 | VENDOR_WRITE_REQUEST, |
| 509 | VENDOR_WRITE_REQUEST_TYPE, | 615 | VENDOR_WRITE_REQUEST_TYPE, |
| 510 | 0x0, index, NULL, 0, 100); | 616 | 0x0, index, NULL, 0, 100); |
| 511 | dbg ("0x40:0x1:0x0:0x%x %d", index, i); | 617 | dbg("0x40:0x1:0x0:0x%x %d", index, i); |
| 618 | } | ||
| 619 | |||
| 620 | kfree(buf); | ||
| 621 | } | ||
| 622 | |||
| 623 | static void pl2303_close(struct usb_serial_port *port, struct file *filp) | ||
| 624 | { | ||
| 625 | struct pl2303_private *priv = usb_get_serial_port_data(port); | ||
| 626 | unsigned long flags; | ||
| 627 | unsigned int c_cflag; | ||
| 628 | int bps; | ||
| 629 | long timeout; | ||
| 630 | wait_queue_t wait; | ||
| 631 | |||
| 632 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
| 633 | |||
| 634 | /* wait for data to drain from the buffer */ | ||
| 635 | spin_lock_irqsave(&priv->lock, flags); | ||
| 636 | timeout = PL2303_CLOSING_WAIT; | ||
| 637 | init_waitqueue_entry(&wait, current); | ||
| 638 | add_wait_queue(&port->tty->write_wait, &wait); | ||
| 639 | for (;;) { | ||
| 640 | set_current_state(TASK_INTERRUPTIBLE); | ||
| 641 | if (pl2303_buf_data_avail(priv->buf) == 0 || | ||
| 642 | timeout == 0 || signal_pending(current) || | ||
| 643 | !usb_get_intfdata(port->serial->interface)) /* disconnect */ | ||
| 644 | break; | ||
| 645 | spin_unlock_irqrestore(&priv->lock, flags); | ||
| 646 | timeout = schedule_timeout(timeout); | ||
| 647 | spin_lock_irqsave(&priv->lock, flags); | ||
| 512 | } | 648 | } |
| 649 | set_current_state(TASK_RUNNING); | ||
| 650 | remove_wait_queue(&port->tty->write_wait, &wait); | ||
| 651 | /* clear out any remaining data in the buffer */ | ||
| 652 | pl2303_buf_clear(priv->buf); | ||
| 653 | spin_unlock_irqrestore(&priv->lock, flags); | ||
| 654 | |||
| 655 | /* wait for characters to drain from the device */ | ||
| 656 | /* (this is long enough for the entire 256 byte */ | ||
| 657 | /* pl2303 hardware buffer to drain with no flow */ | ||
| 658 | /* control for data rates of 1200 bps or more, */ | ||
| 659 | /* for lower rates we should really know how much */ | ||
| 660 | /* data is in the buffer to compute a delay */ | ||
| 661 | /* that is not unnecessarily long) */ | ||
| 662 | bps = tty_get_baud_rate(port->tty); | ||
| 663 | if (bps > 1200) | ||
| 664 | timeout = max((HZ*2560)/bps,HZ/10); | ||
| 665 | else | ||
| 666 | timeout = 2*HZ; | ||
| 667 | schedule_timeout_interruptible(timeout); | ||
| 513 | 668 | ||
| 514 | kfree (buf); | 669 | /* shutdown our urbs */ |
| 670 | dbg("%s - shutting down urbs", __FUNCTION__); | ||
| 671 | usb_kill_urb(port->write_urb); | ||
| 672 | usb_kill_urb(port->read_urb); | ||
| 673 | usb_kill_urb(port->interrupt_in_urb); | ||
| 674 | |||
| 675 | if (port->tty) { | ||
| 676 | c_cflag = port->tty->termios->c_cflag; | ||
| 677 | if (c_cflag & HUPCL) { | ||
| 678 | /* drop DTR and RTS */ | ||
| 679 | spin_lock_irqsave(&priv->lock, flags); | ||
| 680 | priv->line_control = 0; | ||
| 681 | spin_unlock_irqrestore(&priv->lock, flags); | ||
| 682 | set_control_lines(port->serial->dev, 0); | ||
| 683 | } | ||
| 684 | } | ||
| 515 | } | 685 | } |
| 516 | 686 | ||
| 517 | static int pl2303_open (struct usb_serial_port *port, struct file *filp) | 687 | static int pl2303_open(struct usb_serial_port *port, struct file *filp) |
| 518 | { | 688 | { |
| 519 | struct termios tmp_termios; | 689 | struct termios tmp_termios; |
| 520 | struct usb_serial *serial = port->serial; | 690 | struct usb_serial *serial = port->serial; |
| @@ -568,98 +738,35 @@ static int pl2303_open (struct usb_serial_port *port, struct file *filp) | |||
| 568 | 738 | ||
| 569 | /* Setup termios */ | 739 | /* Setup termios */ |
| 570 | if (port->tty) { | 740 | if (port->tty) { |
| 571 | pl2303_set_termios (port, &tmp_termios); | 741 | pl2303_set_termios(port, &tmp_termios); |
| 572 | } | 742 | } |
| 573 | 743 | ||
| 574 | //FIXME: need to assert RTS and DTR if CRTSCTS off | 744 | //FIXME: need to assert RTS and DTR if CRTSCTS off |
| 575 | 745 | ||
| 576 | dbg("%s - submitting read urb", __FUNCTION__); | 746 | dbg("%s - submitting read urb", __FUNCTION__); |
| 577 | port->read_urb->dev = serial->dev; | 747 | port->read_urb->dev = serial->dev; |
| 578 | result = usb_submit_urb (port->read_urb, GFP_KERNEL); | 748 | result = usb_submit_urb(port->read_urb, GFP_KERNEL); |
| 579 | if (result) { | 749 | if (result) { |
| 580 | dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result); | 750 | dev_err(&port->dev, "%s - failed submitting read urb," |
| 581 | pl2303_close (port, NULL); | 751 | " error %d\n", __FUNCTION__, result); |
| 752 | pl2303_close(port, NULL); | ||
| 582 | return -EPROTO; | 753 | return -EPROTO; |
| 583 | } | 754 | } |
| 584 | 755 | ||
| 585 | dbg("%s - submitting interrupt urb", __FUNCTION__); | 756 | dbg("%s - submitting interrupt urb", __FUNCTION__); |
| 586 | port->interrupt_in_urb->dev = serial->dev; | 757 | port->interrupt_in_urb->dev = serial->dev; |
| 587 | result = usb_submit_urb (port->interrupt_in_urb, GFP_KERNEL); | 758 | result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
| 588 | if (result) { | 759 | if (result) { |
| 589 | dev_err(&port->dev, "%s - failed submitting interrupt urb, error %d\n", __FUNCTION__, result); | 760 | dev_err(&port->dev, "%s - failed submitting interrupt urb," |
| 590 | pl2303_close (port, NULL); | 761 | " error %d\n", __FUNCTION__, result); |
| 762 | pl2303_close(port, NULL); | ||
| 591 | return -EPROTO; | 763 | return -EPROTO; |
| 592 | } | 764 | } |
| 593 | return 0; | 765 | return 0; |
| 594 | } | 766 | } |
| 595 | 767 | ||
| 596 | 768 | static int pl2303_tiocmset(struct usb_serial_port *port, struct file *file, | |
| 597 | static void pl2303_close (struct usb_serial_port *port, struct file *filp) | 769 | unsigned int set, unsigned int clear) |
| 598 | { | ||
| 599 | struct pl2303_private *priv = usb_get_serial_port_data(port); | ||
| 600 | unsigned long flags; | ||
| 601 | unsigned int c_cflag; | ||
| 602 | int bps; | ||
| 603 | long timeout; | ||
| 604 | wait_queue_t wait; | ||
| 605 | |||
| 606 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
| 607 | |||
| 608 | /* wait for data to drain from the buffer */ | ||
| 609 | spin_lock_irqsave(&priv->lock, flags); | ||
| 610 | timeout = PL2303_CLOSING_WAIT; | ||
| 611 | init_waitqueue_entry(&wait, current); | ||
| 612 | add_wait_queue(&port->tty->write_wait, &wait); | ||
| 613 | for (;;) { | ||
| 614 | set_current_state(TASK_INTERRUPTIBLE); | ||
| 615 | if (pl2303_buf_data_avail(priv->buf) == 0 | ||
| 616 | || timeout == 0 || signal_pending(current) | ||
| 617 | || !usb_get_intfdata(port->serial->interface)) /* disconnect */ | ||
| 618 | break; | ||
| 619 | spin_unlock_irqrestore(&priv->lock, flags); | ||
| 620 | timeout = schedule_timeout(timeout); | ||
| 621 | spin_lock_irqsave(&priv->lock, flags); | ||
| 622 | } | ||
| 623 | set_current_state(TASK_RUNNING); | ||
| 624 | remove_wait_queue(&port->tty->write_wait, &wait); | ||
| 625 | /* clear out any remaining data in the buffer */ | ||
| 626 | pl2303_buf_clear(priv->buf); | ||
| 627 | spin_unlock_irqrestore(&priv->lock, flags); | ||
| 628 | |||
| 629 | /* wait for characters to drain from the device */ | ||
| 630 | /* (this is long enough for the entire 256 byte */ | ||
| 631 | /* pl2303 hardware buffer to drain with no flow */ | ||
| 632 | /* control for data rates of 1200 bps or more, */ | ||
| 633 | /* for lower rates we should really know how much */ | ||
| 634 | /* data is in the buffer to compute a delay */ | ||
| 635 | /* that is not unnecessarily long) */ | ||
| 636 | bps = tty_get_baud_rate(port->tty); | ||
| 637 | if (bps > 1200) | ||
| 638 | timeout = max((HZ*2560)/bps,HZ/10); | ||
| 639 | else | ||
| 640 | timeout = 2*HZ; | ||
| 641 | schedule_timeout_interruptible(timeout); | ||
| 642 | |||
| 643 | /* shutdown our urbs */ | ||
| 644 | dbg("%s - shutting down urbs", __FUNCTION__); | ||
| 645 | usb_kill_urb(port->write_urb); | ||
| 646 | usb_kill_urb(port->read_urb); | ||
| 647 | usb_kill_urb(port->interrupt_in_urb); | ||
| 648 | |||
| 649 | if (port->tty) { | ||
| 650 | c_cflag = port->tty->termios->c_cflag; | ||
| 651 | if (c_cflag & HUPCL) { | ||
| 652 | /* drop DTR and RTS */ | ||
| 653 | spin_lock_irqsave(&priv->lock, flags); | ||
| 654 | priv->line_control = 0; | ||
| 655 | spin_unlock_irqrestore (&priv->lock, flags); | ||
| 656 | set_control_lines (port->serial->dev, 0); | ||
| 657 | } | ||
| 658 | } | ||
| 659 | } | ||
| 660 | |||
| 661 | static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file, | ||
| 662 | unsigned int set, unsigned int clear) | ||
| 663 | { | 770 | { |
| 664 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 771 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
| 665 | unsigned long flags; | 772 | unsigned long flags; |
| @@ -668,7 +775,7 @@ static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file, | |||
| 668 | if (!usb_get_intfdata(port->serial->interface)) | 775 | if (!usb_get_intfdata(port->serial->interface)) |
| 669 | return -ENODEV; | 776 | return -ENODEV; |
| 670 | 777 | ||
| 671 | spin_lock_irqsave (&priv->lock, flags); | 778 | spin_lock_irqsave(&priv->lock, flags); |
| 672 | if (set & TIOCM_RTS) | 779 | if (set & TIOCM_RTS) |
| 673 | priv->line_control |= CONTROL_RTS; | 780 | priv->line_control |= CONTROL_RTS; |
| 674 | if (set & TIOCM_DTR) | 781 | if (set & TIOCM_DTR) |
| @@ -678,12 +785,12 @@ static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file, | |||
| 678 | if (clear & TIOCM_DTR) | 785 | if (clear & TIOCM_DTR) |
| 679 | priv->line_control &= ~CONTROL_DTR; | 786 | priv->line_control &= ~CONTROL_DTR; |
| 680 | control = priv->line_control; | 787 | control = priv->line_control; |
| 681 | spin_unlock_irqrestore (&priv->lock, flags); | 788 | spin_unlock_irqrestore(&priv->lock, flags); |
| 682 | 789 | ||
| 683 | return set_control_lines (port->serial->dev, control); | 790 | return set_control_lines(port->serial->dev, control); |
| 684 | } | 791 | } |
| 685 | 792 | ||
| 686 | static int pl2303_tiocmget (struct usb_serial_port *port, struct file *file) | 793 | static int pl2303_tiocmget(struct usb_serial_port *port, struct file *file) |
| 687 | { | 794 | { |
| 688 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 795 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
| 689 | unsigned long flags; | 796 | unsigned long flags; |
| @@ -696,10 +803,10 @@ static int pl2303_tiocmget (struct usb_serial_port *port, struct file *file) | |||
| 696 | if (!usb_get_intfdata(port->serial->interface)) | 803 | if (!usb_get_intfdata(port->serial->interface)) |
| 697 | return -ENODEV; | 804 | return -ENODEV; |
| 698 | 805 | ||
| 699 | spin_lock_irqsave (&priv->lock, flags); | 806 | spin_lock_irqsave(&priv->lock, flags); |
| 700 | mcr = priv->line_control; | 807 | mcr = priv->line_control; |
| 701 | status = priv->line_status; | 808 | status = priv->line_status; |
| 702 | spin_unlock_irqrestore (&priv->lock, flags); | 809 | spin_unlock_irqrestore(&priv->lock, flags); |
| 703 | 810 | ||
| 704 | result = ((mcr & CONTROL_DTR) ? TIOCM_DTR : 0) | 811 | result = ((mcr & CONTROL_DTR) ? TIOCM_DTR : 0) |
| 705 | | ((mcr & CONTROL_RTS) ? TIOCM_RTS : 0) | 812 | | ((mcr & CONTROL_RTS) ? TIOCM_RTS : 0) |
| @@ -721,22 +828,22 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) | |||
| 721 | unsigned int status; | 828 | unsigned int status; |
| 722 | unsigned int changed; | 829 | unsigned int changed; |
| 723 | 830 | ||
| 724 | spin_lock_irqsave (&priv->lock, flags); | 831 | spin_lock_irqsave(&priv->lock, flags); |
| 725 | prevstatus = priv->line_status; | 832 | prevstatus = priv->line_status; |
| 726 | spin_unlock_irqrestore (&priv->lock, flags); | 833 | spin_unlock_irqrestore(&priv->lock, flags); |
| 727 | 834 | ||
| 728 | while (1) { | 835 | while (1) { |
| 729 | interruptible_sleep_on(&priv->delta_msr_wait); | 836 | interruptible_sleep_on(&priv->delta_msr_wait); |
| 730 | /* see if a signal did it */ | 837 | /* see if a signal did it */ |
| 731 | if (signal_pending(current)) | 838 | if (signal_pending(current)) |
| 732 | return -ERESTARTSYS; | 839 | return -ERESTARTSYS; |
| 733 | 840 | ||
| 734 | spin_lock_irqsave (&priv->lock, flags); | 841 | spin_lock_irqsave(&priv->lock, flags); |
| 735 | status = priv->line_status; | 842 | status = priv->line_status; |
| 736 | spin_unlock_irqrestore (&priv->lock, flags); | 843 | spin_unlock_irqrestore(&priv->lock, flags); |
| 737 | 844 | ||
| 738 | changed=prevstatus^status; | 845 | changed=prevstatus^status; |
| 739 | 846 | ||
| 740 | if (((arg & TIOCM_RNG) && (changed & UART_RING)) || | 847 | if (((arg & TIOCM_RNG) && (changed & UART_RING)) || |
| 741 | ((arg & TIOCM_DSR) && (changed & UART_DSR)) || | 848 | ((arg & TIOCM_DSR) && (changed & UART_DSR)) || |
| 742 | ((arg & TIOCM_CD) && (changed & UART_DCD)) || | 849 | ((arg & TIOCM_CD) && (changed & UART_DCD)) || |
| @@ -749,7 +856,8 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) | |||
| 749 | return 0; | 856 | return 0; |
| 750 | } | 857 | } |
| 751 | 858 | ||
| 752 | static int pl2303_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg) | 859 | static int pl2303_ioctl(struct usb_serial_port *port, struct file *file, |
| 860 | unsigned int cmd, unsigned long arg) | ||
| 753 | { | 861 | { |
| 754 | dbg("%s (%d) cmd = 0x%04x", __FUNCTION__, port->number, cmd); | 862 | dbg("%s (%d) cmd = 0x%04x", __FUNCTION__, port->number, cmd); |
| 755 | 863 | ||
| @@ -766,7 +874,7 @@ static int pl2303_ioctl (struct usb_serial_port *port, struct file *file, unsign | |||
| 766 | return -ENOIOCTLCMD; | 874 | return -ENOIOCTLCMD; |
| 767 | } | 875 | } |
| 768 | 876 | ||
| 769 | static void pl2303_break_ctl (struct usb_serial_port *port, int break_state) | 877 | static void pl2303_break_ctl(struct usb_serial_port *port, int break_state) |
| 770 | { | 878 | { |
| 771 | struct usb_serial *serial = port->serial; | 879 | struct usb_serial *serial = port->serial; |
| 772 | u16 state; | 880 | u16 state; |
| @@ -780,15 +888,14 @@ static void pl2303_break_ctl (struct usb_serial_port *port, int break_state) | |||
| 780 | state = BREAK_ON; | 888 | state = BREAK_ON; |
| 781 | dbg("%s - turning break %s", __FUNCTION__, state==BREAK_OFF ? "off" : "on"); | 889 | dbg("%s - turning break %s", __FUNCTION__, state==BREAK_OFF ? "off" : "on"); |
| 782 | 890 | ||
| 783 | result = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0), | 891 | result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
| 784 | BREAK_REQUEST, BREAK_REQUEST_TYPE, state, | 892 | BREAK_REQUEST, BREAK_REQUEST_TYPE, state, |
| 785 | 0, NULL, 0, 100); | 893 | 0, NULL, 0, 100); |
| 786 | if (result) | 894 | if (result) |
| 787 | dbg("%s - error sending break = %d", __FUNCTION__, result); | 895 | dbg("%s - error sending break = %d", __FUNCTION__, result); |
| 788 | } | 896 | } |
| 789 | 897 | ||
| 790 | 898 | static void pl2303_shutdown(struct usb_serial *serial) | |
| 791 | static void pl2303_shutdown (struct usb_serial *serial) | ||
| 792 | { | 899 | { |
| 793 | int i; | 900 | int i; |
| 794 | struct pl2303_private *priv; | 901 | struct pl2303_private *priv; |
| @@ -802,7 +909,7 @@ static void pl2303_shutdown (struct usb_serial *serial) | |||
| 802 | kfree(priv); | 909 | kfree(priv); |
| 803 | usb_set_serial_port_data(serial->port[i], NULL); | 910 | usb_set_serial_port_data(serial->port[i], NULL); |
| 804 | } | 911 | } |
| 805 | } | 912 | } |
| 806 | } | 913 | } |
| 807 | 914 | ||
| 808 | static void pl2303_update_line_status(struct usb_serial_port *port, | 915 | static void pl2303_update_line_status(struct usb_serial_port *port, |
| @@ -814,29 +921,33 @@ static void pl2303_update_line_status(struct usb_serial_port *port, | |||
| 814 | unsigned long flags; | 921 | unsigned long flags; |
| 815 | u8 status_idx = UART_STATE; | 922 | u8 status_idx = UART_STATE; |
| 816 | u8 length = UART_STATE + 1; | 923 | u8 length = UART_STATE + 1; |
| 924 | u16 idv, idp; | ||
| 925 | |||
| 926 | idv = le16_to_cpu(port->serial->dev->descriptor.idVendor); | ||
| 927 | idp = le16_to_cpu(port->serial->dev->descriptor.idProduct); | ||
| 817 | 928 | ||
| 818 | if ((le16_to_cpu(port->serial->dev->descriptor.idVendor) == SIEMENS_VENDOR_ID) && | 929 | |
| 819 | (le16_to_cpu(port->serial->dev->descriptor.idProduct) == SIEMENS_PRODUCT_ID_X65 || | 930 | if (idv == SIEMENS_VENDOR_ID) { |
| 820 | le16_to_cpu(port->serial->dev->descriptor.idProduct) == SIEMENS_PRODUCT_ID_SX1 || | 931 | if (idp == SIEMENS_PRODUCT_ID_X65 || |
| 821 | le16_to_cpu(port->serial->dev->descriptor.idProduct) == SIEMENS_PRODUCT_ID_X75)) { | 932 | idp == SIEMENS_PRODUCT_ID_SX1 || |
| 822 | length = 1; | 933 | idp == SIEMENS_PRODUCT_ID_X75) { |
| 823 | status_idx = 0; | 934 | |
| 935 | length = 1; | ||
| 936 | status_idx = 0; | ||
| 937 | } | ||
| 824 | } | 938 | } |
| 825 | 939 | ||
| 826 | if (actual_length < length) | 940 | if (actual_length < length) |
| 827 | goto exit; | 941 | return; |
| 828 | 942 | ||
| 829 | /* Save off the uart status for others to look at */ | 943 | /* Save off the uart status for others to look at */ |
| 830 | spin_lock_irqsave(&priv->lock, flags); | 944 | spin_lock_irqsave(&priv->lock, flags); |
| 831 | priv->line_status = data[status_idx]; | 945 | priv->line_status = data[status_idx]; |
| 832 | spin_unlock_irqrestore(&priv->lock, flags); | 946 | spin_unlock_irqrestore(&priv->lock, flags); |
| 833 | wake_up_interruptible (&priv->delta_msr_wait); | 947 | wake_up_interruptible(&priv->delta_msr_wait); |
| 834 | |||
| 835 | exit: | ||
| 836 | return; | ||
| 837 | } | 948 | } |
| 838 | 949 | ||
| 839 | static void pl2303_read_int_callback (struct urb *urb, struct pt_regs *regs) | 950 | static void pl2303_read_int_callback(struct urb *urb, struct pt_regs *regs) |
| 840 | { | 951 | { |
| 841 | struct usb_serial_port *port = (struct usb_serial_port *) urb->context; | 952 | struct usb_serial_port *port = (struct usb_serial_port *) urb->context; |
| 842 | unsigned char *data = urb->transfer_buffer; | 953 | unsigned char *data = urb->transfer_buffer; |
| @@ -853,25 +964,29 @@ static void pl2303_read_int_callback (struct urb *urb, struct pt_regs *regs) | |||
| 853 | case -ENOENT: | 964 | case -ENOENT: |
| 854 | case -ESHUTDOWN: | 965 | case -ESHUTDOWN: |
| 855 | /* this urb is terminated, clean up */ | 966 | /* this urb is terminated, clean up */ |
| 856 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); | 967 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, |
| 968 | urb->status); | ||
| 857 | return; | 969 | return; |
| 858 | default: | 970 | default: |
| 859 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); | 971 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, |
| 972 | urb->status); | ||
| 860 | goto exit; | 973 | goto exit; |
| 861 | } | 974 | } |
| 862 | 975 | ||
| 863 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, urb->transfer_buffer); | 976 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, |
| 977 | urb->actual_length, urb->transfer_buffer); | ||
| 978 | |||
| 864 | pl2303_update_line_status(port, data, actual_length); | 979 | pl2303_update_line_status(port, data, actual_length); |
| 865 | 980 | ||
| 866 | exit: | 981 | exit: |
| 867 | status = usb_submit_urb (urb, GFP_ATOMIC); | 982 | status = usb_submit_urb(urb, GFP_ATOMIC); |
| 868 | if (status) | 983 | if (status) |
| 869 | dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n", | 984 | dev_err(&urb->dev->dev, |
| 985 | "%s - usb_submit_urb failed with result %d\n", | ||
| 870 | __FUNCTION__, status); | 986 | __FUNCTION__, status); |
| 871 | } | 987 | } |
| 872 | 988 | ||
| 873 | 989 | static void pl2303_read_bulk_callback(struct urb *urb, struct pt_regs *regs) | |
| 874 | static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs) | ||
| 875 | { | 990 | { |
| 876 | struct usb_serial_port *port = (struct usb_serial_port *) urb->context; | 991 | struct usb_serial_port *port = (struct usb_serial_port *) urb->context; |
| 877 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 992 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
| @@ -892,20 +1007,25 @@ static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs) | |||
| 892 | return; | 1007 | return; |
| 893 | } | 1008 | } |
| 894 | if (urb->status == -EPROTO) { | 1009 | if (urb->status == -EPROTO) { |
| 895 | /* PL2303 mysteriously fails with -EPROTO reschedule the read */ | 1010 | /* PL2303 mysteriously fails with -EPROTO reschedule |
| 896 | dbg("%s - caught -EPROTO, resubmitting the urb", __FUNCTION__); | 1011 | * the read */ |
| 1012 | dbg("%s - caught -EPROTO, resubmitting the urb", | ||
| 1013 | __FUNCTION__); | ||
| 897 | urb->status = 0; | 1014 | urb->status = 0; |
| 898 | urb->dev = port->serial->dev; | 1015 | urb->dev = port->serial->dev; |
| 899 | result = usb_submit_urb(urb, GFP_ATOMIC); | 1016 | result = usb_submit_urb(urb, GFP_ATOMIC); |
| 900 | if (result) | 1017 | if (result) |
| 901 | dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); | 1018 | dev_err(&urb->dev->dev, "%s - failed" |
| 1019 | " resubmitting read urb, error %d\n", | ||
| 1020 | __FUNCTION__, result); | ||
| 902 | return; | 1021 | return; |
| 903 | } | 1022 | } |
| 904 | dbg("%s - unable to handle the error, exiting.", __FUNCTION__); | 1023 | dbg("%s - unable to handle the error, exiting.", __FUNCTION__); |
| 905 | return; | 1024 | return; |
| 906 | } | 1025 | } |
| 907 | 1026 | ||
| 908 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); | 1027 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, |
| 1028 | urb->actual_length, data); | ||
| 909 | 1029 | ||
| 910 | /* get tty_flag from status */ | 1030 | /* get tty_flag from status */ |
| 911 | tty_flag = TTY_NORMAL; | 1031 | tty_flag = TTY_NORMAL; |
| @@ -914,7 +1034,7 @@ static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs) | |||
| 914 | status = priv->line_status; | 1034 | status = priv->line_status; |
| 915 | priv->line_status &= ~UART_STATE_TRANSIENT_MASK; | 1035 | priv->line_status &= ~UART_STATE_TRANSIENT_MASK; |
| 916 | spin_unlock_irqrestore(&priv->lock, flags); | 1036 | spin_unlock_irqrestore(&priv->lock, flags); |
| 917 | wake_up_interruptible (&priv->delta_msr_wait); | 1037 | wake_up_interruptible(&priv->delta_msr_wait); |
| 918 | 1038 | ||
| 919 | /* break takes precedence over parity, */ | 1039 | /* break takes precedence over parity, */ |
| 920 | /* which takes precedence over framing errors */ | 1040 | /* which takes precedence over framing errors */ |
| @@ -933,8 +1053,8 @@ static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs) | |||
| 933 | if (status & UART_OVERRUN_ERROR) | 1053 | if (status & UART_OVERRUN_ERROR) |
| 934 | tty_insert_flip_char(tty, 0, TTY_OVERRUN); | 1054 | tty_insert_flip_char(tty, 0, TTY_OVERRUN); |
| 935 | for (i = 0; i < urb->actual_length; ++i) | 1055 | for (i = 0; i < urb->actual_length; ++i) |
| 936 | tty_insert_flip_char (tty, data[i], tty_flag); | 1056 | tty_insert_flip_char(tty, data[i], tty_flag); |
| 937 | tty_flip_buffer_push (tty); | 1057 | tty_flip_buffer_push(tty); |
| 938 | } | 1058 | } |
| 939 | 1059 | ||
| 940 | /* Schedule the next read _if_ we are still open */ | 1060 | /* Schedule the next read _if_ we are still open */ |
| @@ -942,15 +1062,14 @@ static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs) | |||
| 942 | urb->dev = port->serial->dev; | 1062 | urb->dev = port->serial->dev; |
| 943 | result = usb_submit_urb(urb, GFP_ATOMIC); | 1063 | result = usb_submit_urb(urb, GFP_ATOMIC); |
| 944 | if (result) | 1064 | if (result) |
| 945 | dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); | 1065 | dev_err(&urb->dev->dev, "%s - failed resubmitting" |
| 1066 | " read urb, error %d\n", __FUNCTION__, result); | ||
| 946 | } | 1067 | } |
| 947 | 1068 | ||
| 948 | return; | 1069 | return; |
| 949 | } | 1070 | } |
| 950 | 1071 | ||
| 951 | 1072 | static void pl2303_write_bulk_callback(struct urb *urb, struct pt_regs *regs) | |
| 952 | |||
| 953 | static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs) | ||
| 954 | { | 1073 | { |
| 955 | struct usb_serial_port *port = (struct usb_serial_port *) urb->context; | 1074 | struct usb_serial_port *port = (struct usb_serial_port *) urb->context; |
| 956 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 1075 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
| @@ -966,18 +1085,21 @@ static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs) | |||
| 966 | case -ENOENT: | 1085 | case -ENOENT: |
| 967 | case -ESHUTDOWN: | 1086 | case -ESHUTDOWN: |
| 968 | /* this urb is terminated, clean up */ | 1087 | /* this urb is terminated, clean up */ |
| 969 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); | 1088 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, |
| 1089 | urb->status); | ||
| 970 | priv->write_urb_in_use = 0; | 1090 | priv->write_urb_in_use = 0; |
| 971 | return; | 1091 | return; |
| 972 | default: | 1092 | default: |
| 973 | /* error in the urb, so we have to resubmit it */ | 1093 | /* error in the urb, so we have to resubmit it */ |
| 974 | dbg("%s - Overflow in write", __FUNCTION__); | 1094 | dbg("%s - Overflow in write", __FUNCTION__); |
| 975 | dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); | 1095 | dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, |
| 1096 | urb->status); | ||
| 976 | port->write_urb->transfer_buffer_length = 1; | 1097 | port->write_urb->transfer_buffer_length = 1; |
| 977 | port->write_urb->dev = port->serial->dev; | 1098 | port->write_urb->dev = port->serial->dev; |
| 978 | result = usb_submit_urb (port->write_urb, GFP_ATOMIC); | 1099 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); |
| 979 | if (result) | 1100 | if (result) |
| 980 | dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n", __FUNCTION__, result); | 1101 | dev_err(&urb->dev->dev, "%s - failed resubmitting write" |
| 1102 | " urb, error %d\n", __FUNCTION__, result); | ||
| 981 | else | 1103 | else |
| 982 | return; | 1104 | return; |
| 983 | } | 1105 | } |
| @@ -988,191 +1110,38 @@ static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs) | |||
| 988 | pl2303_send(port); | 1110 | pl2303_send(port); |
| 989 | } | 1111 | } |
| 990 | 1112 | ||
| 1113 | /* All of the device info needed for the PL2303 SIO serial converter */ | ||
| 1114 | static struct usb_serial_driver pl2303_device = { | ||
| 1115 | .driver = { | ||
| 1116 | .owner = THIS_MODULE, | ||
| 1117 | .name = "pl2303", | ||
| 1118 | }, | ||
| 1119 | .id_table = id_table, | ||
| 1120 | .num_interrupt_in = NUM_DONT_CARE, | ||
| 1121 | .num_bulk_in = 1, | ||
| 1122 | .num_bulk_out = 1, | ||
| 1123 | .num_ports = 1, | ||
| 1124 | .open = pl2303_open, | ||
| 1125 | .close = pl2303_close, | ||
| 1126 | .write = pl2303_write, | ||
| 1127 | .ioctl = pl2303_ioctl, | ||
| 1128 | .break_ctl = pl2303_break_ctl, | ||
| 1129 | .set_termios = pl2303_set_termios, | ||
| 1130 | .tiocmget = pl2303_tiocmget, | ||
| 1131 | .tiocmset = pl2303_tiocmset, | ||
| 1132 | .read_bulk_callback = pl2303_read_bulk_callback, | ||
| 1133 | .read_int_callback = pl2303_read_int_callback, | ||
| 1134 | .write_bulk_callback = pl2303_write_bulk_callback, | ||
| 1135 | .write_room = pl2303_write_room, | ||
| 1136 | .chars_in_buffer = pl2303_chars_in_buffer, | ||
| 1137 | .attach = pl2303_startup, | ||
| 1138 | .shutdown = pl2303_shutdown, | ||
| 1139 | }; | ||
| 991 | 1140 | ||
| 992 | /* | 1141 | static int __init pl2303_init(void) |
| 993 | * pl2303_buf_alloc | ||
| 994 | * | ||
| 995 | * Allocate a circular buffer and all associated memory. | ||
| 996 | */ | ||
| 997 | |||
| 998 | static struct pl2303_buf *pl2303_buf_alloc(unsigned int size) | ||
| 999 | { | ||
| 1000 | |||
| 1001 | struct pl2303_buf *pb; | ||
| 1002 | |||
| 1003 | |||
| 1004 | if (size == 0) | ||
| 1005 | return NULL; | ||
| 1006 | |||
| 1007 | pb = (struct pl2303_buf *)kmalloc(sizeof(struct pl2303_buf), GFP_KERNEL); | ||
| 1008 | if (pb == NULL) | ||
| 1009 | return NULL; | ||
| 1010 | |||
| 1011 | pb->buf_buf = kmalloc(size, GFP_KERNEL); | ||
| 1012 | if (pb->buf_buf == NULL) { | ||
| 1013 | kfree(pb); | ||
| 1014 | return NULL; | ||
| 1015 | } | ||
| 1016 | |||
| 1017 | pb->buf_size = size; | ||
| 1018 | pb->buf_get = pb->buf_put = pb->buf_buf; | ||
| 1019 | |||
| 1020 | return pb; | ||
| 1021 | |||
| 1022 | } | ||
| 1023 | |||
| 1024 | |||
| 1025 | /* | ||
| 1026 | * pl2303_buf_free | ||
| 1027 | * | ||
| 1028 | * Free the buffer and all associated memory. | ||
| 1029 | */ | ||
| 1030 | |||
| 1031 | static void pl2303_buf_free(struct pl2303_buf *pb) | ||
| 1032 | { | ||
| 1033 | if (pb) { | ||
| 1034 | kfree(pb->buf_buf); | ||
| 1035 | kfree(pb); | ||
| 1036 | } | ||
| 1037 | } | ||
| 1038 | |||
| 1039 | |||
| 1040 | /* | ||
| 1041 | * pl2303_buf_clear | ||
| 1042 | * | ||
| 1043 | * Clear out all data in the circular buffer. | ||
| 1044 | */ | ||
| 1045 | |||
| 1046 | static void pl2303_buf_clear(struct pl2303_buf *pb) | ||
| 1047 | { | ||
| 1048 | if (pb != NULL) | ||
| 1049 | pb->buf_get = pb->buf_put; | ||
| 1050 | /* equivalent to a get of all data available */ | ||
| 1051 | } | ||
| 1052 | |||
| 1053 | |||
| 1054 | /* | ||
| 1055 | * pl2303_buf_data_avail | ||
| 1056 | * | ||
| 1057 | * Return the number of bytes of data available in the circular | ||
| 1058 | * buffer. | ||
| 1059 | */ | ||
| 1060 | |||
| 1061 | static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb) | ||
| 1062 | { | ||
| 1063 | if (pb != NULL) | ||
| 1064 | return ((pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size); | ||
| 1065 | else | ||
| 1066 | return 0; | ||
| 1067 | } | ||
| 1068 | |||
| 1069 | |||
| 1070 | /* | ||
| 1071 | * pl2303_buf_space_avail | ||
| 1072 | * | ||
| 1073 | * Return the number of bytes of space available in the circular | ||
| 1074 | * buffer. | ||
| 1075 | */ | ||
| 1076 | |||
| 1077 | static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb) | ||
| 1078 | { | ||
| 1079 | if (pb != NULL) | ||
| 1080 | return ((pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size); | ||
| 1081 | else | ||
| 1082 | return 0; | ||
| 1083 | } | ||
| 1084 | |||
| 1085 | |||
| 1086 | /* | ||
| 1087 | * pl2303_buf_put | ||
| 1088 | * | ||
| 1089 | * Copy data data from a user buffer and put it into the circular buffer. | ||
| 1090 | * Restrict to the amount of space available. | ||
| 1091 | * | ||
| 1092 | * Return the number of bytes copied. | ||
| 1093 | */ | ||
| 1094 | |||
| 1095 | static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf, | ||
| 1096 | unsigned int count) | ||
| 1097 | { | ||
| 1098 | |||
| 1099 | unsigned int len; | ||
| 1100 | |||
| 1101 | |||
| 1102 | if (pb == NULL) | ||
| 1103 | return 0; | ||
| 1104 | |||
| 1105 | len = pl2303_buf_space_avail(pb); | ||
| 1106 | if (count > len) | ||
| 1107 | count = len; | ||
| 1108 | |||
| 1109 | if (count == 0) | ||
| 1110 | return 0; | ||
| 1111 | |||
| 1112 | len = pb->buf_buf + pb->buf_size - pb->buf_put; | ||
| 1113 | if (count > len) { | ||
| 1114 | memcpy(pb->buf_put, buf, len); | ||
| 1115 | memcpy(pb->buf_buf, buf+len, count - len); | ||
| 1116 | pb->buf_put = pb->buf_buf + count - len; | ||
| 1117 | } else { | ||
| 1118 | memcpy(pb->buf_put, buf, count); | ||
| 1119 | if (count < len) | ||
| 1120 | pb->buf_put += count; | ||
| 1121 | else /* count == len */ | ||
| 1122 | pb->buf_put = pb->buf_buf; | ||
| 1123 | } | ||
| 1124 | |||
| 1125 | return count; | ||
| 1126 | |||
| 1127 | } | ||
| 1128 | |||
| 1129 | |||
| 1130 | /* | ||
| 1131 | * pl2303_buf_get | ||
| 1132 | * | ||
| 1133 | * Get data from the circular buffer and copy to the given buffer. | ||
| 1134 | * Restrict to the amount of data available. | ||
| 1135 | * | ||
| 1136 | * Return the number of bytes copied. | ||
| 1137 | */ | ||
| 1138 | |||
| 1139 | static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf, | ||
| 1140 | unsigned int count) | ||
| 1141 | { | ||
| 1142 | |||
| 1143 | unsigned int len; | ||
| 1144 | |||
| 1145 | |||
| 1146 | if (pb == NULL) | ||
| 1147 | return 0; | ||
| 1148 | |||
| 1149 | len = pl2303_buf_data_avail(pb); | ||
| 1150 | if (count > len) | ||
| 1151 | count = len; | ||
| 1152 | |||
| 1153 | if (count == 0) | ||
| 1154 | return 0; | ||
| 1155 | |||
| 1156 | len = pb->buf_buf + pb->buf_size - pb->buf_get; | ||
| 1157 | if (count > len) { | ||
| 1158 | memcpy(buf, pb->buf_get, len); | ||
| 1159 | memcpy(buf+len, pb->buf_buf, count - len); | ||
| 1160 | pb->buf_get = pb->buf_buf + count - len; | ||
| 1161 | } else { | ||
| 1162 | memcpy(buf, pb->buf_get, count); | ||
| 1163 | if (count < len) | ||
| 1164 | pb->buf_get += count; | ||
| 1165 | else /* count == len */ | ||
| 1166 | pb->buf_get = pb->buf_buf; | ||
| 1167 | } | ||
| 1168 | |||
| 1169 | return count; | ||
| 1170 | |||
| 1171 | } | ||
| 1172 | |||
| 1173 | static int __init pl2303_init (void) | ||
| 1174 | { | 1142 | { |
| 1175 | int retval; | 1143 | int retval; |
| 1144 | |||
| 1176 | retval = usb_serial_register(&pl2303_device); | 1145 | retval = usb_serial_register(&pl2303_device); |
| 1177 | if (retval) | 1146 | if (retval) |
| 1178 | goto failed_usb_serial_register; | 1147 | goto failed_usb_serial_register; |
| @@ -1187,14 +1156,12 @@ failed_usb_serial_register: | |||
| 1187 | return retval; | 1156 | return retval; |
| 1188 | } | 1157 | } |
| 1189 | 1158 | ||
| 1190 | 1159 | static void __exit pl2303_exit(void) | |
| 1191 | static void __exit pl2303_exit (void) | ||
| 1192 | { | 1160 | { |
| 1193 | usb_deregister (&pl2303_driver); | 1161 | usb_deregister(&pl2303_driver); |
| 1194 | usb_serial_deregister (&pl2303_device); | 1162 | usb_serial_deregister(&pl2303_device); |
| 1195 | } | 1163 | } |
| 1196 | 1164 | ||
| 1197 | |||
| 1198 | module_init(pl2303_init); | 1165 | module_init(pl2303_init); |
| 1199 | module_exit(pl2303_exit); | 1166 | module_exit(pl2303_exit); |
| 1200 | 1167 | ||
