Skip to contentSkip to conversation

Add support for Tegra UART Trace Controller (UTC) client

PATCH Superseded Kartik Rajput 2 participants 5 messages Feb 13, 2025

Subsystems (3)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add support for Tegra UART Trace Controller (UTC) client

The Tegra UTC (UART Trace Controller) is a hardware controller that allows multiple systems within the Tegra SoC to share a hardware UART interface. It supports up to 16 clients, with each client having its own interrupt and a FIFO buffer for both RX (receive) and TX (transmit), each capable of holding 128 characters.

The Tegra UTC uses 8-N-1 configuration and operates on a pre-configured baudrate, which is configured by the bootloader.

Kartik Rajput (2):
dt-bindings: serial: Add bindings for nvidia,tegra264-utc
serial: tegra-utc: Add driver for Tegra UART Trace Controller (UTC)

 .../bindings/serial/nvidia,tegra264-utc.yaml  |  73 ++
 drivers/tty/serial/Kconfig                    |  23 +
 drivers/tty/serial/Makefile                   |   1 +
 drivers/tty/serial/tegra-utc.c                | 625 ++++++++++++++++++
 4 files changed, 722 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/nvidia,tegra264-utc.yaml
 create mode 100644 drivers/tty/serial/tegra-utc.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 1/2 dt-bindings: serial: Add bindings for nvidia,tegra264-utc

The Tegra UTC (UART Trace Controller) allows multiple clients within the Tegra SoC to share a physical UART interface. It supports up to 16 clients. Each client operates as an independent UART endpoint with a dedicated interrupt and 128-character TX/RX FIFOs.

Add device tree binding documentation for the Tegra UTC client.

---
v1 -> v2:
* Removed current-speed as it might not be accurate as the Tegra UTC multiplex data from various clients.
* Use 'tx-threshold' and 'rx-threshold' properties defined in serial.yaml instead of 'nvidia,utc-fifo-threshold'.
* Add serial.yaml reference.
* Define minimum and maximum values for threshold.
* Rephrase the documentation to clarify that we are documenting the Tegra UTC clients and not the controller itself.

---
 .../bindings/serial/nvidia,tegra264-utc.yaml  | 73 +++++++++++++++++++
 1 file changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/nvidia,tegra264-utc.yaml
Documentation/devicetree/bindings/serial/nvidia,tegra264-utc.yaml new file +73 -0
new file mode 100644
index 000000000000..572cc574da64
@@ -0,0 +1,73 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/serial/nvidia,tegra264-utc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NVIDIA Tegra UTC (UART Trace Controller) client
+
+maintainers:
+  - Kartik Rajput <[email protected]>
+  - Thierry Reding <[email protected]>
+  - Jonathan Hunter <[email protected]>
+
+description:
+  Represents a client interface of the Tegra UTC (UART Trace Controller). The
+  Tegra UTC allows multiple clients within the Tegra SoC to share a physical
+  UART interface. It supports up to 16 clients. Each client operates as an
+  independent UART endpoint with a dedicated interrupt and 128-character TX/RX
+  FIFOs.
+
+  The Tegra UTC clients use 8-N-1 configuration and operates on a baudrate
+  configured by the bootloader at the controller level.
+
+allOf:
+  - $ref: serial.yaml#
+
+properties:
+  compatible:
+    const: nvidia,tegra264-utc
+
+  reg:
+    items:
+      - description: TX region.
+      - description: RX region.
+
+  reg-names:
+    items:
+      - const: tx
+      - const: rx
+
+  interrupts:
+    maxItems: 1
+
+  tx-threshold:
+    minimum: 1
+    maximum: 128
+
+  rx-threshold:
+    minimum: 1
+    maximum: 128
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - interrupts
+  - tx-threshold
+  - rx-threshold
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    tegra_utc: serial@c4e0000 {
+        compatible = "nvidia,tegra264-utc";
+        reg = <0xc4e0000 0x8000>, <0xc4e8000 0x8000>;
+        reg-names = "tx", "rx";
+        interrupts = <GIC_SPI 514 IRQ_TYPE_LEVEL_HIGH>;
+        tx-threshold = <4>;
+        rx-threshold = <4>;
+    };
Signature · 1 line
2.43.0
#2 lore raw

