lib: utils: Improve fdt_parse_uart8250() API
authorAnup Patel <anup.patel@wdc.com>
Fri, 24 Apr 2020 09:51:34 +0000 (15:21 +0530)
committerAnup Patel <anup@brainfault.org>
Fri, 1 May 2020 04:06:13 +0000 (09:36 +0530)
The information parsed by fdt_parse_uart8250() API is not complete.
We need to parse reg-shift and reg-io-width for UART 8520 as well.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
include/sbi_utils/fdt/fdt_helper.h
lib/utils/fdt/fdt_helper.c

index 06b8a62..d3cc791 100644 (file)
@@ -14,6 +14,8 @@ struct platform_uart_data {
        unsigned long addr;
        unsigned long freq;
        unsigned long baud;
+       unsigned long reg_shift;
+       unsigned long reg_io_width;
 };
 
 struct platform_plic_data {
index 07f7221..f620e74 100644 (file)
 #include <sbi/sbi_scratch.h>
 #include <sbi_utils/fdt/fdt_helper.h>
 
+#define DEFAULT_UART_FREQ              0
+#define DEFAULT_UART_BAUD              115200
+#define DEFAULT_UART_REG_SHIFT         0
+#define DEFAULT_UART_REG_IO_WIDTH      1
+
 static int fdt_get_node_addr_size(void *fdt, int node, unsigned long *addr,
                                  unsigned long *size)
 {
@@ -81,10 +86,26 @@ int fdt_parse_uart8250(void *fdt, struct platform_uart_data *uart,
        val = (fdt32_t *)fdt_getprop(fdt, nodeoffset, "clock-frequency", &len);
        if (len > 0 && val)
                uart->freq = fdt32_to_cpu(*val);
+       else
+               uart->freq = DEFAULT_UART_FREQ;
 
        val = (fdt32_t *)fdt_getprop(fdt, nodeoffset, "current-speed", &len);
        if (len > 0 && val)
                uart->baud = fdt32_to_cpu(*val);
+       else
+               uart->baud = DEFAULT_UART_BAUD;
+
+       val = (fdt32_t *)fdt_getprop(fdt, nodeoffset, "reg-shift", &len);
+       if (len > 0 && val)
+               uart->reg_shift = fdt32_to_cpu(*val);
+       else
+               uart->reg_shift = DEFAULT_UART_REG_SHIFT;
+
+       val = (fdt32_t *)fdt_getprop(fdt, nodeoffset, "reg-io-width", &len);
+       if (len > 0 && val)
+               uart->reg_io_width = fdt32_to_cpu(*val);
+       else
+               uart->reg_io_width = DEFAULT_UART_REG_IO_WIDTH;
 
        return 0;
 }