[U-Boot-Users] [PATCH 5/7] serial: add s3c64xx serial driver

2008-07-31 Thread Guennadi Liakhovetski
Ported from u-boot-1.1.6 driver by Samsung.

Signed-off-by: Guennadi Liakhovetski [EMAIL PROTECTED]
---
 drivers/serial/Makefile  |1 +
 drivers/serial/s3c64xx.c |  189 ++
 2 files changed, 190 insertions(+), 0 deletions(-)
 create mode 100644 drivers/serial/s3c64xx.c

diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index c9e797e..70fe638 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -36,6 +36,7 @@ COBJS-y += serial_pl010.o
 COBJS-y += serial_pl011.o
 COBJS-y += serial_xuartlite.o
 COBJS-y += serial_sh.o
+COBJS-$(CONFIG_S3C64XX) += s3c64xx.o
 COBJS-y += usbtty.o
 
 COBJS  := $(COBJS-y)
diff --git a/drivers/serial/s3c64xx.c b/drivers/serial/s3c64xx.c
new file mode 100644
index 000..d7e9d01
--- /dev/null
+++ b/drivers/serial/s3c64xx.c
@@ -0,0 +1,189 @@
+/*
+ * (C) Copyright 2002
+ * Gary Jennejohn, DENX Software Engineering, [EMAIL PROTECTED]
+ *
+ * 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
+ *
+ */
+
+#include common.h
+
+#include s3c6400.h
+
+#ifdef CONFIG_SERIAL1
+#define UART_NRS3C64XX_UART0
+
+#elif defined(CONFIG_SERIAL2)
+#define UART_NRS3C64XX_UART1
+
+#elif defined(CONFIG_SERIAL3)
+#define UART_NRS3C64XX_UART2
+
+#else
+#error Bad: you didn't configure serial ...
+#endif
+
+#define barrier() asm volatile( ::: memory)
+
+/* See table in 31.6.11 */
+static const int udivslot[] = {
+   0,
+   0x0080,
+   0x0808,
+   0x0888,
+   0x,
+   0x4924,
+   0x4a52,
+   0x54aa,
+   0x,
+   0xd555,
+   0xd5d5,
+   0xddd5,
+   0x,
+   0xdfdd,
+   0xdfdf,
+   0xffdf,
+};
+
+void serial_setbrg(void)
+{
+   DECLARE_GLOBAL_DATA_PTR;
+   S3C64XX_UART *const uart = S3C64XX_GetBase_UART(UART_NR);
+   u32 reg, pclk_ratio = get_PCLK() / gd-baudrate;
+   int i;
+
+   /* PCLK / (16 * baudrate) - 1 */
+   reg = pclk_ratio / 16 - 1;
+   i = pclk_ratio - (reg + 1) * 16;
+
+   uart-UBRDIV = reg;
+   uart-UDIVSLOT = udivslot[i];
+
+   for (i = 0; i  100; i++)
+   barrier();
+}
+
+/*
+ * Initialise the serial port with the given baudrate. The settings
+ * are always 8 data bits, no parity, 1 stop bit, no start bits.
+ *
+ */
+int serial_init(void)
+{
+   S3C64XX_UART *const uart = S3C64XX_GetBase_UART(UART_NR);
+
+   /* reset and enable FIFOs, set triggers to the maximum */
+   uart-UFCON = 0xff;
+   uart-UMCON = 0;
+   /* 8N1 */
+   uart-ULCON = 3;
+   /* No interrupts, no DMA, pure polling */
+   uart-UCON = 5;
+
+   serial_setbrg();
+
+   return 0;
+}
+
+/*
+ * Read a single byte from the serial port. Returns 1 on success, 0
+ * otherwise. When the function is succesfull, the character read is
+ * written into its argument c.
+ */
+int serial_getc(void)
+{
+   S3C64XX_UART *const uart = S3C64XX_GetBase_UART(UART_NR);
+
+   /* wait for character to arrive */
+   while (!(uart-UTRSTAT  0x1));
+
+   return uart-URXH  0xff;
+}
+
+#ifdef CONFIG_HWFLOW
+static int hwflow = 0; /* turned off by default */
+int hwflow_onoff(int on)
+{
+   switch (on) {
+   case 0:
+   default:
+   break;  /* return current */
+   case 1:
+   hwflow = 1; /* turn on */
+   break;
+   case -1:
+   hwflow = 0; /* turn off */
+   break;
+   }
+   return hwflow;
+}
+#endif
+
+#ifdef CONFIG_MODEM_SUPPORT
+static int be_quiet;
+void disable_putc(void)
+{
+   be_quiet = 1;
+}
+
+void enable_putc(void)
+{
+   be_quiet = 0;
+}
+#endif
+
+
+/*
+ * Output a single byte to the serial port.
+ */
+void serial_putc(const char c)
+{
+   S3C64XX_UART *const uart = S3C64XX_GetBase_UART(UART_NR);
+
+#ifdef CONFIG_MODEM_SUPPORT
+   if (be_quiet)
+   return;
+#endif
+
+   /* wait for room in the tx FIFO */
+   while (!(uart-UTRSTAT  0x2));
+
+#ifdef CONFIG_HWFLOW
+   /* Wait for CTS up */
+   while (hwflow  !(uart-UMSTAT  0x1));
+#endif
+
+   uart-UTXH = c;
+
+   /* If \n, also do \r */
+   if (c == '\n')
+   serial_putc('\r');
+}
+
+/*
+ * Test whether a character is in the RX buffer
+ */
+int serial_tstc(void)
+{
+   S3C64XX_UART 

Re: [U-Boot-Users] [PATCH 5/7] serial: add s3c64xx serial driver

2008-07-31 Thread Wolfgang Denk
In message [EMAIL PROTECTED] you wrote:
 Ported from u-boot-1.1.6 driver by Samsung.
 
 Signed-off-by: Guennadi Liakhovetski [EMAIL PROTECTED]

 --- a/drivers/serial/Makefile
 +++ b/drivers/serial/Makefile
 @@ -36,6 +36,7 @@ COBJS-y += serial_pl010.o
  COBJS-y += serial_pl011.o
  COBJS-y += serial_xuartlite.o
  COBJS-y += serial_sh.o
 +COBJS-$(CONFIG_S3C64XX) += s3c64xx.o
  COBJS-y += usbtty.o

Please keep the list sorted.


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH, MD: Wolfgang Denk  Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [EMAIL PROTECTED]
To be a winner, all you need to give is all you have.

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
U-Boot-Users mailing list
U-Boot-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/u-boot-users


Re: [U-Boot-Users] [PATCH 5/7] serial: add s3c64xx serial driver

2008-07-31 Thread Jean-Christophe PLAGNIOL-VILLARD
On 12:54 Thu 31 Jul , Guennadi Liakhovetski wrote:
 Ported from u-boot-1.1.6 driver by Samsung.
 
 Signed-off-by: Guennadi Liakhovetski [EMAIL PROTECTED]
 ---
  drivers/serial/Makefile  |1 +
  drivers/serial/s3c64xx.c |  189 
 ++
  2 files changed, 190 insertions(+), 0 deletions(-)
  create mode 100644 drivers/serial/s3c64xx.c
 
 diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
 index c9e797e..70fe638 100644
 --- a/drivers/serial/Makefile
 +++ b/drivers/serial/Makefile
 @@ -36,6 +36,7 @@ COBJS-y += serial_pl010.o
  COBJS-y += serial_pl011.o
  COBJS-y += serial_xuartlite.o
  COBJS-y += serial_sh.o
 +COBJS-$(CONFIG_S3C64XX) += s3c64xx.o
  COBJS-y += usbtty.o
  
  COBJS:= $(COBJS-y)
 diff --git a/drivers/serial/s3c64xx.c b/drivers/serial/s3c64xx.c
 new file mode 100644
 index 000..d7e9d01
 --- /dev/null
 +++ b/drivers/serial/s3c64xx.c
 @@ -0,0 +1,189 @@
 +/*
 + * (C) Copyright 2002
 + * Gary Jennejohn, DENX Software Engineering, [EMAIL PROTECTED]
 + *
 + * 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
 + *
 + */
 +
 +#include common.h
 +
 +#include s3c6400.h
 +
 +#ifdef CONFIG_SERIAL1
 +#define UART_NR  S3C64XX_UART0
 +
 +#elif defined(CONFIG_SERIAL2)
 +#define UART_NR  S3C64XX_UART1
 +
 +#elif defined(CONFIG_SERIAL3)
 +#define UART_NR  S3C64XX_UART2
 +
 +#else
 +#error Bad: you didn't configure serial ...
 +#endif
 +
 +#define barrier() asm volatile( ::: memory)
 +
 +/* See table in 31.6.11 */
 +static const int udivslot[] = {
 + 0,
 + 0x0080,
 + 0x0808,
 + 0x0888,
 + 0x,
 + 0x4924,
 + 0x4a52,
 + 0x54aa,
 + 0x,
 + 0xd555,
 + 0xd5d5,
 + 0xddd5,
 + 0x,
 + 0xdfdd,
 + 0xdfdf,
 + 0xffdf,
 +};
 +
 +void serial_setbrg(void)
 +{
 + DECLARE_GLOBAL_DATA_PTR;
 + S3C64XX_UART *const uart = S3C64XX_GetBase_UART(UART_NR);
 + u32 reg, pclk_ratio = get_PCLK() / gd-baudrate;
 + int i;
 +
 + /* PCLK / (16 * baudrate) - 1 */
 + reg = pclk_ratio / 16 - 1;
 + i = pclk_ratio - (reg + 1) * 16;
 +
 + uart-UBRDIV = reg;
 + uart-UDIVSLOT = udivslot[i];
 +
 + for (i = 0; i  100; i++)
 + barrier();
 +}
 +
 +/*
 + * Initialise the serial port with the given baudrate. The settings
 + * are always 8 data bits, no parity, 1 stop bit, no start bits.
 + *
 + */
 +int serial_init(void)
 +{
 + S3C64XX_UART *const uart = S3C64XX_GetBase_UART(UART_NR);
please do not use UPPERCASE var name and function  co
 +
 + /* reset and enable FIFOs, set triggers to the maximum */
 + uart-UFCON = 0xff;
 + uart-UMCON = 0;
 + /* 8N1 */
 + uart-ULCON = 3;
 + /* No interrupts, no DMA, pure polling */
 + uart-UCON = 5;
 +
 + serial_setbrg();
 +
 + return 0;
 +}
 +
 +/*
 + * Read a single byte from the serial port. Returns 1 on success, 0
 + * otherwise. When the function is succesfull, the character read is
 + * written into its argument c.
 + */
 +int serial_getc(void)
 +{
 + S3C64XX_UART *const uart = S3C64XX_GetBase_UART(UART_NR);
 +
 + /* wait for character to arrive */
 + while (!(uart-UTRSTAT  0x1));
 +
 + return uart-URXH  0xff;
 +}
 +
 +#ifdef CONFIG_HWFLOW
 +static int hwflow = 0;   /* turned off by default */
 +int hwflow_onoff(int on)
 +{
 + switch (on) {
 + case 0:
 + default:
 + break;  /* return current */
IMHO it's weird to have the default at top
 + case 1:
 + hwflow = 1; /* turn on */
 + break;
 + case -1:
 + hwflow = 0; /* turn off */
 + break;
 + }
 + return hwflow;
 +}
 +#endif
 +

Best Regards,
J.

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
U-Boot-Users mailing list
U-Boot-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/u-boot-users