PATCH v4 2/2 serial: tegra-utc: Add driver for Tegra UART Trace Controller (UTC)

In reply to Kartik Rajput

The Tegra264 SoC supports the UART Trace Controller (UTC), which allows multiple firmware clients (up to 16) to share a single physical UART. Each client is provided with its own interrupt and has access to a 128-character wide FIFO for both transmit (TX) and receive (RX) operations.

Add tegra-utc driver to support Tegra UART Trace Controller (UTC) client.

---
v3 -> v4:
* Cleaned up included header files.
* Guard unregister_console() with CONFIG_SERIAL_TEGRA_UTC_CONSOLE macro.
* Remove unused variable val from tegra_utc_get_poll_char().
* Define TEGRA_UTC_INTR_COMMON for the common interrupts between TX and RX clients.
* Improve error messages in tegra_utc_probe().
* Minor code clean up.
v2 -> v3:
* Update included header files.
* Remove struct tegra_utc_soc and move fifosize to struct tegra_utc_port.
* Remove irq from struct tegra_utc_port and use uart_port::irq instead.
* Update tegra_utc_tx_chars to use uart_port_tx API instead.
* Remove flag variable from tegra_utc_rx_chars() as it was not really required.
* Removed mask for ch in tegra_utc_rx_chars() as both uart_handle_sysrq_char() and tty_insert_flip_char() takes u8 value.
* Update tegra_utc_isr() to return IRQ_HANDLED only when it actually handles the interrupt.
* Use uart_port_lock/unlock APIs in tegra_utc_isr() instead of using irqsave/irqrestore counterparts.
* Update tegra_utc_get_poll_char() logic to return NO_POLL_CHAR if FIFO is empty.
* Use read_poll_timeout_atomic() in tegra_utc_put_poll_char() to avoid stall.
* Introduce write_atomic/thread console APIs to make the driver CON_NBCON compatible.
* Unregister the console in tegra_utc_remove().
* Use max_chars-- instead of --max_chars in tegra_utc_rx_chars().
* Improve error handling logic of tegra_utc_startup() if request_irq() fails.
* Add trailing comma in tegra_utc_driver.
* Propagate error if uart_read_port_properties() fails.
* replace of_* APIs with device_* APIs.
v1 -> v2:
* Use dev_err_probe() in tegra_utc_probe().
* Use uart_read_port_properties() instead of manually parsing the port line.
* Remove duplicate error prints if platform_get_irq() fails.
* In tegra_utc_of_match, remove , after terminator line.
* Remove current-speed, as it is not always accurate.

---
 drivers/tty/serial/Kconfig     |  23 ++
 drivers/tty/serial/Makefile    |   1 +
 drivers/tty/serial/tegra-utc.c | 625 +++++++++++++++++++++++++++++++++
 3 files changed, 649 insertions(+)
 create mode 100644 drivers/tty/serial/tegra-utc.c
drivers/tty/serial/Kconfig +23 -0
index 976dae3bb1bb..edc56a3c0ace 100644
@@ -306,6 +306,29 @@ config SERIAL_TEGRA_TCU_CONSOLE
 
 	  If unsure, say Y.
 
+config SERIAL_TEGRA_UTC
+	tristate "NVIDIA Tegra UART Trace Controller"
+	depends on ARCH_TEGRA || COMPILE_TEST
+	select SERIAL_CORE
+	help
+	  Support for Tegra UTC (UART Trace controller) client serial port.
+
+	  UTC is a HW based serial port that allows multiplexing multiple data
+	  streams of up to 16 UTC clients into a single hardware serial port.
+
+config SERIAL_TEGRA_UTC_CONSOLE
+	bool "Support for console on a Tegra UTC serial port"
+	depends on SERIAL_TEGRA_UTC
+	select SERIAL_CORE_CONSOLE
+	default SERIAL_TEGRA_UTC
+	help
+	  If you say Y here, it will be possible to use a Tegra UTC client as
+	  the system console (the system console is the device which receives
+	  all kernel messages and warnings and which allows logins in single
+	  user mode).
+
+	  If unsure, say Y.
+
 config SERIAL_MAX3100
 	tristate "MAX3100/3110/3111/3222 support"
 	depends on SPI
