No, I can't readily find it, so I'll go through the steps required.
[ Unfortunately for you I'm running up-to-date kernels that already have the logical names, but I'll try to fake the situation you will be seeing. ]
Every UART (and tty of any kind) has an entry in /sys/class/tty/ - for /dev/ttyAMA2 that is /sys/class/tty/ttyAMA2:
Code: Select all
$ ls -l /sys/class/tty/ttyAMA2
lrwxrwxrwx 1 root root 0 Oct 3 09:14 /sys/class/tty/ttyAMA2 -> ../../devices/platform/soc/fe201a00.serial/tty/ttyAMA2
The hexadecimal address in there (fe201a00) is enough to identify that this is actually UART5, but let's proceed anyway and follow the symbolic link (note the trailing slash):
Code: Select all
$ ls -l /sys/class/tty/ttyAMA2/
total 0
-r--r--r-- 1 root root 4096 Oct 3 09:34 close_delay
-r--r--r-- 1 root root 4096 Oct 3 09:34 closing_wait
-rw-r--r-- 1 root root 4096 Oct 3 09:34 console
-r--r--r-- 1 root root 4096 Oct 3 09:34 custom_divisor
-r--r--r-- 1 root root 4096 Oct 3 09:34 dev
lrwxrwxrwx 1 root root 0 Oct 3 09:14 device -> ../../../fe201a00.serial
-r--r--r-- 1 root root 4096 Oct 3 09:34 flags
-r--r--r-- 1 root root 4096 Oct 3 09:34 iomem_base
-r--r--r-- 1 root root 4096 Oct 3 09:34 iomem_reg_shift
-r--r--r-- 1 root root 4096 Oct 3 09:34 io_type
-r--r--r-- 1 root root 4096 Oct 3 09:34 irq
-r--r--r-- 1 root root 4096 Oct 3 09:34 line
-r--r--r-- 1 root root 4096 Oct 3 09:34 port
drwxr-xr-x 2 root root 0 Oct 3 09:34 power
lrwxrwxrwx 1 root root 0 Oct 3 09:14 subsystem -> ../../../../../../class/tty
-r--r--r-- 1 root root 4096 Oct 3 09:34 type
-r--r--r-- 1 root root 4096 Oct 3 09:34 uartclk
-rw-r--r-- 1 root root 4096 Oct 3 09:14 uevent
-r--r--r-- 1 root root 4096 Oct 3 09:34 xmit_fifo_size
And now follow the device link:
Code: Select all
$ ls -l /sys/class/tty/ttyAMA2/device/
total 0
lrwxrwxrwx 1 root root 0 Oct 3 09:14 driver -> ../../../../bus/amba/drivers/uart-pl011
-rw-r--r-- 1 root root 4096 Oct 3 09:34 driver_override
-r--r--r-- 1 root root 4096 Oct 3 09:34 id
lrwxrwxrwx 1 root root 0 Oct 3 09:14 of_node -> ../../../../firmware/devicetree/base/soc/serial@7e201a00
drwxr-xr-x 2 root root 0 Oct 3 09:34 power
-r--r--r-- 1 root root 4096 Oct 3 09:34 resource
lrwxrwxrwx 1 root root 0 Oct 3 09:14 subsystem -> ../../../../bus/amba
lrwxrwxrwx 1 root root 0 Oct 3 09:34 supplier:platform:fe101000.cprman -> ../../../virtual/devlink/platform:fe101000.cprman--amba:fe201a00.serial
lrwxrwxrwx 1 root root 0 Oct 3 09:34 supplier:platform:fe200000.gpio -> ../../../virtual/devlink/platform:fe200000.gpio--amba:fe201a00.serial
drwxr-xr-x 3 root root 0 Oct 3 09:14 tty
-rw-r--r-- 1 root root 4096 Oct 3 09:14 uevent
The "of_node" symbolic link is useful because it points directly into the live Device Tree:
Code: Select all
$ readlink /sys/class/tty/ttyAMA2/device/of_node
../../../../firmware/devicetree/base/soc/serial@7e201a00
Now let's find the uart aliases in Device Tree. We tend to use "/proc/device-tree" as file system location, but it is just a symbolic link into /sys:
Code: Select all
$ ls -l /proc/device-tree
lrwxrwxrwx 1 root root 29 Oct 3 09:14 /proc/device-tree -> /sys/firmware/devicetree/base
$ ls /sys/firmware/devicetree/base/aliases/uart*
/sys/firmware/devicetree/base/aliases/uart0
/sys/firmware/devicetree/base/aliases/uart1
/sys/firmware/devicetree/base/aliases/uart2
/sys/firmware/devicetree/base/aliases/uart3
/sys/firmware/devicetree/base/aliases/uart4
/sys/firmware/devicetree/base/aliases/uart5
Ah, this is where 5.15 and 6.1 really diverge - your list probably stops at uart1, because our 5.15 kernel didn't contain a complete list of UART aliases. However, I can use my image to show what the content of each of them should be on a Pi 4:
Code: Select all
$ grep -a . /sys/firmware/devicetree/base/aliases/uart*
/sys/firmware/devicetree/base/aliases/uart0:/soc/serial@7e201000
/sys/firmware/devicetree/base/aliases/uart1:/soc/serial@7e215040
/sys/firmware/devicetree/base/aliases/uart2:/soc/serial@7e201400
/sys/firmware/devicetree/base/aliases/uart3:/soc/serial@7e201600
/sys/firmware/devicetree/base/aliases/uart4:/soc/serial@7e201800
/sys/firmware/devicetree/base/aliases/uart5:/soc/serial@7e201a00
This shows that the alias "uart5" contains the string "/soc/serial@7e201a00", which matches the end of the of_node for ttyAMA2:
Code: Select all
$ readlink /sys/class/tty/ttyAMA2/device/of_node
../../../../firmware/devicetree/base/soc/serial@7e201a00
If I was coding a conversion from tty name to UART index in bash shell I'd do something like this:
Code: Select all
ttyname="ttyAMA2" # for example
case $(readlink /sys/class/tty/$ttyname/device/of_node | cut -d@ -f2) in
7e201000) uartidx=0;;
7e201400) uartidx=2;;
7e201600) uartidx=3;;
7e201800) uartidx=4;;
7e201a00) uartidx=5;;
esac
In C I would locate the hex number after the '@', then use the formula:
Code: Select all
uartidx = (address - 0x7e201000) / 0x200;
I hope that helps a bit.