[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] drivers: char: omap-uart: add "clock-hz" option



Quite a few TI K3 devices do not have clock-frequency specified in their
respective UART nodes. However hard-coding the frequency is not a
solution as the function clock input can differ between SoCs. So,
similar to com1/com2, let the user pass the frequency as a dtuart option
via the bootargs. If not specified it will fallback to the same DT
parsing as before. For example, dtuart=serial2:clock-hz=48000000 can be
a valid bootarg.

Signed-off-by: Amneesh Singh <a-singh21@xxxxxx>
---
 xen/drivers/char/omap-uart.c | 62 +++++++++++++++++++++++++++++-------
 1 file changed, 50 insertions(+), 12 deletions(-)

diff --git a/xen/drivers/char/omap-uart.c b/xen/drivers/char/omap-uart.c
index 1079198..660c486 100644
--- a/xen/drivers/char/omap-uart.c
+++ b/xen/drivers/char/omap-uart.c
@@ -305,33 +305,71 @@ static struct uart_driver __read_mostly omap_uart_driver 
= {
     .vuart_info = omap_vuart_info,
 };
 
+static void __init omap_uart_parse_config(struct omap_uart *uart,
+                                         const char *config) {
+
+    char options[256];
+    char *value, *start = options;
+
+    if ( !strcmp(config, "") )
+        return;
+
+    strlcpy(options, config, ARRAY_SIZE(options));
+
+    while (start != NULL)
+    {
+        char *name;
+
+        /* Parse next name-value pair. */
+        value = strsep(&start, ",");
+        name = strsep(&value, "=");
+
+        if ( !strcmp(name, "clock-hz") )
+            uart->clock_hz = simple_strtoul(value, NULL, 0);
+        else
+            printk("WARNING: UART configuration option %s is not supported\n",
+                   name);
+
+    }
+}
+
 static int __init omap_uart_init(struct dt_device_node *dev,
                                  const void *data)
 {
     const char *config = data;
     struct omap_uart *uart;
-    u32 clkspec;
     int res;
     paddr_t addr, size;
 
-    if ( strcmp(config, "") )
-        printk("WARNING: UART configuration is not supported\n");
-
     uart = &omap_com;
 
-    res = dt_property_read_u32(dev, "clock-frequency", &clkspec);
-    if ( !res )
-    {
-        printk("omap-uart: Unable to retrieve the clock frequency\n");
-        return -EINVAL;
-    }
-
-    uart->clock_hz = clkspec;
+    /* Default configuration. */
+    uart->clock_hz = 0;
     uart->baud = 115200;
     uart->data_bits = 8;
     uart->parity = UART_PARITY_NONE;
     uart->stop_bits = 1;
 
+    /*
+     * Parse dtuart options.
+     * Valid options:
+     *   - clock-hz
+     */
+    omap_uart_parse_config(uart, config);
+
+    /* If clock-hz is missing. */
+    if ( uart->clock_hz == 0 )
+    {
+        u32 clkspec;
+        res = dt_property_read_u32(dev, "clock-frequency", &clkspec);
+        if ( !res )
+        {
+            printk("omap-uart: Unable to retrieve the clock frequency\n");
+            return -EINVAL;
+        }
+        uart->clock_hz = clkspec;
+    }
+
     res = dt_device_get_paddr(dev, 0, &addr, &size);
     if ( res )
     {
-- 
2.34.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.