[PATCH] arm: amlogic: add setbrg op to serial device

Edoardo Tomelleri e.tomell at gmail.com
Thu Sep 22 20:51:13 CEST 2022


Hello,
Il giorno gio 22 set 2022 alle ore 18:51 Neil Armstrong
<neil.armstrong at linaro.org> ha scritto:
>
> Hi,
>
> Sorry for the delay...
No problem, don't worry

> Looks good !
>
> If someone can test it ? otherwise I'll take it for next release.
...does it count if I've tested it? I have a radxa zero board (S905Y2
chip), this started as an experimentation
with editing register values in memory "for fun" and I decided to try
to make a patch out of it.
I do not have an oscilloscope so I can not accurately measure the baud
rate, but the logic is the same as
in linux and using an USB to UART (PL2303) adapter console input and
loady command work fine.
I've just repeated a small test: I'm using picocom and lrzsz in ymodem
mode under WSL, the usb adapter
is forwarded to WSL using usbip, but this should not change anything
at this kind of speed (I hope).
Here are some results sending a 1 MB test file (created once from /dev/urandom):
picocom v3.1

port is        : /dev/ttyUSB0
flowcontrol    : none
baudrate is    : 115200
parity is      : none
databits are   : 8
stopbits are   : 1
[...]
send_cmd is    : sz --ymodem -vv
receive_cmd is : rz -vv -E
[...]
@115200
Bytes Sent:1048576   BPS:7762
@230400
Bytes Sent:1048576   BPS:16372
@460800
Bytes Sent:1048576   BPS:26681
@500000
Bytes Sent:1048576   BPS:27689
@500000 (2nd run)
Bytes Sent:1048576   BPS:27207

At this point I stopped testing, I think my adapter is not good enough
and that the logic
is correct (I've read amlogic's public datasheets [1], but I've not
found a formula specified there),
Reading address (for hardware device UARTAO1, that _of course_ is not
listed there)
md.l 0xff803014 1
ff803014: 0180000f
This corresponds to REG5 of device UARTAO1, with bits 24 (USE_XTAL_CLK), 23
(use new baud rate) set, and bits 27 and 26 clear (so 24 MHz crystal
clock is divided by 3),
NEW_BAUD_RATE is f, so baud rate should be (8 MHz / (15 + 1)) = 500K.

Other than that, I noticed that setting the env variable baudrate is
restricted to values allowed
in a compile time config, loady is not and loady ignores the return
value of meson_serial_setbrg
(it returns -EINVAL if for example a baudrate higher than 8'000'000 is
requested), here's a test
(with env variable baudrate=500000):
=> loady 0x01000000 8000001
## Switch baudrate to 8000001 bps and press ENTER ...
## Ready for binary (ymodem) download to 0x01000000 at 8000001 bps...
C
*** file: ./dest
$ sz --ymodem -vv ./dest
Sending: dest
Bytes Sent:1048576   BPS:27781
Sending:
Ymodem sectors/kbytes sent:   0/ 0k
Transfer complete

*** exit status: 0 ***
## Total Size      = 0x00100000 = 1048576 Bytes
## Start Addr      = 0x01000000
## Switch baudrate to 500000 bps and press ESC ...
=>

setbrg fails, the baud rate register is left at the 500'000 setting
and that's it.
I think the "for fun" experiment has gone a bit too far.

Edoardo
[1] https://dl.radxa.com/zero/docs/hw/IO%20Interface%ef%bc%8dS905Y2%20Datasheet.pdf


More information about the U-Boot mailing list