dm: Expand and complete Kconfig in drivers/
[oweals/u-boot.git] / drivers / serial / serial_uniphier.c
index 9114b3ed6002a1a0d9e3c6303ad07993060b07f9..e8a1608b9988c193c1c860795730ecced5b4c107 100644 (file)
@@ -5,12 +5,13 @@
  * SPDX-License-Identifier:    GPL-2.0+
  */
 
-#include <common.h>
+#include <linux/serial_reg.h>
 #include <asm/io.h>
 #include <asm/errno.h>
 #include <dm/device.h>
 #include <dm/platform_data/serial-uniphier.h>
 #include <serial.h>
+#include <fdtdec.h>
 
 #define UART_REG(x)                                    \
        u8 x;                                           \
@@ -37,17 +38,6 @@ struct uniphier_serial {
 
 #define thr rbr
 
-/*
- * These are the definitions for the Line Control Register
- */
-#define UART_LCR_WLS_8 0x03            /* 8 bit character length */
-
-/*
- * These are the definitions for the Line Status Register
- */
-#define UART_LSR_DR    0x01            /* Data ready */
-#define UART_LSR_THRE  0x20            /* Xmit holding register empty */
-
 struct uniphier_serial_private_data {
        struct uniphier_serial __iomem *membase;
 };
@@ -55,14 +45,14 @@ struct uniphier_serial_private_data {
 #define uniphier_serial_port(dev)      \
        ((struct uniphier_serial_private_data *)dev_get_priv(dev))->membase
 
-int uniphier_serial_setbrg(struct udevice *dev, int baudrate)
+static int uniphier_serial_setbrg(struct udevice *dev, int baudrate)
 {
        struct uniphier_serial_platform_data *plat = dev_get_platdata(dev);
        struct uniphier_serial __iomem *port = uniphier_serial_port(dev);
        const unsigned int mode_x_div = 16;
        unsigned int divisor;
 
-       writeb(UART_LCR_WLS_8, &port->lcr);
+       writeb(UART_LCR_WLEN8, &port->lcr);
 
        divisor = DIV_ROUND_CLOSEST(plat->uartclk, mode_x_div * baudrate);
 
@@ -93,7 +83,17 @@ static int uniphier_serial_putc(struct udevice *dev, const char c)
        return 0;
 }
 
-int uniphier_serial_probe(struct udevice *dev)
+static int uniphier_serial_pending(struct udevice *dev, bool input)
+{
+       struct uniphier_serial __iomem *port = uniphier_serial_port(dev);
+
+       if (input)
+               return readb(&port->lsr) & UART_LSR_DR;
+       else
+               return !(readb(&port->lsr) & UART_LSR_THRE);
+}
+
+static int uniphier_serial_probe(struct udevice *dev)
 {
        struct uniphier_serial_private_data *priv = dev_get_priv(dev);
        struct uniphier_serial_platform_data *plat = dev_get_platdata(dev);
@@ -106,7 +106,7 @@ int uniphier_serial_probe(struct udevice *dev)
        return 0;
 }
 
-int uniphier_serial_remove(struct udevice *dev)
+static int uniphier_serial_remove(struct udevice *dev)
 {
        unmap_sysmem(uniphier_serial_port(dev));
 
@@ -114,19 +114,21 @@ int uniphier_serial_remove(struct udevice *dev)
 }
 
 #ifdef CONFIG_OF_CONTROL
-static const struct udevice_id uniphier_uart_of_match = {
-       { .compatible = "panasonic,uniphier-uart"},
+static const struct udevice_id uniphier_uart_of_match[] = {
+       { .compatible = "panasonic,uniphier-uart" },
        {},
 };
 
 static int uniphier_serial_ofdata_to_platdata(struct udevice *dev)
 {
-       /*
-        * TODO: Masahiro Yamada (yamada.m@jp.panasonic.com)
-        *
-        * Implement conversion code from DTB to platform data
-        * when supporting CONFIG_OF_CONTROL on UniPhir platform.
-        */
+       struct uniphier_serial_platform_data *plat = dev_get_platdata(dev);
+       DECLARE_GLOBAL_DATA_PTR;
+
+       plat->base = fdtdec_get_addr(gd->fdt_blob, dev->of_offset, "reg");
+       plat->uartclk = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+                                      "clock-frequency", 0);
+
+       return 0;
 }
 #endif
 
@@ -134,6 +136,7 @@ static const struct dm_serial_ops uniphier_serial_ops = {
        .setbrg = uniphier_serial_setbrg,
        .getc = uniphier_serial_getc,
        .putc = uniphier_serial_putc,
+       .pending = uniphier_serial_pending,
 };
 
 U_BOOT_DRIVER(uniphier_serial) = {