[U-Boot] [PATCH] serial: ns16550: Add register shift variable

Felix Brack fb at ltec.ch
Fri Jul 13 14:43:00 UTC 2018


This patch adds a new Kconfig variable that allows setting
the register shift value for the ns16550 driver to some other
value then 0 if not defined by the DT. All credit for this
patch goes to Lokesh Vutla as it was his idea.

The motivation for writing this patch originates in the
effort of synchronizing U-Boot DT to Linux DT for am33xx SOCs.
The current am33xx.dtsi file from U-Boot defines the <reg-shift>
property for all UART nodes. The actual (4.18+) am33xx.dtsi
file from Linux does not define <reg-shift> anymore. To prevent
(probably difficult) changes in many .dts and .dtsi files once
the synchronization is done, one can use this new variable. For
the pdu001 board, for example, SYS_NS16550_REG_SHIFT is set
to 2; no need to clutter U-Boot and board specific dts files
with <reg-shift> properties.

Signed-off-by: Felix Brack <fb at ltec.ch>
---

 drivers/serial/Kconfig   | 12 ++++++++++++
 drivers/serial/ns16550.c |  3 ++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 766e5ce..c80ad4d 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -530,6 +530,18 @@ config SYS_NS16550
 	  be used. It can be a constant or a function to get clock, eg,
 	  get_serial_clock().
 
+config SYS_NS16550_REG_SHIFT
+	int "Number of bytes to shift register offsets"
+	default 0
+	depends on SYS_NS16550
+	help
+	  Use this to specify the amount of bytes between discrete
+	  device registers. If, for example, the device registers are
+	  located at 0x00, 0x04, 0x08, 0x0C and so forth than set
+	  this to 2. The default value is 0.
+	  Note that a <reg-shift> property defined in a UART node of
+	  the device tree will always take precedence.
+
 config INTEL_MID_SERIAL
 	bool "Intel MID platform UART support"
 	depends on DM_SERIAL && OF_CONTROL
diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c
index 9c80090..9ff6dbe 100644
--- a/drivers/serial/ns16550.c
+++ b/drivers/serial/ns16550.c
@@ -442,7 +442,8 @@ int ns16550_serial_ofdata_to_platdata(struct udevice *dev)
 #endif
 
 	plat->reg_offset = dev_read_u32_default(dev, "reg-offset", 0);
-	plat->reg_shift = dev_read_u32_default(dev, "reg-shift", 0);
+	plat->reg_shift = dev_read_u32_default(dev, "reg-shift",
+					       CONFIG_SYS_NS16550_REG_SHIFT);
 
 	err = clk_get_by_index(dev, 0, &clk);
 	if (!err) {
-- 
2.7.4



More information about the U-Boot mailing list