drivers/tty/serial/Makefile +1 -0
index 6ff74f0a9530..7190914ba707 100644
@@ -86,6 +86,7 @@ obj-$(CONFIG_SERIAL_STM32)		+= stm32-usart.o
 obj-$(CONFIG_SERIAL_SUNPLUS)		+= sunplus-uart.o
 obj-$(CONFIG_SERIAL_TEGRA)		+= serial-tegra.o
 obj-$(CONFIG_SERIAL_TEGRA_TCU)		+= tegra-tcu.o
+obj-$(CONFIG_SERIAL_TEGRA_UTC)		+= tegra-utc.o
 obj-$(CONFIG_SERIAL_TIMBERDALE)		+= timbuart.o
 obj-$(CONFIG_SERIAL_TXX9)		+= serial_txx9.o
 obj-$(CONFIG_SERIAL_UARTLITE)		+= uartlite.o
drivers/tty/serial/tegra-utc.c new file +625 -0

625 lines not on this page · raw message

Signature · 1 line
2.43.0
Reviewed-by on v4 2/2
#3 lore raw

Re: [PATCH v4 2/2] serial: tegra-utc: Add driver for Tegra UART Trace Controller (UTC)

Quoted 8 lines · Kartik Rajput

The Tegra264 SoC supports the UART Trace Controller (UTC), which allows multiple firmware clients (up to 16) to share a single physical UART. Each client is provided with its own interrupt and has access to a 128-character wide FIFO for both transmit (TX) and receive (RX) operations.

Add tegra-utc driver to support Tegra UART Trace Controller (UTC) client.

Btw, neither the commit message nor cover letter explain why the new driver is needed. There are some serial Tegra drivers already. Is this one completely different from the existing drivers?

...

Quoted 1 line

+#define TEGRA_UTC_ENABLE 0x0

It would be nice to use fixed width values for the register offsets, e.g., 0x000 here.

drivers/tty/serial/tegra-utc.c line 28

Quoted 5 lines
drivers/tty/serial/tegra-utc.c new file +5 -0
+#define TEGRA_UTC_ENABLE_CLIENT_ENABLE		BIT(0)
+
+#define TEGRA_UTC_FIFO_THRESHOLD		0x8
+
+#define TEGRA_UTC_COMMAND			0xc

Ditto.

drivers/tty/serial/tegra-utc.c line 32

Quoted 4 lines
drivers/tty/serial/tegra-utc.c new file +3 -0
+#define TEGRA_UTC_COMMAND_RESET			BIT(0)
+#define TEGRA_UTC_COMMAND_FLUSH			BIT(1)
 
+#define TEGRA_UTC_DATA				0x20

Ditto.

Quoted 18 lines
drivers/tty/serial/tegra-utc.c new file +18 -0
+#define TEGRA_UTC_FIFO_STATUS			0x100
+#define TEGRA_UTC_FIFO_EMPTY			BIT(0)
+#define TEGRA_UTC_FIFO_FULL			BIT(1)
+#define TEGRA_UTC_FIFO_REQ			BIT(2)
+#define TEGRA_UTC_FIFO_OVERFLOW			BIT(3)
+#define TEGRA_UTC_FIFO_TIMEOUT			BIT(4)
+
+#define TEGRA_UTC_FIFO_OCCUPANCY		0x104
+
+#define TEGRA_UTC_INTR_STATUS			0x108
+#define TEGRA_UTC_INTR_SET			0x10c
+#define TEGRA_UTC_INTR_MASK			0x110
+#define TEGRA_UTC_INTR_CLEAR			0x114
+#define TEGRA_UTC_INTR_EMPTY			BIT(0)
+#define TEGRA_UTC_INTR_FULL			BIT(1)
+#define TEGRA_UTC_INTR_REQ			BIT(2)
+#define TEGRA_UTC_INTR_OVERFLOW			BIT(3)
+#define TEGRA_UTC_INTR_TIMEOUT			BIT(4)

...

drivers/tty/serial/tegra-utc.c line 356

Quoted 2 lines
drivers/tty/serial/tegra-utc.c new file +2 -0
+#if IS_ENABLED(CONFIG_SERIAL_TEGRA_UTC_CONSOLE)
+#define TEGRA_UTC_DEFAULT_FIFO_THRESHOLD	0x4

Hmm... Is this a register offset? If not, why it's in a hexadecimal format?

Quoted 1 line

