]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/serial/serial_sh.c
Merge branch 'master' of git://git.denx.de/u-boot-arm
[karo-tx-uboot.git] / drivers / serial / serial_sh.c
index bcf246854f93f62c1b35d5f4b140ce7ab0a51e93..7c1f27137615faa4a56f0b40f567c49a0ff73378 100644 (file)
@@ -1,21 +1,10 @@
 /*
  * SuperH SCIF device driver.
+ * Copyright (C) 2013  Renesas Electronics Corporation
  * Copyright (C) 2007,2008,2010 Nobuhiro Iwamatsu
  * Copyright (C) 2002 - 2008  Paul Mundt
  *
- * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -60,7 +49,15 @@ static struct uart_port sh_sci = {
 static void sh_serial_setbrg(void)
 {
        DECLARE_GLOBAL_DATA_PTR;
-       sci_out(&sh_sci, SCBRR, SCBRR_VALUE(gd->baudrate, CONFIG_SYS_CLK_FREQ));
+#ifdef CONFIG_SCIF_USE_EXT_CLK
+       unsigned short dl = DL_VALUE(gd->baudrate, CONFIG_SH_SCIF_CLK_FREQ);
+       sci_out(&sh_sci, DL, dl);
+       /* Need wait: Clock * 1/dl \e$B!_\e(B 1/16 */
+       udelay((1000000 * dl * 16 / CONFIG_SYS_CLK_FREQ) * 1000 + 1);
+#else
+       sci_out(&sh_sci, SCBRR,
+               SCBRR_VALUE(gd->baudrate, CONFIG_SH_SCIF_CLK_FREQ));
+#endif
 }
 
 static int sh_serial_init(void)
@@ -117,7 +114,15 @@ static int serial_rx_fifo_level(void)
        return scif_rxfill(&sh_sci);
 }
 
-void serial_raw_putc(const char c)
+static void handle_error(void)
+{
+       sci_in(&sh_sci, SCxSR);
+       sci_out(&sh_sci, SCxSR, SCxSR_ERROR_CLEAR(&sh_sci));
+       sci_in(&sh_sci, SCLSR);
+       sci_out(&sh_sci, SCLSR, 0x00);
+}
+
+static void serial_raw_putc(const char c)
 {
        while (1) {
                /* Tx fifo is empty */
@@ -136,27 +141,18 @@ static void sh_serial_putc(const char c)
        serial_raw_putc(c);
 }
 
-static void sh_serial_puts(const char *s)
-{
-       char c;
-       while ((c = *s++) != 0)
-               serial_putc(c);
-}
-
 static int sh_serial_tstc(void)
 {
+       if (sci_in(&sh_sci, SCxSR) & SCIF_ERRORS) {
+               handle_error();
+               return 0;
+       }
+
        return serial_rx_fifo_level() ? 1 : 0;
 }
 
-void handle_error(void)
-{
-       sci_in(&sh_sci, SCxSR);
-       sci_out(&sh_sci, SCxSR, SCxSR_ERROR_CLEAR(&sh_sci));
-       sci_in(&sh_sci, SCLSR);
-       sci_out(&sh_sci, SCLSR, 0x00);
-}
 
-int serial_getc_check(void)
+static int serial_getc_check(void)
 {
        unsigned short status;
 
@@ -190,14 +186,13 @@ static int sh_serial_getc(void)
        return ch;
 }
 
-#ifdef CONFIG_SERIAL_MULTI
 static struct serial_device sh_serial_drv = {
        .name   = "sh_serial",
        .start  = sh_serial_init,
        .stop   = NULL,
        .setbrg = sh_serial_setbrg,
        .putc   = sh_serial_putc,
-       .puts   = sh_serial_puts,
+       .puts   = default_serial_puts,
        .getc   = sh_serial_getc,
        .tstc   = sh_serial_tstc,
 };
@@ -211,34 +206,3 @@ __weak struct serial_device *default_serial_console(void)
 {
        return &sh_serial_drv;
 }
-#else
-int serial_init(void)
-{
-       return sh_serial_init();
-}
-
-void serial_setbrg(void)
-{
-       sh_serial_setbrg();
-}
-
-void serial_putc(const char c)
-{
-       sh_serial_putc(c);
-}
-
-void serial_puts(const char *s)
-{
-       sh_serial_puts(s);
-}
-
-int serial_getc(void)
-{
-       return sh_serial_getc();
-}
-
-int serial_tstc(void)
-{
-       return sh_serial_tstc();
-}
-#endif