]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/serial/lpc32xx_hsuart.c
Net: macb: reset GBE bit when fallback checking
[karo-tx-uboot.git] / drivers / serial / lpc32xx_hsuart.c
index 8ce3382d8690aa9c648ecada2852f0857c23cd5b..c8926a8945ac6c84e81ff651a18ed0b2eb8566ef 100644 (file)
@@ -1,20 +1,7 @@
 /*
  * Copyright (C) 2011 Vladimir Zapolskiy <vz@mleia.com>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <asm/arch/clk.h>
 #include <asm/arch/uart.h>
 #include <asm/io.h>
+#include <serial.h>
+#include <linux/compiler.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
 static struct hsuart_regs *hsuart = (struct hsuart_regs *)HS_UART_BASE;
 
-static void lpc32xx_hsuart_set_baudrate(void)
+static void lpc32xx_serial_setbrg(void)
 {
        u32 div;
 
@@ -39,7 +28,7 @@ static void lpc32xx_hsuart_set_baudrate(void)
        writel(div, &hsuart->rate);
 }
 
-static int lpc32xx_hsuart_getc(void)
+static int lpc32xx_serial_getc(void)
 {
        while (!(readl(&hsuart->level) & HSUART_LEVEL_RX))
                /* NOP */;
@@ -47,8 +36,11 @@ static int lpc32xx_hsuart_getc(void)
        return readl(&hsuart->rx) & HSUART_RX_DATA;
 }
 
-static void lpc32xx_hsuart_putc(const char c)
+static void lpc32xx_serial_putc(const char c)
 {
+       if (c == '\n')
+               serial_putc('\r');
+
        writel(c, &hsuart->tx);
 
        /* Wait for character to be sent */
@@ -56,7 +48,7 @@ static void lpc32xx_hsuart_putc(const char c)
                /* NOP */;
 }
 
-static int lpc32xx_hsuart_tstc(void)
+static int lpc32xx_serial_tstc(void)
 {
        if (readl(&hsuart->level) & HSUART_LEVEL_RX)
                return 1;
@@ -64,49 +56,34 @@ static int lpc32xx_hsuart_tstc(void)
        return 0;
 }
 
-static void lpc32xx_hsuart_init(void)
+static int lpc32xx_serial_init(void)
 {
-       lpc32xx_hsuart_set_baudrate();
+       lpc32xx_serial_setbrg();
 
        /* Disable hardware RTS and CTS flow control, set up RX and TX FIFO */
        writel(HSUART_CTRL_TMO_16 | HSUART_CTRL_HSU_OFFSET(20) |
               HSUART_CTRL_HSU_RX_TRIG_32 | HSUART_CTRL_HSU_TX_TRIG_0,
               &hsuart->ctrl);
+       return 0;
 }
 
-void serial_setbrg(void)
-{
-       return lpc32xx_hsuart_set_baudrate();
-}
-
-void serial_putc(const char c)
-{
-       lpc32xx_hsuart_putc(c);
-
-       /* If \n, also do \r */
-       if (c == '\n')
-               lpc32xx_hsuart_putc('\r');
-}
-
-int serial_getc(void)
-{
-       return lpc32xx_hsuart_getc();
-}
-
-void serial_puts(const char *s)
-{
-       while (*s)
-               serial_putc(*s++);
-}
-
-int serial_tstc(void)
+static struct serial_device lpc32xx_serial_drv = {
+       .name   = "lpc32xx_serial",
+       .start  = lpc32xx_serial_init,
+       .stop   = NULL,
+       .setbrg = lpc32xx_serial_setbrg,
+       .putc   = lpc32xx_serial_putc,
+       .puts   = default_serial_puts,
+       .getc   = lpc32xx_serial_getc,
+       .tstc   = lpc32xx_serial_tstc,
+};
+
+void lpc32xx_serial_initialize(void)
 {
-       return lpc32xx_hsuart_tstc();
+       serial_register(&lpc32xx_serial_drv);
 }
 
-int serial_init(void)
+__weak struct serial_device *default_serial_console(void)
 {
-       lpc32xx_hsuart_init();
-
-       return 0;
+       return &lpc32xx_serial_drv;
 }