+#define TEGRA_UTC_EARLYCON_MAX_BURST_SIZE 128

...

drivers/tty/serial/tegra-utc.c line 541

Quoted 8 lines
drivers/tty/serial/tegra-utc.c new file +8 -0
+static int tegra_utc_probe(struct platform_device *pdev)
+{
+	const unsigned int *soc_fifosize;
+	struct device *dev = &pdev->dev;
+	struct tegra_utc_port *tup;
+	int ret;
+
+	tup = devm_kzalloc(&pdev->dev, sizeof(*tup), GFP_KERNEL);

Use dev?

Quoted 13 lines
drivers/tty/serial/tegra-utc.c new file +13 -0
+	if (!tup)
+		return -ENOMEM;
+
+	ret = device_property_read_u32(dev, "tx-threshold", &tup->tx_threshold);
+	if (ret)
+		return dev_err_probe(dev, ret, "missing %s property\n", "tx-threshold");
+
+	ret = device_property_read_u32(dev, "rx-threshold", &tup->rx_threshold);
+	if (ret)
+		return dev_err_probe(dev, ret, "missing %s property\n", "rx-threshold");
+
+	soc_fifosize = device_get_match_data(&pdev->dev);
+	tup->fifosize = *soc_fifosize;

drivers/tty/serial/tegra-utc.c line 564

Quoted 10 lines
drivers/tty/serial/tegra-utc.c new file +9 -0
+
+	tup->tx_base = devm_platform_ioremap_resource_byname(pdev, "tx");
+	if (IS_ERR(tup->tx_base))
+		return PTR_ERR(tup->tx_base);
+
+	tup->rx_base = devm_platform_ioremap_resource_byname(pdev, "rx");
+	if (IS_ERR(tup->rx_base))
+		return PTR_ERR(tup->rx_base);
 
+	ret = tegra_utc_setup_port(&pdev->dev, tup);

Ditto.

drivers/tty/serial/tegra-utc.c line 571

Quoted 7 lines
drivers/tty/serial/tegra-utc.c new file +7 -0
+	if (ret)
+		dev_err_probe(dev, ret, "failed to setup uart port\n");
+
+	platform_set_drvdata(pdev, tup);
+
+	return tegra_utc_register_port(tup);
+}

...

With the above being addressed, FWIW,

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH v4 2/2] serial: tegra-utc: Add driver for Tegra UART Trace Controller (UTC)

Quoted 12 lines · Andy Shevchenko

External email: Use caution opening links or attachments

Quoted 8 lines · Kartik Rajput

The Tegra264 SoC supports the UART Trace Controller (UTC), which allows
multiple firmware clients (up to 16) to share a single physical UART.
Each client is provided with its own interrupt and has access to a 128-character wide FIFO for both transmit (TX) and receive (RX) operations.

Quoted 9 lines
Quoted 2 lines

Add tegra-utc driver to support Tegra UART Trace Controller (UTC) client.

Btw, neither the commit message nor cover letter explain why the new driver
is needed. There are some serial Tegra drivers already. Is this one completely
different from the existing drivers?

Tegra264 platforms have a single debug UART which is shared across multiple firmwares and the OS. The Tegra UTC is added to address this issue.

It is a completely different driver.

Quoted 7 lines

...

Quoted 1 line

+#define TEGRA_UTC_ENABLE                     0x0

It would be nice to use fixed width values for the register offsets, e.g., 0x000 here.

Ack.

Quoted 8 lines

drivers/tty/serial/tegra-utc.c line 28

Quoted 5 lines
drivers/tty/serial/tegra-utc.c new file +5 -0
+#define TEGRA_UTC_ENABLE_CLIENT_ENABLE               BIT(0)
+
+#define TEGRA_UTC_FIFO_THRESHOLD             0x8
+
+#define TEGRA_UTC_COMMAND                    0xc

Ditto.

Ack.

Quoted 7 lines

drivers/tty/serial/tegra-utc.c line 32

Quoted 4 lines
drivers/tty/serial/tegra-utc.c new file +3 -0
+#define TEGRA_UTC_COMMAND_RESET                      BIT(0)
+#define TEGRA_UTC_COMMAND_FLUSH                      BIT(1)
 
+#define TEGRA_UTC_DATA                               0x20

Ditto.

Ack.

