Can we switch UART1(ttyTHS2) and UART2(ttyTHS1) pins?

Hi,
I want to test the UART2(ttyTHS1) on the dev kit. Is it possible to assign the header J17 to UART2? By default, its assigned to UART1(ttyTHS2).

hello vinmeen,

you may gather from kernel init messages for the serial port mappings.
i.e. $ dmesg | grep ttyTHS

after that, please check below device tree to have customization.
for example,
$L4T_Sources/r32.4.2/Linux_for_Tegra/source/public/kernel_src/hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc/tegra186-soc-uart.dtsi

Hi JerryChang,
dmesg | grep tttyTHS gave me the memory map of the ttyTHS1 and ttyTHS2

I downloaded the kernel sources and found the file tegra186-soc-uart.dtsi to have the following

uartb: serial@3110000 {
compatible = “nvidia,tegra186-hsuart”;
iommus = <&smmu TEGRA_SID_GPCDMA_0>;
reg = <0x0 0x03110000 0x0 0x40>;
reg-shift = <2>;
interrupts = <0 TEGRA186_IRQ_UARTB 0x04>;
nvidia,memory-clients = <14>;
dmas = <&gpcdma 9>, <&gpcdma 9>;
dma-names = “rx”, “tx”;
clocks = <&tegra_car TEGRA186_CLK_UARTB>,
<&tegra_car TEGRA186_CLK_PLLP_OUT0>;
clock-names = “serial”, “parent”;
resets = <&tegra_car TEGRA186_RESET_UARTB>;
reset-names = “serial”;
status = “disabled”;
nvidia,tolerance-low-range = <0>;
nvidia,tolerance-high-range = <4>;
nvidia,adjust-baud-rates = <115200 115200 100>;
};

uartc: serial@c280000 {
compatible = “nvidia,tegra186-hsuart”;
iommus = <&smmu TEGRA_SID_GPCDMA_0>;
reg = <0x0 0xc280000 0x0 0x40>;
reg-shift = <2>;
interrupts = <0 TEGRA186_IRQ_UARTC 0x04>;
nvidia,memory-clients = <14>;
dmas = <&gpcdma 3>, <&gpcdma 3>;
dma-names = “rx”, “tx”;
clocks = <&tegra_car TEGRA186_CLK_UARTC>,
<&tegra_car TEGRA186_CLK_PLLP_OUT0>;
clock-names = “serial”, “parent”;
resets = <&tegra_car TEGRA186_RESET_UARTC>;
reset-names = “serial”;
status = “disabled”;
nvidia,tolerance-low-range = <0>;
nvidia,tolerance-high-range = <4>;
nvidia,adjust-baud-rates = <115200 115200 100>;
};

Should I swap the address 3110000 and c280000 and the macros TEGRA186_IRQ_UARTB and TEGRA186_IRQ_UARTC for uartb and uartc ? If I recompile the kernel, will it swap the ttyTHS1 and ttyTHS2 ?

hello vinmeen,

you can simply to change the order by switch the sequence of uartb and uartc for verification.
for example,

uartc: serial@c280000  {
uartb: serial@3110000 { 

please also refer to below kernel sources for reference,
for example,
$L4T_Sources/r32.4.2/Linux_for_Tegra/source/public/kernel/kernel-4.9/drivers/tty/serial/serial_core.c

int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport){...}

I am unable to switch the uartc and uartb. I modified the file tegra186-soc-uart.dtsi by swapping the blocks

uartc: serial@c280000  {
uartb: serial@3110000 { 

I built the kernel image and used the built image on boot. The J17 header is still mapped to /dev/ttyTHS2. Does rebuilding the kernel takes the changes in the file tegra186-soc-uart.dtsi in the first place ? hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc path falls outside the kernel source folder.

Also I did not understand what I need to do with the file
$L4T_Sources/r32.4.2/Linux_for_Tegra/source/public/kernel/kernel-4.9/drivers/tty/serial/serial_core.c. Please guide me with the procedure to swap uart pins

hello vinmeen,

since it’s dtb update, please update the device tree to check the modification results.
for example,

update kernel/dtb/tegra186-quill-p3310-1000-c03-00-base.dtb with the customize one. 
$ sudo ./flash.sh -k kernel-dtb jetson-tx2 mmcblk0p1

Just to be clear, you cannot actually swap the physical UART ports to different pins. The /dev/ttyX names are only pointers into the kernel drivers and can be changed/remapped. If you are trying to make the UARTC located at 0x0c280000 and UARTB located at 0x03110000 go to opposite physical locations on the SoM, this cannot be done.

This question was related to my other post. I had difficulties is using the UART located physically at pins B16 and B15. @JerryChang replied that the UART in pins B16 and B15 is configured to be used for wifi or bluetooth (not sure if that is going to make a difference for me to use them as serial port). From my perspective, ports /dev/ttyTHS2 works and /dev/ttyTHS1 doesn’t. So if I swap the drivers for the UARTs by using the procedure above, will I be able to use the pins B16,B15 as a serial port?