Add support for Tegra UART Trace Controller (UTC) client
v3 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 | 634 ++++++++++++++++++ 4 files changed, 731 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
PATCH v3 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
@@ -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
Re: [PATCH v3 1/2] dt-bindings: serial: Add bindings for nvidia,tegra264-utc
Quoted 8 lines · Kartik Rajput
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.
Signed-off-by Kartik Rajput <[email protected]>
Best regards,
Krzysztof
PATCH v3 2/2 serial: tegra-utc: Add driver for Tegra UART Trace Controller (UTC)
In reply to Kartik RajputThe 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.
---
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 | 634 +++++++++++++++++++++++++++++++++ 3 files changed, 658 insertions(+) create mode 100644 drivers/tty/serial/tegra-utc.c
drivers/tty/serial/Kconfig +23 -0
@@ -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
@@ -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 +634 -0
634 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v3 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.
...
Quoted 3 lines
+/*
+ * NVIDIA Tegra UTC (UART Trace Controller) driver.
+ */
Can be a single line.
...
drivers/tty/serial/tegra-utc.c line 13
Quoted 8 lines
drivers/tty/serial/tegra-utc.c new file +7
-0+#include <linux/bits.h> +#include <linux/console.h> +#include <linux/container_of.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/io.h> +#include <linux/iopoll.h>
iopoll.h guarantees to include io.h in case you want to have less lines here. (yeah, I know that the header guarantees is a tribal knowledge, it's undocumented)
drivers/tty/serial/tegra-utc.c line 17
Quoted 5 lines
drivers/tty/serial/tegra-utc.c new file +4
-0+#include <linux/kfifo.h> +#include <linux/module.h> +#include <linux/mod_devicetable.h> +#include <linux/of.h>
Is this being used now?
Quoted 8 lines
drivers/tty/serial/tegra-utc.c new file +8
-0+#include <linux/property.h> +#include <linux/platform_device.h> +#include <linux/serial.h> +#include <linux/serial_core.h> +#include <linux/slab.h> +#include <linux/tty.h> +#include <linux/tty_flip.h> +#include <linux/types.h>
...
Quoted 1 line
+#define
UART_NR16
Bad naming, calling for collisions. Move it to the driver's namespace.
...
drivers/tty/serial/tegra-utc.c line 137
Quoted 11 lines
drivers/tty/serial/tegra-utc.c new file +11
-0+static void tegra_utc_init_tx (struct tegra_utc_port *tup) +{ +/* Disable TX. */ +tegra_utc_tx_writel (tup,0x0 ,TEGRA_UTC_ENABLE ); + +/* Update the FIFO Threshold. */ +tegra_utc_tx_writel (tup, tup->tx_threshold,TEGRA_UTC_FIFO_THRESHOLD ); + +/* Clear and mask all the interrupts. */ +tegra_utc_tx_writel (tup,TEGRA_UTC_INTR_REQ |TEGRA_UTC_INTR_FULL |TEGRA_UTC_INTR_EMPTY , +TEGRA_UTC_INTR_CLEAR );
Here...
Quoted 7 lines
drivers/tty/serial/tegra-utc.c new file +7
-0+tegra_utc_disable_tx_irq (tup); + +/* Enable TX. */ +tegra_utc_tx_writel (tup,TEGRA_UTC_ENABLE_CLIENT_ENABLE ,TEGRA_UTC_ENABLE ); +} + +static void tegra_utc_init_rx (struct tegra_utc_port *tup)
drivers/tty/serial/tegra-utc.c line 154
Quoted 10 lines
drivers/tty/serial/tegra-utc.c new file +10
-0+{ + tup->rx_irqmask =TEGRA_UTC_INTR_REQ |TEGRA_UTC_INTR_TIMEOUT ; + +tegra_utc_rx_writel (tup,TEGRA_UTC_COMMAND_RESET ,TEGRA_UTC_COMMAND ); +tegra_utc_rx_writel (tup, tup->rx_threshold,TEGRA_UTC_FIFO_THRESHOLD ); + +/* Clear all the pending interrupts. */ +tegra_utc_rx_writel (tup,TEGRA_UTC_INTR_TIMEOUT |TEGRA_UTC_INTR_OVERFLOW | +TEGRA_UTC_INTR_REQ |TEGRA_UTC_INTR_FULL | +TEGRA_UTC_INTR_EMPTY ,TEGRA_UTC_INTR_CLEAR );
...and here the potential of deduplication by introducing an additional constant:
#define TEGRA_UTC_INTR_COMMON \ (...)
(choose better name)
Quoted 6 lines
drivers/tty/serial/tegra-utc.c new file +6
-0+tegra_utc_rx_writel (tup, tup->rx_irqmask,TEGRA_UTC_INTR_MASK ); +tegra_utc_rx_writel (tup, tup->rx_irqmask,TEGRA_UTC_INTR_SET ); + +/* Enable RX. */ +tegra_utc_rx_writel (tup,TEGRA_UTC_ENABLE_CLIENT_ENABLE ,TEGRA_UTC_ENABLE ); +}
...
drivers/tty/serial/tegra-utc.c line 170
Quoted 9 lines
drivers/tty/serial/tegra-utc.c new file +9
-0+static bool tegra_utc_tx_chars (struct tegra_utc_port *tup) +{ +struct uart_port *port = &tup->port; +unsigned int pending; +u8 c; + + pending =uart_port_tx (port, c, + !(tegra_utc_tx_readl (tup,TEGRA_UTC_FIFO_STATUS ) &TEGRA_UTC_FIFO_FULL ), +tegra_utc_tx_writel (tup, c,TEGRA_UTC_DATA ));
Make the last two to reside in temporary variables with self-explanatory names.
Quoted 1 line
+
Redundant blank line.
drivers/tty/serial/tegra-utc.c line 175
Quoted 4 lines
drivers/tty/serial/tegra-utc.c new file +4
-0+if (pending) +return true; + +return false;
return pending;
Quoted 1 line
+}
...
drivers/tty/serial/tegra-utc.c line 287
Quoted 8 lines
drivers/tty/serial/tegra-utc.c new file +8
-0+static int tegra_utc_startup (struct uart_port *port) +{ + struct tegra_utc_port *tup = container_of(port, struct tegra_utc_port, port); +int ret; + +tegra_utc_hw_init (tup); + + ret =request_irq (port->irq, tegra_utc_isr,0 ,dev_name (port->dev), tup);
Seems the same Q stands about sharing, perhaps a comment why it's expected to be always exclusive?
Quoted 5 lines
drivers/tty/serial/tegra-utc.c new file +5
-0+if (ret <0 ) +dev_err (port->dev,"failed to register interrupt handler\n" ); + +return ret; +}
...
drivers/tty/serial/tegra-utc.c line 462
Quoted 6 lines
drivers/tty/serial/tegra-utc.c new file +6
-0+for (i =0 ; i < len; i++) { +if (!nbcon_enter_unsafe (wctxt)) +break ; + +read_poll_timeout_atomic (tegra_utc_tx_readl, val, !(val &TEGRA_UTC_FIFO_FULL ), +0 ,USEC_PER_SEC , false, tup,TEGRA_UTC_FIFO_STATUS );
No error check?
drivers/tty/serial/tegra-utc.c line 468
Quoted 7 lines
drivers/tty/serial/tegra-utc.c new file +6
-0+uart_console_write (&tup->port, wctxt->outbuf + i,1 , tegra_utc_console_putchar); + +if (!nbcon_exit_unsafe (wctxt)) +break ; + } +
Unneeded blank line.
Quoted 1 line
+}
...
Quoted 4 lines
drivers/tty/serial/tegra-utc.c new file +4
-0+static int tegra_utc_probe (struct platform_device *pdev) +{ +const unsigned int *soc_fifosize; +struct device *dev = &pdev->dev;
drivers/tty/serial/tegra-utc.c line 556
Quoted 10 lines
drivers/tty/serial/tegra-utc.c new file +10
-0+struct tegra_utc_port *tup; +int ret; + + tup =devm_kzalloc (&pdev->dev,sizeof (*tup),GFP_KERNEL ); +if (!tup) +return -ENOMEM ; + + ret =device_property_read_u32 (dev,"tx-threshold" , &tup->tx_threshold); +if (ret) +return dev_err_probe (dev, ret,"missing tx-threshold device-tree property\n" );
' device-tree' is redundant part.
drivers/tty/serial/tegra-utc.c line 560
Quoted 3 lines
drivers/tty/serial/tegra-utc.c new file +3
-0+ ret =device_property_read_u32 (dev,"rx-threshold" , &tup->rx_threshold); +if (ret) +return dev_err_probe (dev, ret,"missing rx-threshold device-tree property\n" );
Ditto.
Also in a form of
return dev_err_probe(dev, ret, "missing %s property\n", "rx-threshold");
in both cases the size of the object file will be smaller by a couple of dozens of bytes.
Quoted 19 lines
drivers/tty/serial/tegra-utc.c new file +19
-0+ soc_fifosize =device_get_match_data (&pdev->dev); + 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); + + ret =tegra_utc_setup_port (&pdev->dev, tup); +if (ret) +dev_err_probe (dev, ret,"failed to setup uart port\n" ); + +platform_set_drvdata (pdev, tup); + +return tegra_utc_register_port (tup); +}
...
Quoted 6 lines
drivers/tty/serial/tegra-utc.c new file +6
-0+static int __init tegra_utc_init (void ) +{ +int ret; + + ret =uart_register_driver (&tegra_utc_driver); +if (ret)
drivers/tty/serial/tegra-utc.c line 621
Quoted 10 lines
drivers/tty/serial/tegra-utc.c new file +9
-0+return ret; + + ret =platform_driver_register (&tegra_utc_platform_driver); +if (ret) { +uart_unregister_driver (&tegra_utc_driver); +return ret; + } + +return 0 ;
Just
return ret;
will be good instead of the above 4 LoCs.
Quoted 1 line
+}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jiri Slaby
maintainerRe: [PATCH v3 2/2] serial: tegra-utc: Add driver for Tegra UART Trace Controller (UTC)
Quoted 11 lines · Andy Shevchenko
drivers/tty/serial/tegra-utc.c line 170
Quoted 9 lines
drivers/tty/serial/tegra-utc.c new file +9
-0+static bool tegra_utc_tx_chars (struct tegra_utc_port *tup) +{ +struct uart_port *port = &tup->port; +unsigned int pending; +u8 c; + + pending =uart_port_tx (port, c, + !(tegra_utc_tx_readl (tup,TEGRA_UTC_FIFO_STATUS ) &TEGRA_UTC_FIFO_FULL ), +tegra_utc_tx_writel (tup, c,TEGRA_UTC_DATA ));Make the last two to reside in temporary variables with self-explanatory names.
Not sure what you mean here? They are needed to be evaluated (read/written) in every loop.
Signature · 2 lines
js suse labs
Re: [PATCH v3 2/2] serial: tegra-utc: Add driver for Tegra UART Trace Controller (UTC)
Quoted 1 line · Jiri Slaby
On 12. 02. 25, 16:09, Andy Shevchenko wrote:
...
Quoted 8 lines
Quoted 5 lines
drivers/tty/serial/tegra-utc.c line 170
Quoted 3 lines
drivers/tty/serial/tegra-utc.c new file +3
-0+ pending =uart_port_tx (port, c, + !(tegra_utc_tx_readl (tup,TEGRA_UTC_FIFO_STATUS ) &TEGRA_UTC_FIFO_FULL ), +tegra_utc_tx_writel (tup, c,TEGRA_UTC_DATA ));Make the last two to reside in temporary variables with self-explanatory names.
Not sure what you mean here? They are needed to be evaluated (read/written) in every loop.
Ah, uart_port_tx() is a macro!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 2/2] serial: tegra-utc: Add driver for Tegra UART Trace Controller (UTC)
In reply to Andy ShevchenkoHi Andy,
Thanks for the review!
Quoted 15 lines · Andy Shevchenko
External email: Use caution opening links or attachments
Quoted 10 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.
Quoted 8 lines
...
Quoted 3 lines
+/*
+ * NVIDIA Tegra UTC (UART Trace Controller) driver.
+ */Can be a single line.
Ack.
Quoted 8 lines
...
Quoted 5 lines
drivers/tty/serial/tegra-utc.c new file +5
-0+#include <linux/bits.h> +#include <linux/console.h> +#include <linux/container_of.h> +#include <linux/device.h> +#include <linux/err.h>
Quoted 7 lines
drivers/tty/serial/tegra-utc.c line 13
Quoted 2 lines
drivers/tty/serial/tegra-utc.c new file +2
-0+#include <linux/io.h> +#include <linux/iopoll.h>
iopoll.hguarantees to includeio.hin case you want to have less lines here.
(yeah, I know that the header guarantees is a tribal knowledge, it's undocumented)
Ack. I will remove io.h from here.
Quoted 9 lines
drivers/tty/serial/tegra-utc.c line 17
Quoted 6 lines
drivers/tty/serial/tegra-utc.c new file +4
-0+#include <linux/kfifo.h> +#include <linux/module.h> +#include <linux/mod_devicetable.h> +#include <linux/of.h> Is this being used now?
No, I will remove this.
Quoted 11 lines
Quoted 8 lines
drivers/tty/serial/tegra-utc.c new file +8
-0+#include <linux/property.h> +#include <linux/platform_device.h> +#include <linux/serial.h> +#include <linux/serial_core.h> +#include <linux/slab.h> +#include <linux/tty.h> +#include <linux/tty_flip.h> +#include <linux/types.h> ...
Quoted 5 lines
Quoted 1 line
+#define UART_NR 16
Bad naming, calling for collisions. Move it to the driver's namespace.
Ack.
Quoted 46 lines
...
Quoted 7 lines
drivers/tty/serial/tegra-utc.c new file +7
-0+static void tegra_utc_init_tx (struct tegra_utc_port *tup) +{ + /* Disable TX. */ + tegra_utc_tx_writel(tup, 0x0, TEGRA_UTC_ENABLE); + + /* Update the FIFO Threshold. */ + tegra_utc_tx_writel(tup, tup->tx_threshold,Quoted 6 lines
TEGRA_UTC_FIFO_THRESHOLD);
+
+ /* Clear and mask all the interrupts. */ + tegra_utc_tx_writel(tup,TEGRA_UTC_INTR_REQ|TEGRA_UTC_INTR_FULL|TEGRA_UTC_INTR_EMPTY, +TEGRA_UTC_INTR_CLEAR);Here...
Quoted 16 lines
+
tegra_utc_disable_tx_irq(tup);
+
+ /* Enable TX. */
+tegra_utc_tx_writel(tup, TEGRA_UTC_ENABLE_CLIENT_ENABLE, TEGRA_UTC_ENABLE);drivers/tty/serial/tegra-utc.c new file +5
-0+} + +static void tegra_utc_init_rx (struct tegra_utc_port *tup) +{ + tup->rx_irqmask = TEGRA_UTC_INTR_REQ |
TEGRA_UTC_INTR_TIMEOUT;
+
+tegra_utc_rx_writel(tup, TEGRA_UTC_COMMAND_RESET, TEGRA_UTC_COMMAND);
+tegra_utc_rx_writel(tup, tup->rx_threshold, TEGRA_UTC_FIFO_THRESHOLD);Quoted 8 lines
+
+ /* Clear all the pending interrupts. */
+ tegra_utc_rx_writel(tup,TEGRA_UTC_INTR_TIMEOUT|TEGRA_UTC_INTR_OVERFLOW|
+TEGRA_UTC_INTR_REQ|TEGRA_UTC_INTR_FULL|
+TEGRA_UTC_INTR_EMPTY,TEGRA_UTC_INTR_CLEAR);...and here the potential of deduplication by introducing an additional constant:
Quoted 5 lines
#define TEGRA_UTC_INTR_COMMON \
(...)(choose better name)
Ack.
I think TEGRA_UTC_INTR_COMMON would be a good name for this macro since these interrupts are common between TX and RX client.
Quoted 26 lines
Quoted 9 lines
+
tegra_utc_rx_writel(tup, tup->rx_irqmask, TEGRA_UTC_INTR_MASK);
+tegra_utc_rx_writel(tup, tup->rx_irqmask, TEGRA_UTC_INTR_SET);
+
+ /* Enable RX. */
+tegra_utc_rx_writel(tup, TEGRA_UTC_ENABLE_CLIENT_ENABLE, TEGRA_UTC_ENABLE);
+}...
Quoted 10 lines
drivers/tty/serial/tegra-utc.c new file +8
-0+static bool tegra_utc_tx_chars (struct tegra_utc_port *tup) +{ + struct uart_port *port = &tup->port; + unsigned int pending; + u8 c; + + pending = uart_port_tx(port, c, + !(tegra_utc_tx_readl(tup, TEGRA_UTC_FIFO_STATUS)&
TEGRA_UTC_FIFO_FULL),
+tegra_utc_tx_writel(tup, c, TEGRA_UTC_DATA));Make the last two to reside in temporary variables with self- explanatory names.
Quoted 3 lines
Quoted 1 line
+
Redundant blank line.
Ack.
Quoted 8 lines
Quoted 5 lines
+ if (pending)
+ return true;
+
+ return false;return pending;
Ack.
Quoted 13 lines
Quoted 1 line
+}
...
Quoted 9 lines
drivers/tty/serial/tegra-utc.c new file +3
-0+static int tegra_utc_startup (struct uart_port *port) +{ + struct tegra_utc_port *tup = container_of(port, struct
tegra_utc_port, port);
+ int ret;drivers/tty/serial/tegra-utc.c new file +4
-0+ + tegra_utc_hw_init(tup); + + ret = request_irq(port->irq, tegra_utc_isr, 0, dev_name(port-
Quoted 5 lines
Quoted 1 line
Quoted 1 line
dev), tup);
Seems the same Q stands about sharing, perhaps a comment why it's expected to
be always exclusive?
Ack. I will drop a comment here.
Quoted 19 lines
Quoted 7 lines
+ if (ret < 0)
+dev_err(port->dev, "failed to register interrupt handler\n");drivers/tty/serial/tegra-utc.c new file +3
-0+ + return ret; +}...
Quoted 8 lines
+ for (i = 0; i < len; i++) {
+ if (!nbcon_enter_unsafe(wctxt))
+ break;
+
+ read_poll_timeout_atomic(tegra_utc_tx_readl, val, !(val &TEGRA_UTC_FIFO_FULL),
+ 0,USEC_PER_SEC, false, tup,TEGRA_UTC_FIFO_STATUS);
Quoted 2 lines
No error check?
I'm not sure about this. The case where the TX FIFO doesn't clear up, even after polling for 1 second, is highly unlikely, especially since there's no flow control involved here. Even if that did happen, writing to the TX FIFO should just result in an overflow, which is probably acceptable in this scenario.
Quoted 10 lines
drivers/tty/serial/tegra-utc.c line 468
Quoted 8 lines
+
uart_console_write(&tup->port, wctxt->outbuf + i, 1, tegra_utc_console_putchar);drivers/tty/serial/tegra-utc.c new file +5
-0+ + if (!nbcon_exit_unsafe(wctxt)) + break; + } +Unneeded blank line.
Ack.
Quoted 17 lines
Quoted 2 lines
+}
...
Quoted 12 lines
drivers/tty/serial/tegra-utc.c new file +12
-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); + if (!tup) + return -ENOMEM; + + ret = device_property_read_u32(dev, "tx-threshold", &tup-
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
tx_threshold);+ if (ret)
+ returndev_err_probe(dev, ret, "missing tx-threshold device-tree property\n");' device-tree' is redundant part.
Ack.
Quoted 9 lines
Quoted 6 lines
+ ret = device_property_read_u32(dev, "rx-threshold", &tup-
Quoted 1 line
rx_threshold);+ if (ret)
+ returndev_err_probe(dev, ret, "missing rx-threshold device-tree property\n");Ditto.
Quoted 8 lines
Also in a form of
return
dev_err_probe(dev, ret, "missing %s property\n", "rx-threshold");in both cases the size of the object file will be smaller by a couple of dozens
of bytes.
Ack.
Quoted 43 lines
Quoted 23 lines
+
soc_fifosize=device_get_match_data(&pdev->dev); +tup->fifosize=*soc_fifosize;
+
+tup->tx_base=devm_platform_ioremap_resource_byname(pdev, "tx");
+ if (IS_ERR(tup->tx_base))
+ returnPTR_ERR(tup->tx_base);
+
+tup->rx_base=devm_platform_ioremap_resource_byname(pdev, "rx");
+ if (IS_ERR(tup->rx_base))
+ returnPTR_ERR(tup->rx_base);
+
+ ret =tegra_utc_setup_port(&pdev->dev, tup);
+ 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 6 lines
drivers/tty/serial/tegra-utc.c new file +6
-0+static int __init tegra_utc_init (void ) +{ + int ret; + + ret = uart_register_driver(&tegra_utc_driver); + if (ret)drivers/tty/serial/tegra-utc.c line 621
Quoted 10 lines
drivers/tty/serial/tegra-utc.c new file +9
-0+ return ret; + + ret = platform_driver_register(&tegra_utc_platform_driver); + if (ret) { + uart_unregister_driver(&tegra_utc_driver); + return ret; + } + + return 0;
Quoted 6 lines
Just
return ret;
will be good instead of the above 4 LoCs.
Ack.
Quoted 7 lines
Quoted 1 line
+}
--
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 2/2] serial: tegra-utc: Add driver for Tegra UART Trace Controller (UTC)
Quoted 2 lines · Kartik Rajput
Quoted 1 line · Andy Shevchenko
On Wed, Feb 12, 2025 at 04:11:32PM +0530, Kartik Rajput wrote:
...
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
+ for (i = 0; i < len; i++) {
+ if (!nbcon_enter_unsafe(wctxt))
+ break;
+
+ read_poll_timeout_atomic(tegra_utc_tx_readl, val, !(val &TEGRA_UTC_FIFO_FULL),
+ 0,USEC_PER_SEC, false, tup,TEGRA_UTC_FIFO_STATUS);
Quoted 7 lines
Quoted 1 line
No error check?
I'm not sure about this. The case where the TX FIFO doesn't clear up, even after polling for 1 second, is highly unlikely, especially since there's no flow control involved here. Even if that did happen, writing to the TX FIFO should just result in an overflow, which is probably acceptable in this scenario.
Perhaps a warning (debug?) message in such a case?
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
+
uart_console_write(&tup->port, wctxt->outbuf + i, 1, tegra_utc_console_putchar);
+
+ if (!nbcon_exit_unsafe(wctxt))
+ break;
+ }
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 2/2] serial: tegra-utc: Add driver for Tegra UART Trace Controller (UTC)
Quoted 30 lines · On Thu, 2025-02-13 at 11:55 +0200, [email protected] wrote:
External email: Use caution opening links or attachments
Quoted 2 lines · Kartik Rajput
Quoted 1 line · Andy Shevchenko
On Wed, Feb 12, 2025 at 04:11:32PM +0530, Kartik Rajput wrote:
...
Quoted 12 lines
Quoted 11 lines
Quoted 9 lines
+ for (i = 0; i < len; i++) {
+ if (!nbcon_enter_unsafe(wctxt))
+ break;
+
+ read_poll_timeout_atomic(tegra_utc_tx_readl, val, !(val &TEGRA_UTC_FIFO_FULL),
+ 0,USEC_PER_SEC, false, tup,TEGRA_UTC_FIFO_STATUS);No error check?
Quoted 8 lines
I'm not sure about this. The case where the TX FIFO doesn't clear up,
even after polling for 1 second, is highly unlikely, especially since
there's no flow control involved here. Even if that did happen, writing
to the TX FIFO should just result in an overflow, which is probably acceptable in this scenario.
Quoted 1 line
Perhaps a warning (debug?) message in such a case?
I would prefer avoiding any prints in this function, as we are writing debug messages to the UART HW here.
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ uart_console_write(&tup->port,
wctxt->outbuf+ i, 1,tegra_utc_console_putchar);
+
+ if (!nbcon_exit_unsafe(wctxt))
+ break;
+ }
Quoted 5 lines
--
With Best Regards,
Andy Shevchenko
Thanks & Regards,
Kartik
Re: [PATCH v3 2/2] serial: tegra-utc: Add driver for Tegra UART Trace Controller (UTC)
Quoted 5 lines · Kartik Rajput
Quoted 3 lines · On Thu, 2025-02-13 at 11:55 +0200, [email protected] wrote:
Quoted 2 lines · Kartik Rajput
Quoted 1 line · Andy Shevchenko
On Wed, Feb 12, 2025 at 04:11:32PM +0530, Kartik Rajput wrote:
...
Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 11 lines
Quoted 9 lines
+ for (i = 0; i < len; i++) {
+ if (!nbcon_enter_unsafe(wctxt))
+ break;
+
+ read_poll_timeout_atomic(tegra_utc_tx_readl, val, !(val &TEGRA_UTC_FIFO_FULL),
+ 0,USEC_PER_SEC, false, tup,TEGRA_UTC_FIFO_STATUS);No error check?
I'm not sure about this. The case where the TX FIFO doesn't clear up,
even after polling for 1 second, is highly unlikely, especially since
there's no flow control involved here. Even if that did happen, writing
to the TX FIFO should just result in an overflow, which is probably acceptable in this scenario.
Quoted 4 lines
Quoted 1 line
Perhaps a warning (debug?) message in such a case?
I would prefer avoiding any prints in this function, as we are writing debug messages to the UART HW here.
Not every printf() goes to UART, but to your point the NBCON should solve that issue to some extent. Of course, if the HW in a broken (unrecoverable) state, nothing won't help.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
+ uart_console_write(&tup->port,
wctxt->outbuf+ i, 1,tegra_utc_console_putchar);
+
+ if (!nbcon_exit_unsafe(wctxt))
+ break;
+ }
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 2/2] serial: tegra-utc: Add driver for Tegra UART Trace Controller (UTC)
Quoted 45 lines · On Thu, 2025-02-13 at 12:57 +0200, [email protected] wrote:
External email: Use caution opening links or attachments
Quoted 7 lines · Kartik Rajput
Quoted 4 lines · On Thu, 2025-02-13 at 11:55 +0200, [email protected] wrote:
Quoted 3 lines · Kartik Rajput
Quoted 2 lines · Andy Shevchenko
On Wed, Feb 12, 2025 at 04:11:32PM +0530, Kartik Rajput wrote:
...
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 12 lines
Quoted 11 lines
+ for (i = 0; i < len; i++) {
+ if (!nbcon_enter_unsafe(wctxt))
+ break;
+
+ read_poll_timeout_atomic(tegra_utc_tx_readl, val,
!(val &TEGRA_UTC_FIFO_FULL),
+ 0,USEC_PER_SEC, false,
tup,TEGRA_UTC_FIFO_STATUS);Quoted 1 line
No error check?
I'm not sure about this. The case where the TX FIFO doesn't clear
up,
even after polling for 1 second, is highly unlikely, especially since
there's no flow control involved here. Even if that did happen, writing
to the TX FIFO should just result in an overflow, which is probably
acceptable in this scenario.Quoted 5 lines
Quoted 1 line
Perhaps a warning (debug?) message in such a case?
I would prefer avoiding any prints in this function, as we are writing
debug messages to the UART HW here.
Quoted 6 lines
Not every
printf()goes to UART, but to your point the NBCON should solve that
issue to some extent. Of course, if the HW in a broken (unrecoverable) state,
nothing won't help.
I agree, but we still risk flooding up the ring buffer if we add debug message here.
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ uart_console_write(&tup->port,
wctxt->outbuf
+ i,
1,tegra_utc_console_putchar);
+
+ if (!nbcon_exit_unsafe(wctxt))
+ break;
+ }
Quoted 5 lines
--
With Best Regards,
Andy Shevchenko
Thanks & Regards,
Kartik