Quoted 21 lines
Quoted 18 lines
drivers/tty/serial/tegra-utc.c new file +18 -0
+#define TEGRA_UTC_FIFO_STATUS                        0x100
+#define TEGRA_UTC_FIFO_EMPTY                 BIT(0)
+#define TEGRA_UTC_FIFO_FULL                  BIT(1)
+#define TEGRA_UTC_FIFO_REQ                   BIT(2)
+#define TEGRA_UTC_FIFO_OVERFLOW                      BIT(3)
+#define TEGRA_UTC_FIFO_TIMEOUT                       BIT(4)
+
+#define TEGRA_UTC_FIFO_OCCUPANCY             0x104
+
+#define TEGRA_UTC_INTR_STATUS                        0x108
+#define TEGRA_UTC_INTR_SET                   0x10c
+#define TEGRA_UTC_INTR_MASK                  0x110
+#define TEGRA_UTC_INTR_CLEAR                 0x114
+#define TEGRA_UTC_INTR_EMPTY                 BIT(0)
+#define TEGRA_UTC_INTR_FULL                  BIT(1)
+#define TEGRA_UTC_INTR_REQ                   BIT(2)
+#define TEGRA_UTC_INTR_OVERFLOW                      BIT(3)
+#define TEGRA_UTC_INTR_TIMEOUT                       BIT(4)

...

Quoted 6 lines

drivers/tty/serial/tegra-utc.c line 356

Quoted 2 lines
drivers/tty/serial/tegra-utc.c new file +2 -0
+#if IS_ENABLED(CONFIG_SERIAL_TEGRA_UTC_CONSOLE)
+#define TEGRA_UTC_DEFAULT_FIFO_THRESHOLD     0x4

Hmm... Is this a register offset? If not, why it's in a hexadecimal format?

This is not a register offset. I will use a decimal value here.

Quoted 4 lines
Quoted 1 line

+#define TEGRA_UTC_EARLYCON_MAX_BURST_SIZE    128

...

Quoted 10 lines

drivers/tty/serial/tegra-utc.c line 541

Quoted 8 lines
drivers/tty/serial/tegra-utc.c new file +8 -0
+static int tegra_utc_probe(struct platform_device *pdev)
+{
+     const unsigned int *soc_fifosize;
+     struct device *dev = &pdev->dev;
+     struct tegra_utc_port *tup;
+     int ret;
+
+     tup = devm_kzalloc(&pdev->dev, sizeof(*tup), GFP_KERNEL);

Use dev?

Thanks for catching this, this should've been done before. I will update this.

Quoted 11 lines
Quoted 11 lines

+     if (!tup)
+             return -ENOMEM;
+
+     ret = device_property_read_u32(dev, "tx-threshold", &tup-

Quoted 1 line

tx_threshold);

+     if (ret)
+             return dev_err_probe(dev, ret, "missing %s property\n", "tx-threshold");
+
+     ret = device_property_read_u32(dev, "rx-threshold", &tup-

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

rx_threshold);

+     if (ret)
+             return dev_err_probe(dev, ret, "missing %s property\n", "rx-threshold");
+
+     soc_fifosize = device_get_match_data(&pdev->dev); +

This needs update as well.

Quoted 12 lines
Quoted 11 lines

tup->fifosize = *soc_fifosize;
+
+     tup->tx_base = devm_platform_ioremap_resource_byname(pdev, "tx");
+     if (IS_ERR(tup->tx_base))
+             return PTR_ERR(tup->tx_base);
+
+     tup->rx_base = devm_platform_ioremap_resource_byname(pdev, "rx");
+     if (IS_ERR(tup->rx_base))
+             return PTR_ERR(tup->rx_base);

Quoted 3 lines
Quoted 1 line

+     ret = tegra_utc_setup_port(&pdev->dev, tup);

Ditto.

Ack.

Quoted 12 lines
Quoted 9 lines

+     if (ret)
+             dev_err_probe(dev, ret, "failed to setup uart port\n");

drivers/tty/serial/tegra-utc.c new file +5 -0
+
+     platform_set_drvdata(pdev, tup);
+
+     return tegra_utc_register_port(tup);
+}

...

Quoted 8 lines

With the above being addressed, FWIW,

--
With Best Regards,
Andy Shevchenko

Thanks & Regards,
Kartik