diff options
-rw-r--r-- | drivers/usb/serial/cp210x.c | 137 |
1 files changed, 24 insertions, 113 deletions
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index 666e4c562d88..c7405928dfcd 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c | |||
@@ -324,105 +324,6 @@ struct cp210x_comm_status { | |||
324 | #define PURGE_ALL 0x000f | 324 | #define PURGE_ALL 0x000f |
325 | 325 | ||
326 | /* | 326 | /* |
327 | * cp210x_get_config | ||
328 | * Reads from the CP210x configuration registers | ||
329 | * 'size' is specified in bytes. | ||
330 | * 'data' is a pointer to a pre-allocated array of integers large | ||
331 | * enough to hold 'size' bytes (with 4 bytes to each integer) | ||
332 | */ | ||
333 | static int cp210x_get_config(struct usb_serial_port *port, u8 request, | ||
334 | unsigned int *data, int size) | ||
335 | { | ||
336 | struct usb_serial *serial = port->serial; | ||
337 | struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); | ||
338 | __le32 *buf; | ||
339 | int result, i, length; | ||
340 | |||
341 | /* Number of integers required to contain the array */ | ||
342 | length = (((size - 1) | 3) + 1) / 4; | ||
343 | |||
344 | buf = kcalloc(length, sizeof(__le32), GFP_KERNEL); | ||
345 | if (!buf) | ||
346 | return -ENOMEM; | ||
347 | |||
348 | /* Issue the request, attempting to read 'size' bytes */ | ||
349 | result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | ||
350 | request, REQTYPE_INTERFACE_TO_HOST, 0x0000, | ||
351 | port_priv->bInterfaceNumber, buf, size, | ||
352 | USB_CTRL_GET_TIMEOUT); | ||
353 | |||
354 | /* Convert data into an array of integers */ | ||
355 | for (i = 0; i < length; i++) | ||
356 | data[i] = le32_to_cpu(buf[i]); | ||
357 | |||
358 | kfree(buf); | ||
359 | |||
360 | if (result != size) { | ||
361 | dev_dbg(&port->dev, "%s - Unable to send config request, request=0x%x size=%d result=%d\n", | ||
362 | __func__, request, size, result); | ||
363 | if (result > 0) | ||
364 | result = -EPROTO; | ||
365 | |||
366 | return result; | ||
367 | } | ||
368 | |||
369 | return 0; | ||
370 | } | ||
371 | |||
372 | /* | ||
373 | * cp210x_set_config | ||
374 | * Writes to the CP210x configuration registers | ||
375 | * Values less than 16 bits wide are sent directly | ||
376 | * 'size' is specified in bytes. | ||
377 | */ | ||
378 | static int cp210x_set_config(struct usb_serial_port *port, u8 request, | ||
379 | unsigned int *data, int size) | ||
380 | { | ||
381 | struct usb_serial *serial = port->serial; | ||
382 | struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); | ||
383 | __le32 *buf; | ||
384 | int result, i, length; | ||
385 | |||
386 | /* Number of integers required to contain the array */ | ||
387 | length = (((size - 1) | 3) + 1) / 4; | ||
388 | |||
389 | buf = kmalloc(length * sizeof(__le32), GFP_KERNEL); | ||
390 | if (!buf) | ||
391 | return -ENOMEM; | ||
392 | |||
393 | /* Array of integers into bytes */ | ||
394 | for (i = 0; i < length; i++) | ||
395 | buf[i] = cpu_to_le32(data[i]); | ||
396 | |||
397 | if (size > 2) { | ||
398 | result = usb_control_msg(serial->dev, | ||
399 | usb_sndctrlpipe(serial->dev, 0), | ||
400 | request, REQTYPE_HOST_TO_INTERFACE, 0x0000, | ||
401 | port_priv->bInterfaceNumber, buf, size, | ||
402 | USB_CTRL_SET_TIMEOUT); | ||
403 | } else { | ||
404 | result = usb_control_msg(serial->dev, | ||
405 | usb_sndctrlpipe(serial->dev, 0), | ||
406 | request, REQTYPE_HOST_TO_INTERFACE, data[0], | ||
407 | port_priv->bInterfaceNumber, NULL, 0, | ||
408 | USB_CTRL_SET_TIMEOUT); | ||
409 | } | ||
410 | |||
411 | kfree(buf); | ||
412 | |||
413 | if ((size > 2 && result != size) || result < 0) { | ||
414 | dev_dbg(&port->dev, "%s - Unable to send request, request=0x%x size=%d result=%d\n", | ||
415 | __func__, request, size, result); | ||
416 | if (result > 0) | ||
417 | result = -EPROTO; | ||
418 | |||
419 | return result; | ||
420 | } | ||
421 | |||
422 | return 0; | ||
423 | } | ||
424 | |||
425 | /* | ||
426 | * Reads a variable-sized block of CP210X_ registers, identified by req. | 327 | * Reads a variable-sized block of CP210X_ registers, identified by req. |
427 | * Returns data into buf in native USB byte order. | 328 | * Returns data into buf in native USB byte order. |
428 | */ | 329 | */ |
@@ -788,7 +689,8 @@ static void cp210x_get_termios_port(struct usb_serial_port *port, | |||
788 | unsigned int *cflagp, unsigned int *baudp) | 689 | unsigned int *cflagp, unsigned int *baudp) |
789 | { | 690 | { |
790 | struct device *dev = &port->dev; | 691 | struct device *dev = &port->dev; |
791 | unsigned int cflag, modem_ctl[4]; | 692 | unsigned int cflag; |
693 | u8 modem_ctl[16]; | ||
792 | u32 baud; | 694 | u32 baud; |
793 | u16 bits; | 695 | u16 bits; |
794 | 696 | ||
@@ -886,8 +788,9 @@ static void cp210x_get_termios_port(struct usb_serial_port *port, | |||
886 | break; | 788 | break; |
887 | } | 789 | } |
888 | 790 | ||
889 | cp210x_get_config(port, CP210X_GET_FLOW, modem_ctl, 16); | 791 | cp210x_read_reg_block(port, CP210X_GET_FLOW, modem_ctl, |
890 | if (modem_ctl[0] & 0x0008) { | 792 | sizeof(modem_ctl)); |
793 | if (modem_ctl[0] & 0x08) { | ||
891 | dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__); | 794 | dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__); |
892 | cflag |= CRTSCTS; | 795 | cflag |= CRTSCTS; |
893 | } else { | 796 | } else { |
@@ -956,7 +859,7 @@ static void cp210x_set_termios(struct tty_struct *tty, | |||
956 | struct device *dev = &port->dev; | 859 | struct device *dev = &port->dev; |
957 | unsigned int cflag, old_cflag; | 860 | unsigned int cflag, old_cflag; |
958 | u16 bits; | 861 | u16 bits; |
959 | unsigned int modem_ctl[4]; | 862 | u8 modem_ctl[16]; |
960 | 863 | ||
961 | cflag = tty->termios.c_cflag; | 864 | cflag = tty->termios.c_cflag; |
962 | old_cflag = old_termios->c_cflag; | 865 | old_cflag = old_termios->c_cflag; |
@@ -1040,27 +943,35 @@ static void cp210x_set_termios(struct tty_struct *tty, | |||
1040 | } | 943 | } |
1041 | 944 | ||
1042 | if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) { | 945 | if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) { |
1043 | cp210x_get_config(port, CP210X_GET_FLOW, modem_ctl, 16); | 946 | |
1044 | dev_dbg(dev, "%s - read modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x\n", | 947 | /* Only bytes 0, 4 and 7 out of first 8 have functional bits */ |
1045 | __func__, modem_ctl[0], modem_ctl[1], | 948 | |
1046 | modem_ctl[2], modem_ctl[3]); | 949 | cp210x_read_reg_block(port, CP210X_GET_FLOW, modem_ctl, |
950 | sizeof(modem_ctl)); | ||
951 | dev_dbg(dev, "%s - read modem controls = %02x .. .. .. %02x .. .. %02x\n", | ||
952 | __func__, modem_ctl[0], modem_ctl[4], modem_ctl[7]); | ||
1047 | 953 | ||
1048 | if (cflag & CRTSCTS) { | 954 | if (cflag & CRTSCTS) { |
1049 | modem_ctl[0] &= ~0x7B; | 955 | modem_ctl[0] &= ~0x7B; |
1050 | modem_ctl[0] |= 0x09; | 956 | modem_ctl[0] |= 0x09; |
1051 | modem_ctl[1] = 0x80; | 957 | modem_ctl[4] = 0x80; |
958 | /* FIXME - why clear reserved bits just read? */ | ||
959 | modem_ctl[5] = 0; | ||
960 | modem_ctl[6] = 0; | ||
961 | modem_ctl[7] = 0; | ||
1052 | dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__); | 962 | dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__); |
1053 | } else { | 963 | } else { |
1054 | modem_ctl[0] &= ~0x7B; | 964 | modem_ctl[0] &= ~0x7B; |
1055 | modem_ctl[0] |= 0x01; | 965 | modem_ctl[0] |= 0x01; |
1056 | modem_ctl[1] |= 0x40; | 966 | /* FIXME - OR here instead of assignment looks wrong */ |
967 | modem_ctl[4] |= 0x40; | ||
1057 | dev_dbg(dev, "%s - flow control = NONE\n", __func__); | 968 | dev_dbg(dev, "%s - flow control = NONE\n", __func__); |
1058 | } | 969 | } |
1059 | 970 | ||
1060 | dev_dbg(dev, "%s - write modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x\n", | 971 | dev_dbg(dev, "%s - write modem controls = %02x .. .. .. %02x .. .. %02x\n", |
1061 | __func__, modem_ctl[0], modem_ctl[1], | 972 | __func__, modem_ctl[0], modem_ctl[4], modem_ctl[7]); |
1062 | modem_ctl[2], modem_ctl[3]); | 973 | cp210x_write_reg_block(port, CP210X_SET_FLOW, modem_ctl, |
1063 | cp210x_set_config(port, CP210X_SET_FLOW, modem_ctl, 16); | 974 | sizeof(modem_ctl)); |
1064 | } | 975 | } |
1065 | 976 | ||
1066 | } | 977 | } |