cp210x.c (19165b2b10a3b3d18b32a6add465379deade0736) | cp210x.c (fe1b07e99ce572a870711d4c989baf031468093b) |
---|---|
1/* 2 * Silicon Laboratories CP210x USB to RS232 serial adaptor driver 3 * 4 * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk) 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License version 8 * 2 as published by the Free Software Foundation. --- 456 unchanged lines hidden (view full) --- 465 } 466 467 kfree(dmabuf); 468 469 return result; 470} 471 472/* | 1/* 2 * Silicon Laboratories CP210x USB to RS232 serial adaptor driver 3 * 4 * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk) 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License version 8 * 2 as published by the Free Software Foundation. --- 456 unchanged lines hidden (view full) --- 465 } 466 467 kfree(dmabuf); 468 469 return result; 470} 471 472/* |
473 * Reads any 32-bit CP210X_ register identified by req. 474 */ 475static int cp210x_read_u32_reg(struct usb_serial_port *port, u8 req, u32 *val) 476{ 477 __le32 le32_val; 478 int err; 479 480 err = cp210x_read_reg_block(port, req, &le32_val, sizeof(le32_val)); 481 if (err) { 482 /* 483 * FIXME Some callers don't bother to check for error, 484 * at least give them consistent junk until they are fixed 485 */ 486 *val = 0; 487 return err; 488 } 489 490 *val = le32_to_cpu(le32_val); 491 492 return 0; 493} 494 495/* |
|
473 * Reads any 16-bit CP210X_ register identified by req. 474 */ 475static int cp210x_read_u16_reg(struct usb_serial_port *port, u8 req, u16 *val) 476{ 477 __le16 le16_val; 478 int err; 479 480 err = cp210x_read_reg_block(port, req, &le16_val, sizeof(le16_val)); 481 if (err) 482 return err; 483 484 *val = le16_to_cpu(le16_val); | 496 * Reads any 16-bit CP210X_ register identified by req. 497 */ 498static int cp210x_read_u16_reg(struct usb_serial_port *port, u8 req, u16 *val) 499{ 500 __le16 le16_val; 501 int err; 502 503 err = cp210x_read_reg_block(port, req, &le16_val, sizeof(le16_val)); 504 if (err) 505 return err; 506 507 *val = le16_to_cpu(le16_val); |
508 |
|
485 return 0; 486} 487 488/* | 509 return 0; 510} 511 512/* |
513 * Reads any 8-bit CP210X_ register identified by req. 514 */ 515static int cp210x_read_u8_reg(struct usb_serial_port *port, u8 req, u8 *val) 516{ 517 return cp210x_read_reg_block(port, req, val, sizeof(*val)); 518} 519 520/* |
|
489 * Writes any 16-bit CP210X_ register (req) whose value is passed 490 * entirely in the wValue field of the USB request. 491 */ 492static int cp210x_write_u16_reg(struct usb_serial_port *port, u8 req, u16 val) 493{ 494 struct usb_serial *serial = port->serial; 495 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); 496 int result; --- 6 unchanged lines hidden (view full) --- 503 dev_err(&port->dev, "failed set request 0x%x status: %d\n", 504 req, result); 505 } 506 507 return result; 508} 509 510/* | 521 * Writes any 16-bit CP210X_ register (req) whose value is passed 522 * entirely in the wValue field of the USB request. 523 */ 524static int cp210x_write_u16_reg(struct usb_serial_port *port, u8 req, u16 val) 525{ 526 struct usb_serial *serial = port->serial; 527 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); 528 int result; --- 6 unchanged lines hidden (view full) --- 535 dev_err(&port->dev, "failed set request 0x%x status: %d\n", 536 req, result); 537 } 538 539 return result; 540} 541 542/* |
543 * Writes a variable-sized block of CP210X_ registers, identified by req. 544 * Data in buf must be in native USB byte order. 545 */ 546static int cp210x_write_reg_block(struct usb_serial_port *port, u8 req, 547 void *buf, int bufsize) 548{ 549 struct usb_serial *serial = port->serial; 550 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); 551 void *dmabuf; 552 int result; 553 554 dmabuf = kmalloc(bufsize, GFP_KERNEL); 555 if (!dmabuf) 556 return -ENOMEM; 557 558 memcpy(dmabuf, buf, bufsize); 559 560 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 561 req, REQTYPE_HOST_TO_INTERFACE, 0, 562 port_priv->bInterfaceNumber, dmabuf, bufsize, 563 USB_CTRL_SET_TIMEOUT); 564 565 kfree(dmabuf); 566 567 if (result == bufsize) { 568 result = 0; 569 } else { 570 dev_err(&port->dev, "failed set req 0x%x size %d status: %d\n", 571 req, bufsize, result); 572 if (result >= 0) 573 result = -EPROTO; 574 } 575 576 return result; 577} 578 579/* 580 * Writes any 32-bit CP210X_ register identified by req. 581 */ 582static int cp210x_write_u32_reg(struct usb_serial_port *port, u8 req, u32 val) 583{ 584 __le32 le32_val; 585 586 le32_val = cpu_to_le32(val); 587 588 return cp210x_write_reg_block(port, req, &le32_val, sizeof(le32_val)); 589} 590 591/* |
|
511 * Detect CP2108 GET_LINE_CTL bug and activate workaround. 512 * Write a known good value 0x800, read it back. 513 * If it comes back swapped the bug is detected. 514 * Preserve the original register value. 515 */ 516static int cp210x_detect_swapped_line_ctl(struct usb_serial_port *port) 517{ 518 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); --- 184 unchanged lines hidden (view full) --- 703 * cp210x_get_termios_port 704 * This is the heart of cp210x_get_termios which always uses a &usb_serial_port. 705 */ 706static void cp210x_get_termios_port(struct usb_serial_port *port, 707 unsigned int *cflagp, unsigned int *baudp) 708{ 709 struct device *dev = &port->dev; 710 unsigned int cflag, modem_ctl[4]; | 592 * Detect CP2108 GET_LINE_CTL bug and activate workaround. 593 * Write a known good value 0x800, read it back. 594 * If it comes back swapped the bug is detected. 595 * Preserve the original register value. 596 */ 597static int cp210x_detect_swapped_line_ctl(struct usb_serial_port *port) 598{ 599 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); --- 184 unchanged lines hidden (view full) --- 784 * cp210x_get_termios_port 785 * This is the heart of cp210x_get_termios which always uses a &usb_serial_port. 786 */ 787static void cp210x_get_termios_port(struct usb_serial_port *port, 788 unsigned int *cflagp, unsigned int *baudp) 789{ 790 struct device *dev = &port->dev; 791 unsigned int cflag, modem_ctl[4]; |
711 unsigned int baud; | 792 u32 baud; |
712 u16 bits; 713 | 793 u16 bits; 794 |
714 cp210x_get_config(port, CP210X_GET_BAUDRATE, &baud, 4); | 795 cp210x_read_u32_reg(port, CP210X_GET_BAUDRATE, &baud); |
715 716 dev_dbg(dev, "%s - baud rate = %d\n", __func__, baud); 717 *baudp = baud; 718 719 cflag = *cflagp; 720 721 cp210x_get_line_ctl(port, &bits); 722 cflag &= ~CSIZE; --- 130 unchanged lines hidden (view full) --- 853 /* This maps the requested rate to a rate valid on cp2102 or cp2103, 854 * or to an arbitrary rate in [1M,2M]. 855 * 856 * NOTE: B0 is not implemented. 857 */ 858 baud = cp210x_quantise_baudrate(baud); 859 860 dev_dbg(&port->dev, "%s - setting baud rate to %u\n", __func__, baud); | 796 797 dev_dbg(dev, "%s - baud rate = %d\n", __func__, baud); 798 *baudp = baud; 799 800 cflag = *cflagp; 801 802 cp210x_get_line_ctl(port, &bits); 803 cflag &= ~CSIZE; --- 130 unchanged lines hidden (view full) --- 934 /* This maps the requested rate to a rate valid on cp2102 or cp2103, 935 * or to an arbitrary rate in [1M,2M]. 936 * 937 * NOTE: B0 is not implemented. 938 */ 939 baud = cp210x_quantise_baudrate(baud); 940 941 dev_dbg(&port->dev, "%s - setting baud rate to %u\n", __func__, baud); |
861 if (cp210x_set_config(port, CP210X_SET_BAUDRATE, &baud, 862 sizeof(baud))) { | 942 if (cp210x_write_u32_reg(port, CP210X_SET_BAUDRATE, baud)) { |
863 dev_warn(&port->dev, "failed to set baud rate to %u\n", baud); 864 if (old_termios) 865 baud = old_termios->c_ospeed; 866 else 867 baud = 9600; 868 } 869 870 tty_encode_baud_rate(tty, baud, baud); --- 154 unchanged lines hidden (view full) --- 1025 cp210x_tiocmset_port(p, TIOCM_DTR|TIOCM_RTS, 0); 1026 else 1027 cp210x_tiocmset_port(p, 0, TIOCM_DTR|TIOCM_RTS); 1028} 1029 1030static int cp210x_tiocmget(struct tty_struct *tty) 1031{ 1032 struct usb_serial_port *port = tty->driver_data; | 943 dev_warn(&port->dev, "failed to set baud rate to %u\n", baud); 944 if (old_termios) 945 baud = old_termios->c_ospeed; 946 else 947 baud = 9600; 948 } 949 950 tty_encode_baud_rate(tty, baud, baud); --- 154 unchanged lines hidden (view full) --- 1105 cp210x_tiocmset_port(p, TIOCM_DTR|TIOCM_RTS, 0); 1106 else 1107 cp210x_tiocmset_port(p, 0, TIOCM_DTR|TIOCM_RTS); 1108} 1109 1110static int cp210x_tiocmget(struct tty_struct *tty) 1111{ 1112 struct usb_serial_port *port = tty->driver_data; |
1033 unsigned int control; | 1113 u8 control; |
1034 int result; 1035 | 1114 int result; 1115 |
1036 cp210x_get_config(port, CP210X_GET_MDMSTS, &control, 1); | 1116 cp210x_read_u8_reg(port, CP210X_GET_MDMSTS, &control); |
1037 1038 result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0) 1039 |((control & CONTROL_RTS) ? TIOCM_RTS : 0) 1040 |((control & CONTROL_CTS) ? TIOCM_CTS : 0) 1041 |((control & CONTROL_DSR) ? TIOCM_DSR : 0) 1042 |((control & CONTROL_RING)? TIOCM_RI : 0) 1043 |((control & CONTROL_DCD) ? TIOCM_CD : 0); 1044 --- 58 unchanged lines hidden --- | 1117 1118 result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0) 1119 |((control & CONTROL_RTS) ? TIOCM_RTS : 0) 1120 |((control & CONTROL_CTS) ? TIOCM_CTS : 0) 1121 |((control & CONTROL_DSR) ? TIOCM_DSR : 0) 1122 |((control & CONTROL_RING)? TIOCM_RI : 0) 1123 |((control & CONTROL_DCD) ? TIOCM_CD : 0); 1124 --- 58 unchanged lines hidden --- |