]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - drivers/serial/ns16550.c
ns16550: Fix mem mapped endian check
[people/ms/u-boot.git] / drivers / serial / ns16550.c
index 4f86780cb120b37ed78d849ac9d1f0e86f3195cd..53550bfa8883317c4d82ca7e03a5fd75b9113727 100644 (file)
@@ -8,7 +8,6 @@
 #include <clk.h>
 #include <dm.h>
 #include <errno.h>
-#include <fdtdec.h>
 #include <ns16550.h>
 #include <serial.h>
 #include <watchdog.h>
@@ -56,7 +55,7 @@ static inline void serial_out_shift(void *addr, int shift, int value)
 {
 #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
        outb(value, (ulong)addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) && !defined(CONFIG_SYS_BIG_ENDIAN)
+#elif defined(CONFIG_SYS_NS16550_MEM32) && defined(CONFIG_SYS_LITTLE_ENDIAN)
        out_le32(addr, value);
 #elif defined(CONFIG_SYS_NS16550_MEM32) && defined(CONFIG_SYS_BIG_ENDIAN)
        out_be32(addr, value);
@@ -73,7 +72,7 @@ static inline int serial_in_shift(void *addr, int shift)
 {
 #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
        return inb((ulong)addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) && !defined(CONFIG_SYS_BIG_ENDIAN)
+#elif defined(CONFIG_SYS_NS16550_MEM32) && defined(CONFIG_SYS_LITTLE_ENDIAN)
        return in_le32(addr);
 #elif defined(CONFIG_SYS_NS16550_MEM32) && defined(CONFIG_SYS_BIG_ENDIAN)
        return in_be32(addr);
@@ -175,21 +174,17 @@ void NS16550_init(NS16550_t com_port, int baud_divisor)
                ;
 
        serial_out(CONFIG_SYS_NS16550_IER, &com_port->ier);
-#if defined(CONFIG_OMAP) || defined(CONFIG_AM33XX) || \
-                       defined(CONFIG_TI81XX) || defined(CONFIG_AM43XX)
+#if defined(CONFIG_ARCH_OMAP2PLUS)
        serial_out(0x7, &com_port->mdr1);       /* mode select reset TL16C750*/
 #endif
        serial_out(UART_MCRVAL, &com_port->mcr);
        serial_out(ns16550_getfcr(com_port), &com_port->fcr);
        if (baud_divisor != -1)
                NS16550_setbrg(com_port, baud_divisor);
-#if defined(CONFIG_OMAP) || \
-       defined(CONFIG_AM33XX) || defined(CONFIG_SOC_DA8XX) || \
-       defined(CONFIG_TI81XX) || defined(CONFIG_AM43XX)
-
+#if defined(CONFIG_ARCH_OMAP2PLUS) || defined(CONFIG_SOC_DA8XX)
        /* /16 is proper to hit 115200 with 48MHz */
        serial_out(0, &com_port->mdr1);
-#endif /* CONFIG_OMAP */
+#endif
 #if defined(CONFIG_SOC_KEYSTONE)
        serial_out(UART_REG_VAL_PWREMU_MGMT_UART_ENABLE, &com_port->regC);
 #endif
@@ -246,17 +241,6 @@ int NS16550_tstc(NS16550_t com_port)
 
 #include <debug_uart.h>
 
-#define serial_dout(reg, value)        \
-       serial_out_shift((char *)com_port + \
-               ((char *)reg - (char *)com_port) * \
-                       (1 << CONFIG_DEBUG_UART_SHIFT), \
-               CONFIG_DEBUG_UART_SHIFT, value)
-#define serial_din(reg) \
-       serial_in_shift((char *)com_port + \
-               ((char *)reg - (char *)com_port) * \
-                       (1 << CONFIG_DEBUG_UART_SHIFT), \
-               CONFIG_DEBUG_UART_SHIFT)
-
 static inline void _debug_uart_init(void)
 {
        struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
@@ -293,6 +277,42 @@ DEBUG_UART_FUNCS
 
 #endif
 
+#ifdef CONFIG_DEBUG_UART_OMAP
+
+#include <debug_uart.h>
+
+static inline void _debug_uart_init(void)
+{
+       struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
+       int baud_divisor;
+
+       baud_divisor = ns16550_calc_divisor(com_port, CONFIG_DEBUG_UART_CLOCK,
+                                           CONFIG_BAUDRATE);
+       serial_dout(&com_port->ier, CONFIG_SYS_NS16550_IER);
+       serial_dout(&com_port->mdr1, 0x7);
+       serial_dout(&com_port->mcr, UART_MCRVAL);
+       serial_dout(&com_port->fcr, UART_FCR_DEFVAL);
+
+       serial_dout(&com_port->lcr, UART_LCR_BKSE | UART_LCRVAL);
+       serial_dout(&com_port->dll, baud_divisor & 0xff);
+       serial_dout(&com_port->dlm, (baud_divisor >> 8) & 0xff);
+       serial_dout(&com_port->lcr, UART_LCRVAL);
+       serial_dout(&com_port->mdr1, 0x0);
+}
+
+static inline void _debug_uart_putc(int ch)
+{
+       struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
+
+       while (!(serial_din(&com_port->lsr) & UART_LSR_THRE))
+               ;
+       serial_dout(&com_port->thr, ch);
+}
+
+DEBUG_UART_FUNCS
+
+#endif
+
 #ifdef CONFIG_DM_SERIAL
 static int ns16550_serial_putc(struct udevice *dev, const char ch)
 {
@@ -319,9 +339,9 @@ static int ns16550_serial_pending(struct udevice *dev, bool input)
        struct NS16550 *const com_port = dev_get_priv(dev);
 
        if (input)
-               return serial_in(&com_port->lsr) & UART_LSR_DR ? 1 : 0;
+               return (serial_in(&com_port->lsr) & UART_LSR_DR) ? 1 : 0;
        else
-               return serial_in(&com_port->lsr) & UART_LSR_THRE ? 0 : 1;
+               return (serial_in(&com_port->lsr) & UART_LSR_THRE) ? 0 : 1;
 }
 
 static int ns16550_serial_getc(struct udevice *dev)
@@ -374,7 +394,7 @@ int ns16550_serial_ofdata_to_platdata(struct udevice *dev)
        int err;
 
        /* try Processor Local Bus device first */
-       addr = dev_get_addr(dev);
+       addr = dev_read_addr(dev);
 #if defined(CONFIG_PCI) && defined(CONFIG_DM_PCI)
        if (addr == FDT_ADDR_T_NONE) {
                /* then try pci device */
@@ -413,10 +433,8 @@ int ns16550_serial_ofdata_to_platdata(struct udevice *dev)
        plat->base = (unsigned long)map_physmem(addr, 0, MAP_NOCACHE);
 #endif
 
-       plat->reg_offset = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
-                                    "reg-offset", 0);
-       plat->reg_shift = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
-                                        "reg-shift", 0);
+       plat->reg_offset = dev_read_u32_default(dev, "reg-offset", 0);
+       plat->reg_shift = dev_read_u32_default(dev, "reg-shift", 0);
 
        err = clk_get_by_index(dev, 0, &clk);
        if (!err) {
@@ -429,9 +447,8 @@ int ns16550_serial_ofdata_to_platdata(struct udevice *dev)
        }
 
        if (!plat->clock)
-               plat->clock = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
-                                            "clock-frequency",
-                                            CONFIG_SYS_NS16550_CLK);
+               plat->clock = dev_read_u32_default(dev, "clock-frequency",
+                                                  CONFIG_SYS_NS16550_CLK);
        if (!plat->clock) {
                debug("ns16550 clock not defined\n");
                return -EINVAL;