Skip to contentSkip to conversation

tty/serial: Need clarification on Support for 4+M Baudrate

PATCH Rajanikanth H V 2 participants 7 messages Jan 11, 2012 – Jan 13, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Ref:
kernel version 3.0.8

Platform: ARM Based SOC, UART:amba pl011

I have a requirement to interface UART with an external microcontroller using baud rate above 4Mbps, hence following is my approach to apply the changes. Can any one review/provide me appropriate approach.

arch/arm/include/asm/termbits.h +2 -0
index 704135d..556f5fb 100644
@@ -155,6 +155,8 @@ struct ktermios {
 #define  B3000000 0010015
 #define  B3500000 0010016
 #define  B4000000 0010017
+#define  B4050000 0010020
+#define  B4800000 0010021
 #define CIBAUD	  002003600000		/* input baud rate */
 #define CMSPAR    010000000000		/* mark or space (stick) parity */
 #define CRTSCTS	  020000000000		/* flow control */
drivers/tty/tty_ioctl.c +2 -2
index 53f2442..59c0682 100644
@@ -203,7 +203,7 @@ static const speed_t baud_table[] = {
 	76800, 153600, 307200, 614400, 921600
 #else
 	500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000,
-	2500000, 3000000, 3500000, 4000000
+	2500000, 3000000, 3500000, 4000000, 4050000, 4800000
 #endif
 };
 
@@ -213,7 +213,7 @@ static const tcflag_t baud_bits[] = {
 	B1200, B1800, B2400, B4800, B9600, B19200, B38400,
 	B57600, B115200, B230400, B460800, B500000, B576000,
 	B921600, B1000000, B1152000, B1500000, B2000000, B2500000,
-	B3000000, B3500000, B4000000
+	B3000000, B3500000, B4000000, B4050000, B4800000
 };
 #else
 static const tcflag_t baud_bits[] = {
include/asm-generic/termbits.h +2 -0
index 232b478..f71e72f 100644
@@ -156,6 +156,8 @@ struct ktermios {
 #define  B3000000 0010015
 #define  B3500000 0010016
 #define  B4000000 0010017
+#define  B4050000 0010020
+#define  B4800000 0010021
 #define CIBAUD	  002003600000	/* input baud rate */
 #define CMSPAR	  010000000000	/* mark or space (stick) parity */
 #define CRTSCTS	  020000000000	/* flow control */
#1 lore raw

On Wed, 11 Jan 2012 17:49:01 +0530

Quoted 3 lines

I have a requirement to interface UART with an external microcontroller using baud rate above 4Mbps, hence following is my approach to apply the changes. Can any one review/provide me appropriate approach.

See TCGETS2/TCSETS2 and the BOTHER flag.

The kernel supports aetting arbitary baud rates already.

Alan

#2 lore raw

Alan,

Thanks for your response, suggested modification helped to get 4.8M baud but not 4.05M as this is being approximated to 4.0M baud which happens in tty_termios_encode_baud_rate(...).

I have precise and weird requirement to get 4.05M baud as uart baud clock divisor value changes between 4.0M and 4.05M Baud.

Any suggestion?

Thanks,
Rajanikanth

-----Original Message-----
From: Alan Cox [mailto:alan at lxorguk.ukuu.org.uk]
Sent: Wednesday, January 11, 2012 6:00 PM
To: Rajanikanth H V
Cc: linux-serial at vger.kernel.org; linux-kernel at vger.kernel.org; gregkh at sude.de; linux-arm-kernel at lists.infradead.org
Subject: Re: tty/serial: Need clarification on Support for 4+M Baudrate

On Wed, 11 Jan 2012 17:49:01 +0530

Quoted 3 lines

I have a requirement to interface UART with an external microcontroller using baud rate above 4Mbps, hence following is my approach to apply the changes. Can any one review/provide me appropriate approach.

See TCGETS2/TCSETS2 and the BOTHER flag.

The kernel supports aetting arbitary baud rates already.

Alan

#3 lore raw
Quoted 5 lines · On Thu, 12 Jan 2012 10:49:38 +0100 Rajanikanth H V…

Alan,

Thanks for your response, suggested modification helped to get 4.8M baud but not 4.05M as this is being approximated to 4.0M baud which happens in tty_termios_encode_baud_rate(...).

Only if you don't have the BOTHER flag set and only for returned data to user space.

When you do a TCSETS2 ioctl and have BOTHER set as the rate as well as a c_ispeed/c_ospeed the exactly value is given to the driver.

Alan

#4 lore raw

Alan,

FYI: I am not using application, rather I have a Bluetooth driver invoking encode_baud_rate(...), please find log below.

I made sure that c_ispeed = c_ospeed = 4.05M Baud, however I see tty_termios_encode_baud_rate(...) is normalizing to 4.0

manual trace log below:
======================================================================================

4.05M Arbitrary Baud Setting Sequence:

[    9.664703] alloc_set_baud_rate_cmd Setting arbitrary baudrate using BOTHER baudrate:89 c_cflag:020000016262
[    9.774658] XXXXXX_hci_uart_set_baudrate c_cflag:020000016262 baud:4050000
[    9.781646] XXXXXX_hci_uart_set_baudrate arb flag set
[    9.786956] tty_termios_encode_baud_rate c_ispeed:4050000 c_ospeed:4050000
[    9.794006] tty_termios_encode_baud_rate checking precise weird baudrate:0x80001cb2
[    9.802032] tty_termios_encode_baud_rate checking precise weird baudrate c_cflag:020000006260
[    9.810943] tty_termios_encode_baud_rate did we find close match? i:31 n_baud_table31 ifound:30 ofound:30
[    9.820739] tty_termios_encode_baud_rate BOTHER, c_cflag:020000016277
[    9.827209] tty_termios_baud_rate c_cflag:020000016277 cbaud:010017
[    9.833648] tty_termios_baud_rate:(Arb'ry baud BOTHER not set) c_cflag:020000016277 cbaud:010017
[    9.842773] tty_termios_baud_rate:cbaud:036 baud_val:4000000
[    9.848480] tty_termios_baud_rate c_cflag:020000016277 cbaud:010017
[    9.855499] tty_termios_baud_rate:(Arb'ry baud BOTHER not set) c_cflag:020000016277 cbaud:010017
[    9.864471] tty_termios_baud_rate:cbaud:036 baud_val:4000000
[    9.864501] pl011_set_termios baud:4000000 uart_clk:38400000 port:0 IBRD:1 FBRD:13
[   10.674652] XXXXXX-uart XXXXXX-uart.0: Failed to set new baud rate (4)
[   10.681213] XXXXXX-uart XXXXXX-uart.0: Set chip power: DISABLE
[   10.692596] tty_termios_encode_baud_rate c_ispeed:0 c_ospeed:0
[   10.698822] tty_termios_encode_baud_rate checking precise weird baudrate:0x80001cbf
[   10.706756] tty_termios_encode_baud_rate checking precise weird baudrate c_cflag:020000006260
[   10.715698] tty_termios_encode_baud_rate did we find close match? i:31 n_baud_table31 ifound:0 ofound:0
[   10.725769] tty_termios_encode_baud_rate BOTHER, c_cflag:020000006260
[   10.732574] tty_termios_baud_rate c_cflag:020000006260 cbaud:00
[   10.739929] tty_termios_baud_rate:(Arb'ry baud BOTHER not set) c_cflag:020000006260 cbaud:00
[   10.749176] tty_termios_baud_rate:cbaud:00 baud_val:0
[   10.754638] tty_termios_baud_rate c_cflag:020000006260 cbaud:00
[   10.761505] tty_termios_baud_rate:(Arb'ry baud BOTHER not set) c_cflag:020000006260 cbaud:00
[   10.770660] tty_termios_baud_rate:cbaud:00 baud_val:0

4.05 is failing:

alloc_set_baud_rate_cmd Setting arbitrary baudrate using BOTHER baudrate:89 c_cflag:020000016262

[    9.325225] av8100_hdmi av8100_hdmi.3: HDMI display probed
[    9.334686] XXXXXX_hci_uart_set_baudrate c_cflag:020000016262 baud:4050000, ispeed:4050000 ospeed:4050000
[    9.345275] tty_termios_encode_baud_rate c_ispeed:4050000 c_ospeed:4050000
[    9.352539] tty_termios_encode_baud_rate checking precise weird baudrate:0x80001cb2
[    9.360717] tty_termios_encode_baud_rate checking precise weird baudrate c_cflag:020000006260
[    9.369659] tty_termios_encode_baud_rate did we find close match? i:31 n_baud_table31 ifound:30 ofound:30
[    9.380035] tty_termios_encode_baud_rate BOTHER, c_cflag:020000016277
[    9.387237] tty_termios_baud_rate c_cflag:020000016277 cbaud:010017
[    9.393829] pl011_set_termios i_speed:4050000 o_speed:4050000
[    9.399993] tty_termios_baud_rate c_cflag:020000016277 cbaud:010017

4.8M Arbitrary BaudSetting Sequence:

[   10.004699] alloc_set_baud_rate_cmd Setting arbitrary baudrate using BOTHER baudrate:90 c_cflag:020000016262
[   10.114624] XXXXXX_hci_uart_set_baudrate c_cflag:020000016262 baud:4800000
[   10.122009] XXXXXX_hci_uart_set_baudrate arb flag set
[   10.127624] tty_termios_encode_baud_rate c_ispeed:4800000 c_ospeed:4800000
[   10.134887] tty_termios_encode_baud_rate checking precise weird baudrate:0x80001cb2
[   10.143218] tty_termios_encode_baud_rate checking precise weird baudrate c_cflag:020000006260
[   10.154113] tty_termios_encode_baud_rate did we find close match? i:31 n_baud_table31 ifound:-1 ofound:-1
[   10.172149] tty_termios_encode_baud_rate BOTHER, c_cflag:020000016260
[   10.178833] tty_termios_baud_rate c_cflag:020000016260 cbaud:010000
[   10.185424] tty_termios_baud_rate (Arb'ry baud set) c_cflag:020000016260 cbaud:010000
[   10.193572] i_speed:4800000 o_speed:4800000
[   10.197845] tty_termios_baud_rate c_cflag:020000016260 cbaud:010000
[   10.204620] tty_termios_baud_rate (Arb'ry baud set) c_cflag:020000016260 cbaud:010000
[   10.212799] pl011_set_termios baud:4800000 uart_clk:38400000 port:0 IBRD:1 FBRD:0
[   10.220764] XXXXXX-uart XXXXXX-uart.0: Baud rate changed to 4800000 baud
[   10.973632] Bluetooth: XXXXXX BT core is enabled
[   11.101867] Bluetooth: XXXXXX BT core is disabled

======================================================================================

Thanks,
Rajanikanth

-----Original Message-----
From: Alan Cox [mailto:alan at lxorguk.ukuu.org.uk]
Sent: Thursday, January 12, 2012 5:19 PM
To: Rajanikanth H V
Cc: linux-serial at vger.kernel.org; linux-kernel at vger.kernel.org; gregkh at sude.de; linux-arm-kernel at lists.infradead.org
Subject: Re: tty/serial: Need clarification on Support for 4+M Baudrate

Quoted 5 lines · On Thu, 12 Jan 2012 10:49:38 +0100 Rajanikanth H V…

Alan,

Thanks for your response, suggested modification helped to get 4.8M baud but not 4.05M as this is being approximated to 4.0M baud which happens in tty_termios_encode_baud_rate(...).

Only if you don't have the BOTHER flag set and only for returned data to user space.

When you do a TCSETS2 ioctl and have BOTHER set as the rate as well as a c_ispeed/c_ospeed the exactly value is given to the driver.

Alan

#5 lore raw
Quoted 9 lines · On Thu, 12 Jan 2012 15:20:46 +0100 Rajanikanth H V…

Alan,

FYI: I am not using application, rather I have a Bluetooth driver invoking encode_baud_rate(...), please find log below.

I made sure that c_ispeed = c_ospeed = 4.05M Baud, however I see tty_termios_encode_baud_rate(...) is normalizing to 4.0

Quoted 6 lines

manual trace log below:
======================================================================================

4.05M Arbitrary Baud Setting Sequence:

[    9.664703] alloc_set_baud_rate_cmd Setting arbitrary baudrate using BOTHER baudrate:89 c_cflag:020000016262
[    9.774658] XXXXXX_hci_uart_set_baudrate c_cflag:020000016262 baud:4050000

4050000 seems a bit odd - you want cflag&CBAUD == BOTHER so I'd expect the low bits to end rather different things to 6262 ?

So something like

	struct ktermios new = *tty->termios;
	new.c_cflag &= ~(CBAUD|CIBAUD);
	new.c_cflag |= BOTHER;
	new.c_ispeed = 4050000;
	new.c_ospeed = 4050000;
	tty_set_termios(tty, &new);	/* Can sleep */

	/* Returned new will now hold actual values selected */

should do the trick providing the low level driver supports the rate.

Alan

#6 lore raw

Thanks, explicit termios(with flags) structure usage helped(log below), however, the dependent Bluetooth uart driver switches the uart baud rates between 115K(during initialization), 9600(during low power) and 4+M(data tfr), in this juncture I need to handle termios structure switching accordingly else I see c_cflags getting messed up effecting next baud switch change.

================================

[    9.070648] alloc_set_baud_rate_cmd Setting arbitrary baudrate using BOTHER baudrate:89 c_cflag:020000016260
[    9.164581] tty_termios_encode_baud_rate c_ispeed:4050000 c_ospeed:4050000 c_cflag:020000016260
[    9.173278] tty_termios_encode_baud_rate checking precise weird baudrate c_cflag:020000006260 oclose:0 iclose:81000 ibinput:0
[    9.187103] tty_termios_encode_baud_rate did we find close match? i:31 n_baud_table31 ifound:30 ofound:-1
[    9.197570] tty_termios_encode_baud_rate BOTHER, c_cflag:022003616260
[    9.214630] tty_termios_baud_rate:(Arb'ry baud set) c_cflag:022003616260 cbaud:010000
[    9.222503] pl011_set_termios i_speed:4050000 o_speed:4050000
[    9.231384] tty_termios_baud_rate:(Arb'ry baud set) c_cflag:022003616260 cbaud:010000
[    9.246643] pl011_set_termios baud:4050000 uart_clk:38400000 port:0 IBRD:1 FBRD:12
[    9.254730] XXXXXX-uart XXXXXX-uart.0: Baud rate changed to 4050000 baud

================================

Thanks,
Rajanikanth

Quoted 3 lines

4.05M Arbitrary Baud Setting Sequence:

[    9.664703] alloc_set_baud_rate_cmd Setting arbitrary baudrate using BOTHER baudrate:89 c_cflag:020000016262
[    9.774658] XXXXXX_hci_uart_set_baudrate c_cflag:020000016262 baud:4050000

4050000 seems a bit odd - you want cflag&CBAUD == BOTHER so I'd expect the low bits to end rather different things to 6262 ?

So something like

	struct ktermios new = *tty->termios;
	new.c_cflag &= ~(CBAUD|CIBAUD);
	new.c_cflag |= BOTHER;
	new.c_ispeed = 4050000;
	new.c_ospeed = 4050000;
	tty_set_termios(tty, &new);	/* Can sleep */

	/* Returned new will now hold actual values selected */

should do the trick providing the low level driver supports the rate.

Alan