aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-01-13 09:05:21 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-01-13 09:05:21 -0500
commit2da050e4f151c458df909780843067e7c2d11ec2 (patch)
treec34f57cdcf70e17fd75a477edf116059af41fc54
parent0dbbad992bc544fff42124effc65d26ad0c84b99 (diff)
parentd1c48227d7c45fbb35c81f846a62ec92a74f4701 (diff)
Merge tag 'usb-serial-4.16-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial into usb-next
Johan writes: USB-serial updates for v4.16-rc1 Here are the USB-serial updates for 4.16-rc1, including: - a fix for a potential sleep-while-atomic (warning) in an io_edgeport error path - removal of a dummy TIOCSSERIAL implementation in ark3116 - new features for Fintek F81532/534 devices: - support for higher baud rates (up to 1.5 Mbps) - support for auto-RTS (for RS-485) - support for transceiver configuration - support for detecting disabled ports Included are also various clean ups. All have been (at least compile tested) in linux-next without any reported issues. Signed-off-by: Johan Hovold <johan@kernel.org>
-rw-r--r--drivers/usb/serial/ark3116.c49
-rw-r--r--drivers/usb/serial/f81534.c392
-rw-r--r--drivers/usb/serial/io_edgeport.c1
-rw-r--r--drivers/usb/serial/iuu_phoenix.c1
4 files changed, 318 insertions, 125 deletions
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 3c544782f60b..7796ad8e33c6 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -83,7 +83,10 @@ static int ark3116_write_reg(struct usb_serial *serial,
83 usb_sndctrlpipe(serial->dev, 0), 83 usb_sndctrlpipe(serial->dev, 0),
84 0xfe, 0x40, val, reg, 84 0xfe, 0x40, val, reg,
85 NULL, 0, ARK_TIMEOUT); 85 NULL, 0, ARK_TIMEOUT);
86 return result; 86 if (result)
87 return result;
88
89 return 0;
87} 90}
88 91
89static int ark3116_read_reg(struct usb_serial *serial, 92static int ark3116_read_reg(struct usb_serial *serial,
@@ -105,7 +108,7 @@ static int ark3116_read_reg(struct usb_serial *serial,
105 return result; 108 return result;
106 } 109 }
107 110
108 return buf[0]; 111 return 0;
109} 112}
110 113
111static inline int calc_divisor(int bps) 114static inline int calc_divisor(int bps)
@@ -355,13 +358,13 @@ static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port)
355 358
356 /* read modem status */ 359 /* read modem status */
357 result = ark3116_read_reg(serial, UART_MSR, buf); 360 result = ark3116_read_reg(serial, UART_MSR, buf);
358 if (result < 0) 361 if (result)
359 goto err_close; 362 goto err_close;
360 priv->msr = *buf; 363 priv->msr = *buf;
361 364
362 /* read line status */ 365 /* read line status */
363 result = ark3116_read_reg(serial, UART_LSR, buf); 366 result = ark3116_read_reg(serial, UART_LSR, buf);
364 if (result < 0) 367 if (result)
365 goto err_close; 368 goto err_close;
366 priv->lsr = *buf; 369 priv->lsr = *buf;
367 370
@@ -394,31 +397,35 @@ err_free:
394 return result; 397 return result;
395} 398}
396 399
400static int ark3116_get_serial_info(struct usb_serial_port *port,
401 struct serial_struct __user *retinfo)
402{
403 struct serial_struct tmp;
404
405 memset(&tmp, 0, sizeof(tmp));
406
407 tmp.type = PORT_16654;
408 tmp.line = port->minor;
409 tmp.port = port->port_number;
410 tmp.baud_base = 460800;
411
412 if (copy_to_user(retinfo, &tmp, sizeof(tmp)))
413 return -EFAULT;
414
415 return 0;
416}
417
397static int ark3116_ioctl(struct tty_struct *tty, 418static int ark3116_ioctl(struct tty_struct *tty,
398 unsigned int cmd, unsigned long arg) 419 unsigned int cmd, unsigned long arg)
399{ 420{
400 struct usb_serial_port *port = tty->driver_data; 421 struct usb_serial_port *port = tty->driver_data;
401 struct serial_struct serstruct;
402 void __user *user_arg = (void __user *)arg; 422 void __user *user_arg = (void __user *)arg;
403 423
404 switch (cmd) { 424 switch (cmd) {
405 case TIOCGSERIAL: 425 case TIOCGSERIAL:
406 /* XXX: Some of these values are probably wrong. */ 426 return ark3116_get_serial_info(port, user_arg);
407 memset(&serstruct, 0, sizeof(serstruct)); 427 default:
408 serstruct.type = PORT_16654; 428 break;
409 serstruct.line = port->minor;
410 serstruct.port = port->port_number;
411 serstruct.custom_divisor = 0;
412 serstruct.baud_base = 460800;
413
414 if (copy_to_user(user_arg, &serstruct, sizeof(serstruct)))
415 return -EFAULT;
416
417 return 0;
418 case TIOCSSERIAL:
419 if (copy_from_user(&serstruct, user_arg, sizeof(serstruct)))
420 return -EFAULT;
421 return 0;
422 } 429 }
423 430
424 return -ENOIOCTLCMD; 431 return -ENOIOCTLCMD;
diff --git a/drivers/usb/serial/f81534.c b/drivers/usb/serial/f81534.c
index e4573b4c8935..4dfbff20bda4 100644
--- a/drivers/usb/serial/f81534.c
+++ b/drivers/usb/serial/f81534.c
@@ -41,6 +41,7 @@
41#define F81534_MODEM_CONTROL_REG (0x04 + F81534_UART_BASE_ADDRESS) 41#define F81534_MODEM_CONTROL_REG (0x04 + F81534_UART_BASE_ADDRESS)
42#define F81534_LINE_STATUS_REG (0x05 + F81534_UART_BASE_ADDRESS) 42#define F81534_LINE_STATUS_REG (0x05 + F81534_UART_BASE_ADDRESS)
43#define F81534_MODEM_STATUS_REG (0x06 + F81534_UART_BASE_ADDRESS) 43#define F81534_MODEM_STATUS_REG (0x06 + F81534_UART_BASE_ADDRESS)
44#define F81534_CLOCK_REG (0x08 + F81534_UART_BASE_ADDRESS)
44#define F81534_CONFIG1_REG (0x09 + F81534_UART_BASE_ADDRESS) 45#define F81534_CONFIG1_REG (0x09 + F81534_UART_BASE_ADDRESS)
45 46
46#define F81534_DEF_CONF_ADDRESS_START 0x3000 47#define F81534_DEF_CONF_ADDRESS_START 0x3000
@@ -51,13 +52,14 @@
51#define F81534_CUSTOM_NO_CUSTOM_DATA 0xff 52#define F81534_CUSTOM_NO_CUSTOM_DATA 0xff
52#define F81534_CUSTOM_VALID_TOKEN 0xf0 53#define F81534_CUSTOM_VALID_TOKEN 0xf0
53#define F81534_CONF_OFFSET 1 54#define F81534_CONF_OFFSET 1
55#define F81534_CONF_GPIO_OFFSET 4
54 56
55#define F81534_MAX_DATA_BLOCK 64 57#define F81534_MAX_DATA_BLOCK 64
56#define F81534_MAX_BUS_RETRY 20 58#define F81534_MAX_BUS_RETRY 20
57 59
58/* Default URB timeout for USB operations */ 60/* Default URB timeout for USB operations */
59#define F81534_USB_MAX_RETRY 10 61#define F81534_USB_MAX_RETRY 10
60#define F81534_USB_TIMEOUT 1000 62#define F81534_USB_TIMEOUT 2000
61#define F81534_SET_GET_REGISTER 0xA0 63#define F81534_SET_GET_REGISTER 0xA0
62 64
63#define F81534_NUM_PORT 4 65#define F81534_NUM_PORT 4
@@ -96,16 +98,43 @@
96#define F81534_CMD_READ 0x03 98#define F81534_CMD_READ 0x03
97 99
98#define F81534_DEFAULT_BAUD_RATE 9600 100#define F81534_DEFAULT_BAUD_RATE 9600
99#define F81534_MAX_BAUDRATE 115200
100 101
102#define F81534_PORT_CONF_RS232 0
103#define F81534_PORT_CONF_RS485 BIT(0)
104#define F81534_PORT_CONF_RS485_INVERT (BIT(0) | BIT(1))
105#define F81534_PORT_CONF_MODE_MASK GENMASK(1, 0)
101#define F81534_PORT_CONF_DISABLE_PORT BIT(3) 106#define F81534_PORT_CONF_DISABLE_PORT BIT(3)
102#define F81534_PORT_CONF_NOT_EXIST_PORT BIT(7) 107#define F81534_PORT_CONF_NOT_EXIST_PORT BIT(7)
103#define F81534_PORT_UNAVAILABLE \ 108#define F81534_PORT_UNAVAILABLE \
104 (F81534_PORT_CONF_DISABLE_PORT | F81534_PORT_CONF_NOT_EXIST_PORT) 109 (F81534_PORT_CONF_DISABLE_PORT | F81534_PORT_CONF_NOT_EXIST_PORT)
105 110
111
106#define F81534_1X_RXTRIGGER 0xc3 112#define F81534_1X_RXTRIGGER 0xc3
107#define F81534_8X_RXTRIGGER 0xcf 113#define F81534_8X_RXTRIGGER 0xcf
108 114
115/*
116 * F81532/534 Clock registers (offset +08h)
117 *
118 * Bit0: UART Enable (always on)
119 * Bit2-1: Clock source selector
120 * 00: 1.846MHz.
121 * 01: 18.46MHz.
122 * 10: 24MHz.
123 * 11: 14.77MHz.
124 * Bit4: Auto direction(RTS) control (RTS pin Low when TX)
125 * Bit5: Invert direction(RTS) when Bit4 enabled (RTS pin high when TX)
126 */
127
128#define F81534_UART_EN BIT(0)
129#define F81534_CLK_1_846_MHZ 0
130#define F81534_CLK_18_46_MHZ BIT(1)
131#define F81534_CLK_24_MHZ BIT(2)
132#define F81534_CLK_14_77_MHZ (BIT(1) | BIT(2))
133#define F81534_CLK_MASK GENMASK(2, 1)
134#define F81534_CLK_TX_DELAY_1BIT BIT(3)
135#define F81534_CLK_RS485_MODE BIT(4)
136#define F81534_CLK_RS485_INVERT BIT(5)
137
109static const struct usb_device_id f81534_id_table[] = { 138static const struct usb_device_id f81534_id_table[] = {
110 { USB_DEVICE(FINTEK_VENDOR_ID_1, FINTEK_DEVICE_ID) }, 139 { USB_DEVICE(FINTEK_VENDOR_ID_1, FINTEK_DEVICE_ID) },
111 { USB_DEVICE(FINTEK_VENDOR_ID_2, FINTEK_DEVICE_ID) }, 140 { USB_DEVICE(FINTEK_VENDOR_ID_2, FINTEK_DEVICE_ID) },
@@ -129,12 +158,35 @@ struct f81534_port_private {
129 struct usb_serial_port *port; 158 struct usb_serial_port *port;
130 unsigned long tx_empty; 159 unsigned long tx_empty;
131 spinlock_t msr_lock; 160 spinlock_t msr_lock;
161 u32 baud_base;
132 u8 shadow_mcr; 162 u8 shadow_mcr;
133 u8 shadow_lcr; 163 u8 shadow_lcr;
134 u8 shadow_msr; 164 u8 shadow_msr;
165 u8 shadow_clk;
135 u8 phy_num; 166 u8 phy_num;
136}; 167};
137 168
169struct f81534_pin_data {
170 const u16 reg_addr;
171 const u8 reg_mask;
172};
173
174struct f81534_port_out_pin {
175 struct f81534_pin_data pin[3];
176};
177
178/* Pin output value for M2/M1/M0(SD) */
179static const struct f81534_port_out_pin f81534_port_out_pins[] = {
180 { { { 0x2ae8, BIT(7) }, { 0x2a90, BIT(5) }, { 0x2a90, BIT(4) } } },
181 { { { 0x2ae8, BIT(6) }, { 0x2ae8, BIT(0) }, { 0x2ae8, BIT(3) } } },
182 { { { 0x2a90, BIT(0) }, { 0x2ae8, BIT(2) }, { 0x2a80, BIT(6) } } },
183 { { { 0x2a90, BIT(3) }, { 0x2a90, BIT(2) }, { 0x2a90, BIT(1) } } },
184};
185
186static u32 const baudrate_table[] = { 115200, 921600, 1152000, 1500000 };
187static u8 const clock_table[] = { F81534_CLK_1_846_MHZ, F81534_CLK_14_77_MHZ,
188 F81534_CLK_18_46_MHZ, F81534_CLK_24_MHZ };
189
138static int f81534_logic_to_phy_port(struct usb_serial *serial, 190static int f81534_logic_to_phy_port(struct usb_serial *serial,
139 struct usb_serial_port *port) 191 struct usb_serial_port *port)
140{ 192{
@@ -240,6 +292,36 @@ end:
240 return status; 292 return status;
241} 293}
242 294
295static int f81534_set_mask_register(struct usb_serial *serial, u16 reg,
296 u8 mask, u8 data)
297{
298 int status;
299 u8 tmp;
300
301 status = f81534_get_register(serial, reg, &tmp);
302 if (status)
303 return status;
304
305 tmp &= ~mask;
306 tmp |= (mask & data);
307
308 return f81534_set_register(serial, reg, tmp);
309}
310
311static int f81534_set_phy_port_register(struct usb_serial *serial, int phy,
312 u16 reg, u8 data)
313{
314 return f81534_set_register(serial, reg + F81534_UART_OFFSET * phy,
315 data);
316}
317
318static int f81534_get_phy_port_register(struct usb_serial *serial, int phy,
319 u16 reg, u8 *data)
320{
321 return f81534_get_register(serial, reg + F81534_UART_OFFSET * phy,
322 data);
323}
324
243static int f81534_set_port_register(struct usb_serial_port *port, u16 reg, 325static int f81534_set_port_register(struct usb_serial_port *port, u16 reg,
244 u8 data) 326 u8 data)
245{ 327{
@@ -460,13 +542,52 @@ static u32 f81534_calc_baud_divisor(u32 baudrate, u32 clockrate)
460 return DIV_ROUND_CLOSEST(clockrate, baudrate); 542 return DIV_ROUND_CLOSEST(clockrate, baudrate);
461} 543}
462 544
463static int f81534_set_port_config(struct usb_serial_port *port, u32 baudrate, 545static int f81534_find_clk(u32 baudrate)
464 u8 lcr) 546{
547 int idx;
548
549 for (idx = 0; idx < ARRAY_SIZE(baudrate_table); ++idx) {
550 if (baudrate <= baudrate_table[idx] &&
551 baudrate_table[idx] % baudrate == 0)
552 return idx;
553 }
554
555 return -EINVAL;
556}
557
558static int f81534_set_port_config(struct usb_serial_port *port,
559 struct tty_struct *tty, u32 baudrate, u32 old_baudrate, u8 lcr)
465{ 560{
466 struct f81534_port_private *port_priv = usb_get_serial_port_data(port); 561 struct f81534_port_private *port_priv = usb_get_serial_port_data(port);
467 u32 divisor; 562 u32 divisor;
468 int status; 563 int status;
564 int i;
565 int idx;
469 u8 value; 566 u8 value;
567 u32 baud_list[] = {baudrate, old_baudrate, F81534_DEFAULT_BAUD_RATE};
568
569 for (i = 0; i < ARRAY_SIZE(baud_list); ++i) {
570 idx = f81534_find_clk(baud_list[i]);
571 if (idx >= 0) {
572 baudrate = baud_list[i];
573 tty_encode_baud_rate(tty, baudrate, baudrate);
574 break;
575 }
576 }
577
578 if (idx < 0)
579 return -EINVAL;
580
581 port_priv->baud_base = baudrate_table[idx];
582 port_priv->shadow_clk &= ~F81534_CLK_MASK;
583 port_priv->shadow_clk |= clock_table[idx];
584
585 status = f81534_set_port_register(port, F81534_CLOCK_REG,
586 port_priv->shadow_clk);
587 if (status) {
588 dev_err(&port->dev, "CLOCK_REG setting failed\n");
589 return status;
590 }
470 591
471 if (baudrate <= 1200) 592 if (baudrate <= 1200)
472 value = F81534_1X_RXTRIGGER; /* 128 FIFO & TL: 1x */ 593 value = F81534_1X_RXTRIGGER; /* 128 FIFO & TL: 1x */
@@ -482,7 +603,7 @@ static int f81534_set_port_config(struct usb_serial_port *port, u32 baudrate,
482 if (baudrate <= 1200) 603 if (baudrate <= 1200)
483 value = UART_FCR_TRIGGER_1 | UART_FCR_ENABLE_FIFO; /* TL: 1 */ 604 value = UART_FCR_TRIGGER_1 | UART_FCR_ENABLE_FIFO; /* TL: 1 */
484 else 605 else
485 value = UART_FCR_R_TRIG_11 | UART_FCR_ENABLE_FIFO; /* TL: 14 */ 606 value = UART_FCR_TRIGGER_8 | UART_FCR_ENABLE_FIFO; /* TL: 8 */
486 607
487 status = f81534_set_port_register(port, F81534_FIFO_CONTROL_REG, 608 status = f81534_set_port_register(port, F81534_FIFO_CONTROL_REG,
488 value); 609 value);
@@ -491,7 +612,7 @@ static int f81534_set_port_config(struct usb_serial_port *port, u32 baudrate,
491 return status; 612 return status;
492 } 613 }
493 614
494 divisor = f81534_calc_baud_divisor(baudrate, F81534_MAX_BAUDRATE); 615 divisor = f81534_calc_baud_divisor(baudrate, port_priv->baud_base);
495 616
496 mutex_lock(&port_priv->lcr_mutex); 617 mutex_lock(&port_priv->lcr_mutex);
497 618
@@ -627,6 +748,70 @@ static int f81534_find_config_idx(struct usb_serial *serial, u8 *index)
627} 748}
628 749
629/* 750/*
751 * The F81532/534 will not report serial port to USB serial subsystem when
752 * H/W DCD/DSR/CTS/RI/RX pin connected to ground.
753 *
754 * To detect RX pin status, we'll enable MCR interal loopback, disable it and
755 * delayed for 60ms. It connected to ground If LSR register report UART_LSR_BI.
756 */
757static bool f81534_check_port_hw_disabled(struct usb_serial *serial, int phy)
758{
759 int status;
760 u8 old_mcr;
761 u8 msr;
762 u8 lsr;
763 u8 msr_mask;
764
765 msr_mask = UART_MSR_DCD | UART_MSR_RI | UART_MSR_DSR | UART_MSR_CTS;
766
767 status = f81534_get_phy_port_register(serial, phy,
768 F81534_MODEM_STATUS_REG, &msr);
769 if (status)
770 return false;
771
772 if ((msr & msr_mask) != msr_mask)
773 return false;
774
775 status = f81534_set_phy_port_register(serial, phy,
776 F81534_FIFO_CONTROL_REG, UART_FCR_ENABLE_FIFO |
777 UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
778 if (status)
779 return false;
780
781 status = f81534_get_phy_port_register(serial, phy,
782 F81534_MODEM_CONTROL_REG, &old_mcr);
783 if (status)
784 return false;
785
786 status = f81534_set_phy_port_register(serial, phy,
787 F81534_MODEM_CONTROL_REG, UART_MCR_LOOP);
788 if (status)
789 return false;
790
791 status = f81534_set_phy_port_register(serial, phy,
792 F81534_MODEM_CONTROL_REG, 0x0);
793 if (status)
794 return false;
795
796 msleep(60);
797
798 status = f81534_get_phy_port_register(serial, phy,
799 F81534_LINE_STATUS_REG, &lsr);
800 if (status)
801 return false;
802
803 status = f81534_set_phy_port_register(serial, phy,
804 F81534_MODEM_CONTROL_REG, old_mcr);
805 if (status)
806 return false;
807
808 if ((lsr & UART_LSR_BI) == UART_LSR_BI)
809 return true;
810
811 return false;
812}
813
814/*
630 * We had 2 generation of F81532/534 IC. All has an internal storage. 815 * We had 2 generation of F81532/534 IC. All has an internal storage.
631 * 816 *
632 * 1st is pure USB-to-TTL RS232 IC and designed for 4 ports only, no any 817 * 1st is pure USB-to-TTL RS232 IC and designed for 4 ports only, no any
@@ -647,14 +832,14 @@ static int f81534_find_config_idx(struct usb_serial *serial, u8 *index)
647static int f81534_calc_num_ports(struct usb_serial *serial, 832static int f81534_calc_num_ports(struct usb_serial *serial,
648 struct usb_serial_endpoints *epds) 833 struct usb_serial_endpoints *epds)
649{ 834{
835 struct f81534_serial_private *serial_priv;
650 struct device *dev = &serial->interface->dev; 836 struct device *dev = &serial->interface->dev;
651 int size_bulk_in = usb_endpoint_maxp(epds->bulk_in[0]); 837 int size_bulk_in = usb_endpoint_maxp(epds->bulk_in[0]);
652 int size_bulk_out = usb_endpoint_maxp(epds->bulk_out[0]); 838 int size_bulk_out = usb_endpoint_maxp(epds->bulk_out[0]);
653 u8 setting[F81534_CUSTOM_DATA_SIZE];
654 u8 setting_idx;
655 u8 num_port = 0; 839 u8 num_port = 0;
840 int index = 0;
656 int status; 841 int status;
657 size_t i; 842 int i;
658 843
659 if (size_bulk_out != F81534_WRITE_BUFFER_SIZE || 844 if (size_bulk_out != F81534_WRITE_BUFFER_SIZE ||
660 size_bulk_in != F81534_MAX_RECEIVE_BLOCK_SIZE) { 845 size_bulk_in != F81534_MAX_RECEIVE_BLOCK_SIZE) {
@@ -662,8 +847,16 @@ static int f81534_calc_num_ports(struct usb_serial *serial,
662 return -ENODEV; 847 return -ENODEV;
663 } 848 }
664 849
850 serial_priv = devm_kzalloc(&serial->interface->dev,
851 sizeof(*serial_priv), GFP_KERNEL);
852 if (!serial_priv)
853 return -ENOMEM;
854
855 usb_set_serial_data(serial, serial_priv);
856 mutex_init(&serial_priv->urb_mutex);
857
665 /* Check had custom setting */ 858 /* Check had custom setting */
666 status = f81534_find_config_idx(serial, &setting_idx); 859 status = f81534_find_config_idx(serial, &serial_priv->setting_idx);
667 if (status) { 860 if (status) {
668 dev_err(&serial->interface->dev, "%s: find idx failed: %d\n", 861 dev_err(&serial->interface->dev, "%s: find idx failed: %d\n",
669 __func__, status); 862 __func__, status);
@@ -674,11 +867,12 @@ static int f81534_calc_num_ports(struct usb_serial *serial,
674 * We'll read custom data only when data available, otherwise we'll 867 * We'll read custom data only when data available, otherwise we'll
675 * read default value instead. 868 * read default value instead.
676 */ 869 */
677 if (setting_idx != F81534_CUSTOM_NO_CUSTOM_DATA) { 870 if (serial_priv->setting_idx != F81534_CUSTOM_NO_CUSTOM_DATA) {
678 status = f81534_read_flash(serial, 871 status = f81534_read_flash(serial,
679 F81534_CUSTOM_ADDRESS_START + 872 F81534_CUSTOM_ADDRESS_START +
680 F81534_CONF_OFFSET, 873 F81534_CONF_OFFSET,
681 sizeof(setting), setting); 874 sizeof(serial_priv->conf_data),
875 serial_priv->conf_data);
682 if (status) { 876 if (status) {
683 dev_err(&serial->interface->dev, 877 dev_err(&serial->interface->dev,
684 "%s: get custom data failed: %d\n", 878 "%s: get custom data failed: %d\n",
@@ -688,13 +882,13 @@ static int f81534_calc_num_ports(struct usb_serial *serial,
688 882
689 dev_dbg(&serial->interface->dev, 883 dev_dbg(&serial->interface->dev,
690 "%s: read config from block: %d\n", __func__, 884 "%s: read config from block: %d\n", __func__,
691 setting_idx); 885 serial_priv->setting_idx);
692 } else { 886 } else {
693 /* Read default board setting */ 887 /* Read default board setting */
694 status = f81534_read_flash(serial, 888 status = f81534_read_flash(serial,
695 F81534_DEF_CONF_ADDRESS_START, F81534_NUM_PORT, 889 F81534_DEF_CONF_ADDRESS_START,
696 setting); 890 sizeof(serial_priv->conf_data),
697 891 serial_priv->conf_data);
698 if (status) { 892 if (status) {
699 dev_err(&serial->interface->dev, 893 dev_err(&serial->interface->dev,
700 "%s: read failed: %d\n", __func__, 894 "%s: read failed: %d\n", __func__,
@@ -708,7 +902,10 @@ static int f81534_calc_num_ports(struct usb_serial *serial,
708 902
709 /* New style, find all possible ports */ 903 /* New style, find all possible ports */
710 for (i = 0; i < F81534_NUM_PORT; ++i) { 904 for (i = 0; i < F81534_NUM_PORT; ++i) {
711 if (setting[i] & F81534_PORT_UNAVAILABLE) 905 if (f81534_check_port_hw_disabled(serial, i))
906 serial_priv->conf_data[i] |= F81534_PORT_UNAVAILABLE;
907
908 if (serial_priv->conf_data[i] & F81534_PORT_UNAVAILABLE)
712 continue; 909 continue;
713 910
714 ++num_port; 911 ++num_port;
@@ -720,6 +917,17 @@ static int f81534_calc_num_ports(struct usb_serial *serial,
720 num_port = 4; /* Nothing found, oldest version IC */ 917 num_port = 4; /* Nothing found, oldest version IC */
721 } 918 }
722 919
920 /* Assign phy-to-logic mapping */
921 for (i = 0; i < F81534_NUM_PORT; ++i) {
922 if (serial_priv->conf_data[i] & F81534_PORT_UNAVAILABLE)
923 continue;
924
925 serial_priv->tty_idx[i] = index++;
926 dev_dbg(&serial->interface->dev,
927 "%s: phy_num: %d, tty_idx: %d\n", __func__, i,
928 serial_priv->tty_idx[i]);
929 }
930
723 /* 931 /*
724 * Setup bulk-out endpoint multiplexing. All ports share the same 932 * Setup bulk-out endpoint multiplexing. All ports share the same
725 * bulk-out endpoint. 933 * bulk-out endpoint.
@@ -741,6 +949,7 @@ static void f81534_set_termios(struct tty_struct *tty,
741 u8 new_lcr = 0; 949 u8 new_lcr = 0;
742 int status; 950 int status;
743 u32 baud; 951 u32 baud;
952 u32 old_baud;
744 953
745 if (C_BAUD(tty) == B0) 954 if (C_BAUD(tty) == B0)
746 f81534_update_mctrl(port, 0, TIOCM_DTR | TIOCM_RTS); 955 f81534_update_mctrl(port, 0, TIOCM_DTR | TIOCM_RTS);
@@ -780,18 +989,14 @@ static void f81534_set_termios(struct tty_struct *tty,
780 if (!baud) 989 if (!baud)
781 return; 990 return;
782 991
783 if (baud > F81534_MAX_BAUDRATE) { 992 if (old_termios)
784 if (old_termios) 993 old_baud = tty_termios_baud_rate(old_termios);
785 baud = tty_termios_baud_rate(old_termios); 994 else
786 else 995 old_baud = F81534_DEFAULT_BAUD_RATE;
787 baud = F81534_DEFAULT_BAUD_RATE;
788
789 tty_encode_baud_rate(tty, baud, baud);
790 }
791 996
792 dev_dbg(&port->dev, "%s: baud: %d\n", __func__, baud); 997 dev_dbg(&port->dev, "%s: baud: %d\n", __func__, baud);
793 998
794 status = f81534_set_port_config(port, baud, new_lcr); 999 status = f81534_set_port_config(port, tty, baud, old_baud, new_lcr);
795 if (status < 0) { 1000 if (status < 0) {
796 dev_err(&port->dev, "%s: set port config failed: %d\n", 1001 dev_err(&port->dev, "%s: set port config failed: %d\n",
797 __func__, status); 1002 __func__, status);
@@ -947,7 +1152,7 @@ static int f81534_get_serial_info(struct usb_serial_port *port,
947 tmp.type = PORT_16550A; 1152 tmp.type = PORT_16550A;
948 tmp.port = port->port_number; 1153 tmp.port = port->port_number;
949 tmp.line = port->minor; 1154 tmp.line = port->minor;
950 tmp.baud_base = F81534_MAX_BAUDRATE; 1155 tmp.baud_base = port_priv->baud_base;
951 1156
952 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 1157 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
953 return -EFAULT; 1158 return -EFAULT;
@@ -1124,79 +1329,6 @@ static void f81534_write_usb_callback(struct urb *urb)
1124 } 1329 }
1125} 1330}
1126 1331
1127static int f81534_attach(struct usb_serial *serial)
1128{
1129 struct f81534_serial_private *serial_priv;
1130 int index = 0;
1131 int status;
1132 int i;
1133
1134 serial_priv = devm_kzalloc(&serial->interface->dev,
1135 sizeof(*serial_priv), GFP_KERNEL);
1136 if (!serial_priv)
1137 return -ENOMEM;
1138
1139 usb_set_serial_data(serial, serial_priv);
1140
1141 mutex_init(&serial_priv->urb_mutex);
1142
1143 /* Check had custom setting */
1144 status = f81534_find_config_idx(serial, &serial_priv->setting_idx);
1145 if (status) {
1146 dev_err(&serial->interface->dev, "%s: find idx failed: %d\n",
1147 __func__, status);
1148 return status;
1149 }
1150
1151 /*
1152 * We'll read custom data only when data available, otherwise we'll
1153 * read default value instead.
1154 */
1155 if (serial_priv->setting_idx == F81534_CUSTOM_NO_CUSTOM_DATA) {
1156 /*
1157 * The default configuration layout:
1158 * byte 0/1/2/3: uart setting
1159 */
1160 status = f81534_read_flash(serial,
1161 F81534_DEF_CONF_ADDRESS_START,
1162 F81534_DEF_CONF_SIZE,
1163 serial_priv->conf_data);
1164 if (status) {
1165 dev_err(&serial->interface->dev,
1166 "%s: read reserve data failed: %d\n",
1167 __func__, status);
1168 return status;
1169 }
1170 } else {
1171 /* Only read 8 bytes for mode & GPIO */
1172 status = f81534_read_flash(serial,
1173 F81534_CUSTOM_ADDRESS_START +
1174 F81534_CONF_OFFSET,
1175 sizeof(serial_priv->conf_data),
1176 serial_priv->conf_data);
1177 if (status) {
1178 dev_err(&serial->interface->dev,
1179 "%s: idx: %d get data failed: %d\n",
1180 __func__, serial_priv->setting_idx,
1181 status);
1182 return status;
1183 }
1184 }
1185
1186 /* Assign phy-to-logic mapping */
1187 for (i = 0; i < F81534_NUM_PORT; ++i) {
1188 if (serial_priv->conf_data[i] & F81534_PORT_UNAVAILABLE)
1189 continue;
1190
1191 serial_priv->tty_idx[i] = index++;
1192 dev_dbg(&serial->interface->dev,
1193 "%s: phy_num: %d, tty_idx: %d\n", __func__, i,
1194 serial_priv->tty_idx[i]);
1195 }
1196
1197 return 0;
1198}
1199
1200static void f81534_lsr_worker(struct work_struct *work) 1332static void f81534_lsr_worker(struct work_struct *work)
1201{ 1333{
1202 struct f81534_port_private *port_priv; 1334 struct f81534_port_private *port_priv;
@@ -1212,15 +1344,54 @@ static void f81534_lsr_worker(struct work_struct *work)
1212 dev_warn(&port->dev, "read LSR failed: %d\n", status); 1344 dev_warn(&port->dev, "read LSR failed: %d\n", status);
1213} 1345}
1214 1346
1347static int f81534_set_port_output_pin(struct usb_serial_port *port)
1348{
1349 struct f81534_serial_private *serial_priv;
1350 struct f81534_port_private *port_priv;
1351 struct usb_serial *serial;
1352 const struct f81534_port_out_pin *pins;
1353 int status;
1354 int i;
1355 u8 value;
1356 u8 idx;
1357
1358 serial = port->serial;
1359 serial_priv = usb_get_serial_data(serial);
1360 port_priv = usb_get_serial_port_data(port);
1361
1362 idx = F81534_CONF_GPIO_OFFSET + port_priv->phy_num;
1363 value = serial_priv->conf_data[idx];
1364 pins = &f81534_port_out_pins[port_priv->phy_num];
1365
1366 for (i = 0; i < ARRAY_SIZE(pins->pin); ++i) {
1367 status = f81534_set_mask_register(serial,
1368 pins->pin[i].reg_addr, pins->pin[i].reg_mask,
1369 value & BIT(i) ? pins->pin[i].reg_mask : 0);
1370 if (status)
1371 return status;
1372 }
1373
1374 dev_dbg(&port->dev, "Output pin (M0/M1/M2): %d\n", value);
1375 return 0;
1376}
1377
1215static int f81534_port_probe(struct usb_serial_port *port) 1378static int f81534_port_probe(struct usb_serial_port *port)
1216{ 1379{
1380 struct f81534_serial_private *serial_priv;
1217 struct f81534_port_private *port_priv; 1381 struct f81534_port_private *port_priv;
1218 int ret; 1382 int ret;
1383 u8 value;
1219 1384
1385 serial_priv = usb_get_serial_data(port->serial);
1220 port_priv = devm_kzalloc(&port->dev, sizeof(*port_priv), GFP_KERNEL); 1386 port_priv = devm_kzalloc(&port->dev, sizeof(*port_priv), GFP_KERNEL);
1221 if (!port_priv) 1387 if (!port_priv)
1222 return -ENOMEM; 1388 return -ENOMEM;
1223 1389
1390 /*
1391 * We'll make tx frame error when baud rate from 384~500kps. So we'll
1392 * delay all tx data frame with 1bit.
1393 */
1394 port_priv->shadow_clk = F81534_UART_EN | F81534_CLK_TX_DELAY_1BIT;
1224 spin_lock_init(&port_priv->msr_lock); 1395 spin_lock_init(&port_priv->msr_lock);
1225 mutex_init(&port_priv->mcr_mutex); 1396 mutex_init(&port_priv->mcr_mutex);
1226 mutex_init(&port_priv->lcr_mutex); 1397 mutex_init(&port_priv->lcr_mutex);
@@ -1248,7 +1419,25 @@ static int f81534_port_probe(struct usb_serial_port *port)
1248 if (ret) 1419 if (ret)
1249 return ret; 1420 return ret;
1250 1421
1251 return 0; 1422 value = serial_priv->conf_data[port_priv->phy_num];
1423 switch (value & F81534_PORT_CONF_MODE_MASK) {
1424 case F81534_PORT_CONF_RS485_INVERT:
1425 port_priv->shadow_clk |= F81534_CLK_RS485_MODE |
1426 F81534_CLK_RS485_INVERT;
1427 dev_dbg(&port->dev, "RS485 invert mode\n");
1428 break;
1429 case F81534_PORT_CONF_RS485:
1430 port_priv->shadow_clk |= F81534_CLK_RS485_MODE;
1431 dev_dbg(&port->dev, "RS485 mode\n");
1432 break;
1433
1434 default:
1435 case F81534_PORT_CONF_RS232:
1436 dev_dbg(&port->dev, "RS232 mode\n");
1437 break;
1438 }
1439
1440 return f81534_set_port_output_pin(port);
1252} 1441}
1253 1442
1254static int f81534_port_remove(struct usb_serial_port *port) 1443static int f81534_port_remove(struct usb_serial_port *port)
@@ -1387,7 +1576,6 @@ static struct usb_serial_driver f81534_device = {
1387 .write = f81534_write, 1576 .write = f81534_write,
1388 .tx_empty = f81534_tx_empty, 1577 .tx_empty = f81534_tx_empty,
1389 .calc_num_ports = f81534_calc_num_ports, 1578 .calc_num_ports = f81534_calc_num_ports,
1390 .attach = f81534_attach,
1391 .port_probe = f81534_port_probe, 1579 .port_probe = f81534_port_probe,
1392 .port_remove = f81534_port_remove, 1580 .port_remove = f81534_port_remove,
1393 .break_ctl = f81534_break_ctl, 1581 .break_ctl = f81534_break_ctl,
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index 219265ce3711..17283f4b4779 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -2282,7 +2282,6 @@ static int write_cmd_usb(struct edgeport_port *edge_port,
2282 /* something went wrong */ 2282 /* something went wrong */
2283 dev_err(dev, "%s - usb_submit_urb(write command) failed, status = %d\n", 2283 dev_err(dev, "%s - usb_submit_urb(write command) failed, status = %d\n",
2284 __func__, status); 2284 __func__, status);
2285 usb_kill_urb(urb);
2286 usb_free_urb(urb); 2285 usb_free_urb(urb);
2287 atomic_dec(&CmdUrbs); 2286 atomic_dec(&CmdUrbs);
2288 return status; 2287 return status;
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index 397a8012ffa3..62c91e360baf 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -472,7 +472,6 @@ static int iuu_clk(struct usb_serial_port *port, int dwFrq)
472 } 472 }
473 } 473 }
474 P2 = ((P - PO) / 2) - 4; 474 P2 = ((P - PO) / 2) - 4;
475 DIV = DIV;
476 PUMP = 0x04; 475 PUMP = 0x04;
477 PBmsb = (P2 >> 8 & 0x03); 476 PBmsb = (P2 >> 8 & 0x03);
478 PBlsb = P2 & 0xFF; 477 PBlsb = P2 & 0xFF;