41
41
#define F81534_MODEM_CONTROL_REG (0x04 + F81534_UART_BASE_ADDRESS)
42
42
#define F81534_LINE_STATUS_REG (0x05 + F81534_UART_BASE_ADDRESS)
43
43
#define F81534_MODEM_STATUS_REG (0x06 + F81534_UART_BASE_ADDRESS)
44
+ #define F81534_CLOCK_REG (0x08 + F81534_UART_BASE_ADDRESS)
44
45
#define F81534_CONFIG1_REG (0x09 + F81534_UART_BASE_ADDRESS)
45
46
46
47
#define F81534_DEF_CONF_ADDRESS_START 0x3000
57
58
58
59
/* Default URB timeout for USB operations */
59
60
#define F81534_USB_MAX_RETRY 10
60
- #define F81534_USB_TIMEOUT 1000
61
+ #define F81534_USB_TIMEOUT 2000
61
62
#define F81534_SET_GET_REGISTER 0xA0
62
63
63
64
#define F81534_NUM_PORT 4
96
97
#define F81534_CMD_READ 0x03
97
98
98
99
#define F81534_DEFAULT_BAUD_RATE 9600
99
- #define F81534_MAX_BAUDRATE 115200
100
100
101
101
#define F81534_PORT_CONF_DISABLE_PORT BIT(3)
102
102
#define F81534_PORT_CONF_NOT_EXIST_PORT BIT(7)
106
106
#define F81534_1X_RXTRIGGER 0xc3
107
107
#define F81534_8X_RXTRIGGER 0xcf
108
108
109
+ /*
110
+ * F81532/534 Clock registers (offset +08h)
111
+ *
112
+ * Bit0: UART Enable (always on)
113
+ * Bit2-1: Clock source selector
114
+ * 00: 1.846MHz.
115
+ * 01: 18.46MHz.
116
+ * 10: 24MHz.
117
+ * 11: 14.77MHz.
118
+ */
119
+
120
+ #define F81534_UART_EN BIT(0)
121
+ #define F81534_CLK_1_846_MHZ 0
122
+ #define F81534_CLK_18_46_MHZ BIT(1)
123
+ #define F81534_CLK_24_MHZ BIT(2)
124
+ #define F81534_CLK_14_77_MHZ (BIT(1) | BIT(2))
125
+ #define F81534_CLK_MASK GENMASK(2, 1)
126
+
109
127
static const struct usb_device_id f81534_id_table [] = {
110
128
{ USB_DEVICE (FINTEK_VENDOR_ID_1 , FINTEK_DEVICE_ID ) },
111
129
{ USB_DEVICE (FINTEK_VENDOR_ID_2 , FINTEK_DEVICE_ID ) },
@@ -129,12 +147,18 @@ struct f81534_port_private {
129
147
struct usb_serial_port * port ;
130
148
unsigned long tx_empty ;
131
149
spinlock_t msr_lock ;
150
+ u32 baud_base ;
132
151
u8 shadow_mcr ;
133
152
u8 shadow_lcr ;
134
153
u8 shadow_msr ;
154
+ u8 shadow_clk ;
135
155
u8 phy_num ;
136
156
};
137
157
158
+ static u32 const baudrate_table [] = { 115200 , 921600 , 1152000 , 1500000 };
159
+ static u8 const clock_table [] = { F81534_CLK_1_846_MHZ , F81534_CLK_14_77_MHZ ,
160
+ F81534_CLK_18_46_MHZ , F81534_CLK_24_MHZ };
161
+
138
162
static int f81534_logic_to_phy_port (struct usb_serial * serial ,
139
163
struct usb_serial_port * port )
140
164
{
@@ -460,13 +484,52 @@ static u32 f81534_calc_baud_divisor(u32 baudrate, u32 clockrate)
460
484
return DIV_ROUND_CLOSEST (clockrate , baudrate );
461
485
}
462
486
463
- static int f81534_set_port_config (struct usb_serial_port * port , u32 baudrate ,
464
- u8 lcr )
487
+ static int f81534_find_clk (u32 baudrate )
488
+ {
489
+ int idx ;
490
+
491
+ for (idx = 0 ; idx < ARRAY_SIZE (baudrate_table ); ++ idx ) {
492
+ if (baudrate <= baudrate_table [idx ] &&
493
+ baudrate_table [idx ] % baudrate == 0 )
494
+ return idx ;
495
+ }
496
+
497
+ return - EINVAL ;
498
+ }
499
+
500
+ static int f81534_set_port_config (struct usb_serial_port * port ,
501
+ struct tty_struct * tty , u32 baudrate , u32 old_baudrate , u8 lcr )
465
502
{
466
503
struct f81534_port_private * port_priv = usb_get_serial_port_data (port );
467
504
u32 divisor ;
468
505
int status ;
506
+ int i ;
507
+ int idx ;
469
508
u8 value ;
509
+ u32 baud_list [] = {baudrate , old_baudrate , F81534_DEFAULT_BAUD_RATE };
510
+
511
+ for (i = 0 ; i < ARRAY_SIZE (baud_list ); ++ i ) {
512
+ idx = f81534_find_clk (baud_list [i ]);
513
+ if (idx >= 0 ) {
514
+ baudrate = baud_list [i ];
515
+ tty_encode_baud_rate (tty , baudrate , baudrate );
516
+ break ;
517
+ }
518
+ }
519
+
520
+ if (idx < 0 )
521
+ return - EINVAL ;
522
+
523
+ port_priv -> baud_base = baudrate_table [idx ];
524
+ port_priv -> shadow_clk &= ~F81534_CLK_MASK ;
525
+ port_priv -> shadow_clk |= clock_table [idx ];
526
+
527
+ status = f81534_set_port_register (port , F81534_CLOCK_REG ,
528
+ port_priv -> shadow_clk );
529
+ if (status ) {
530
+ dev_err (& port -> dev , "CLOCK_REG setting failed\n" );
531
+ return status ;
532
+ }
470
533
471
534
if (baudrate <= 1200 )
472
535
value = F81534_1X_RXTRIGGER ; /* 128 FIFO & TL: 1x */
@@ -482,7 +545,7 @@ static int f81534_set_port_config(struct usb_serial_port *port, u32 baudrate,
482
545
if (baudrate <= 1200 )
483
546
value = UART_FCR_TRIGGER_1 | UART_FCR_ENABLE_FIFO ; /* TL: 1 */
484
547
else
485
- value = UART_FCR_R_TRIG_11 | UART_FCR_ENABLE_FIFO ; /* TL: 14 */
548
+ value = UART_FCR_TRIGGER_8 | UART_FCR_ENABLE_FIFO ; /* TL: 8 */
486
549
487
550
status = f81534_set_port_register (port , F81534_FIFO_CONTROL_REG ,
488
551
value );
@@ -491,7 +554,7 @@ static int f81534_set_port_config(struct usb_serial_port *port, u32 baudrate,
491
554
return status ;
492
555
}
493
556
494
- divisor = f81534_calc_baud_divisor (baudrate , F81534_MAX_BAUDRATE );
557
+ divisor = f81534_calc_baud_divisor (baudrate , port_priv -> baud_base );
495
558
496
559
mutex_lock (& port_priv -> lcr_mutex );
497
560
@@ -741,6 +804,7 @@ static void f81534_set_termios(struct tty_struct *tty,
741
804
u8 new_lcr = 0 ;
742
805
int status ;
743
806
u32 baud ;
807
+ u32 old_baud ;
744
808
745
809
if (C_BAUD (tty ) == B0 )
746
810
f81534_update_mctrl (port , 0 , TIOCM_DTR | TIOCM_RTS );
@@ -780,18 +844,14 @@ static void f81534_set_termios(struct tty_struct *tty,
780
844
if (!baud )
781
845
return ;
782
846
783
- if (baud > F81534_MAX_BAUDRATE ) {
784
- if (old_termios )
785
- baud = tty_termios_baud_rate (old_termios );
786
- else
787
- baud = F81534_DEFAULT_BAUD_RATE ;
788
-
789
- tty_encode_baud_rate (tty , baud , baud );
790
- }
847
+ if (old_termios )
848
+ old_baud = tty_termios_baud_rate (old_termios );
849
+ else
850
+ old_baud = F81534_DEFAULT_BAUD_RATE ;
791
851
792
852
dev_dbg (& port -> dev , "%s: baud: %d\n" , __func__ , baud );
793
853
794
- status = f81534_set_port_config (port , baud , new_lcr );
854
+ status = f81534_set_port_config (port , tty , baud , old_baud , new_lcr );
795
855
if (status < 0 ) {
796
856
dev_err (& port -> dev , "%s: set port config failed: %d\n" ,
797
857
__func__ , status );
@@ -947,7 +1007,7 @@ static int f81534_get_serial_info(struct usb_serial_port *port,
947
1007
tmp .type = PORT_16550A ;
948
1008
tmp .port = port -> port_number ;
949
1009
tmp .line = port -> minor ;
950
- tmp .baud_base = F81534_MAX_BAUDRATE ;
1010
+ tmp .baud_base = port_priv -> baud_base ;
951
1011
952
1012
if (copy_to_user (retinfo , & tmp , sizeof (* retinfo )))
953
1013
return - EFAULT ;
@@ -1221,6 +1281,7 @@ static int f81534_port_probe(struct usb_serial_port *port)
1221
1281
if (!port_priv )
1222
1282
return - ENOMEM ;
1223
1283
1284
+ port_priv -> shadow_clk = F81534_UART_EN ;
1224
1285
spin_lock_init (& port_priv -> msr_lock );
1225
1286
mutex_init (& port_priv -> mcr_mutex );
1226
1287
mutex_init (& port_priv -> lcr_mutex );
0 commit comments