* [RFC] ARM/serial: add a DCC based console driver
@ 2012-03-13 13:16 Juergen Beisert
2012-03-13 13:24 ` Sascha Hauer
2012-03-13 13:25 ` Juergen Beisert
0 siblings, 2 replies; 4+ messages in thread
From: Juergen Beisert @ 2012-03-13 13:16 UTC (permalink / raw)
To: barebox
Hi,
please find attached an DCC based driver for Barebox to be able to get early
boot messages. It acts as a regular serial console and can be used in
conjunction with a JTAG debugger. This is really useful when no serial
console is available (don't ask why...) and the bootloader hangs prior it can
enable a network based console.
One issue is still present and I need some hints what might be going wrong
here:
Sending chars via DCC blocks for ever, when I'm using a simple
while loop waiting for the DCC_OUTPUT_BUSY to be cleared. After adding a
timeout loop I receive every other char at the JTAG side. When I write the
char to the DCC even if it timeout, I receive *every* char. Only some chars
are lost when I reduce the timeout value below 750 us.
Any idea? I checked the kernel source, but they doing the same: Waiting for
the DCC_OUTPUT_BUSY to be cleared and timeout after a specific amount of
loops (but without writing the char in this case).
Comments are welcome.
commit 809d26930dc734faad2a4ac4cc5126487a8af261
Author: Juergen Beisert <jbe@pengutronix.de>
Date: Tue Mar 13 13:01:22 2012 +0100
ARM/serial: add a DCC based console driver
Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 9c7f9cf..a71efcf 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -103,4 +103,10 @@ config DRIVER_SERIAL_DUMMY
an input character. Its sole purpose is to provide a regular console
to work with the netconsole.
+config DRIVER_SERIAL_DCC
+ bool "DCC serial driver"
+ help
+ This is a DCC based console driver. DCC is an ARM core internal
+ EmbeddedICE feature and can be used with a JTAG debugger.
+
endmenu
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index 0e89c01..91412bb 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -20,3 +20,4 @@ obj-$(CONFIG_DRIVER_SERIAL_ALTERA) += serial_altera.o
obj-$(CONFIG_DRIVER_SERIAL_ALTERA_JTAG) += serial_altera_jtag.o
obj-$(CONFIG_DRIVER_SERIAL_PXA) += serial_pxa.o
obj-$(CONFIG_DRIVER_SERIAL_DUMMY) += serial_dummy.o
+obj-$(CONFIG_DRIVER_SERIAL_DCC) += serial_dcc.o
diff --git a/drivers/serial/serial_dcc.c b/drivers/serial/serial_dcc.c
new file mode 100644
index 0000000..a6e1a91
--- /dev/null
+++ b/drivers/serial/serial_dcc.c
@@ -0,0 +1,177 @@
+/*
+ * (c) 2012 Juergen Beisert <j.beisert@pengutronix.de>
+ *
+ * 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.
+ *
+ */
+
+#include <common.h>
+#include <driver.h>
+#include <init.h>
+#include <malloc.h>
+#include <clock.h>
+
+#if defined(CONFIG_CPU_32v4T) || defined(CONFIG_CPU_32v5)
+
+#define DCC_OUTPUT_BUSY (1 << 1)
+#define DCC_INPUT_READY (1 << 0)
+
+static u32 read_dcc(void)
+{
+ u32 c;
+
+ __asm__(
+ "mrc p14, 0, %0, c1, c0\n"
+ : "=r" (c));
+
+ return c;
+}
+
+static void write_dcc(u32 c)
+{
+ __asm__(
+ "mcr p14, 0, %0, c1, c0, 0\n"
+ :
+ : "r" (c));
+}
+
+static u32 poll_dcc(void)
+{
+ u32 ret;
+
+ __asm__(
+ "mrc p14, 0, %0, c0, c0, 0\n"
+ : "=r" (ret));
+
+ return ret;
+}
+#endif /* ARMv4 or ARMv5 */
+
+#if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V7)
+
+#define DCC_OUTPUT_BUSY (1 << 29)
+#define DCC_INPUT_READY (1 << 28) /* FIXME */
+
+static u32 read_dcc(void)
+{
+ u32 c;
+
+ __asm__(
+ "mrc p14, 0, %0, c0, c5\n" /* to be checked */
+ : "=r" (c));
+ return c;
+}
+
+static void write_dcc(u32 c)
+{
+ __asm__(
+ "mcr p14, 0, %0, c0, c5, 0\n"
+ :
+ : "r" (c));
+}
+
+static u32 poll_dcc(void)
+{
+ u32 ret;
+
+ __asm__(
+ "mrc p14, 0, %0, c0, c1, 0\n"
+ : "=r" (ret));
+ return ret;
+}
+#endif
+
+struct dcc_uart {
+ struct console_device cdev;
+};
+
+static int dcc_serial_setbaudrate(struct console_device *cdev, int baudrate)
+{
+ /* return happy */
+ return 0;
+}
+
+static void dcc_serial_putc(struct console_device *cdev, char c)
+{
+ uint64_t start = get_time_ns();
+ uint64_t toffs = 750 * 1000;
+
+ do {
+ if (!(poll_dcc() & DCC_OUTPUT_BUSY)) {
+ write_dcc(c);
+ break;
+ }
+ } while (!is_timeout(start, toffs));
+
+ write_dcc(c); /* FIXME: the char gets not lost. It works, but why? */
+}
+
+static int dcc_serial_tstc(struct console_device *cdev)
+{
+ if (poll_dcc() & DCC_INPUT_READY)
+ return 1;
+ return 0; /* nothing */
+}
+
+static int dcc_serial_getc(struct console_device *cdev)
+{
+ return read_dcc();
+}
+
+static void dcc_serial_flush(struct console_device *cdev)
+{
+ while (poll_dcc() & DCC_OUTPUT_BUSY)
+ ;
+}
+
+static int dcc_serial_probe(struct device_d *dev)
+{
+ struct dcc_uart *priv;
+ struct console_device *cdev;
+
+ priv = xzalloc(sizeof(struct dcc_uart));
+ cdev = &priv->cdev;
+ dev->priv = priv;
+ cdev->dev = dev;
+ cdev->f_caps = CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR;
+ cdev->tstc = dcc_serial_tstc;
+ cdev->putc = dcc_serial_putc;
+ cdev->getc = dcc_serial_getc;
+ cdev->flush = dcc_serial_flush;
+ cdev->setbrg = dcc_serial_setbaudrate;
+
+ /* Enable UART */
+ console_register(cdev);
+
+ return 0;
+}
+
+static void dcc_serial_remove(struct device_d *dev)
+{
+ struct dcc_uart *priv= dev->priv;
+
+ console_unregister(&priv->cdev);
+ free(priv);
+}
+
+static struct driver_d dcc_serial_driver = {
+ .name = "dcc_serial",
+ .probe = dcc_serial_probe,
+ .remove = dcc_serial_remove,
+};
+
+static int dcc_serial_init(void)
+{
+ register_driver(&dcc_serial_driver);
+ return 0;
+}
+
+console_initcall(dcc_serial_init);
jbe
--
Pengutronix e.K. | Juergen Beisert |
Linux Solutions for Science and Industry | http://www.pengutronix.de/ |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC] ARM/serial: add a DCC based console driver
2012-03-13 13:16 [RFC] ARM/serial: add a DCC based console driver Juergen Beisert
@ 2012-03-13 13:24 ` Sascha Hauer
2012-03-13 13:32 ` Juergen Beisert
2012-03-13 13:25 ` Juergen Beisert
1 sibling, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2012-03-13 13:24 UTC (permalink / raw)
To: Juergen Beisert; +Cc: barebox
On Tue, Mar 13, 2012 at 02:16:46PM +0100, Juergen Beisert wrote:
> Hi,
>
> please find attached an DCC based driver for Barebox to be able to get early
> boot messages. It acts as a regular serial console and can be used in
> conjunction with a JTAG debugger. This is really useful when no serial
> console is available (don't ask why...) and the bootloader hangs prior it can
> enable a network based console.
>
> One issue is still present and I need some hints what might be going wrong
> here:
>
> Sending chars via DCC blocks for ever, when I'm using a simple
> while loop waiting for the DCC_OUTPUT_BUSY to be cleared. After adding a
> timeout loop I receive every other char at the JTAG side. When I write the
> char to the DCC even if it timeout, I receive *every* char. Only some chars
> are lost when I reduce the timeout value below 750 us.
> Any idea? I checked the kernel source, but they doing the same: Waiting for
> the DCC_OUTPUT_BUSY to be cleared and timeout after a specific amount of
> loops (but without writing the char in this case).
>
> Comments are welcome.
You are probably not aware that we already have such a driver in
drivers/serial/arm_dcc.c.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC] ARM/serial: add a DCC based console driver
2012-03-13 13:16 [RFC] ARM/serial: add a DCC based console driver Juergen Beisert
2012-03-13 13:24 ` Sascha Hauer
@ 2012-03-13 13:25 ` Juergen Beisert
1 sibling, 0 replies; 4+ messages in thread
From: Juergen Beisert @ 2012-03-13 13:25 UTC (permalink / raw)
To: barebox
Myself wrote:
> [...]
> Sending chars via DCC blocks for ever, when I'm using a simple
> while loop waiting for the DCC_OUTPUT_BUSY to be cleared. After adding a
> timeout loop I receive every other char at the JTAG side. When I write the
> char to the DCC even if it timeout, I receive *every* char. Only some chars
> are lost when I reduce the timeout value below 750 us.
> Any idea? I checked the kernel source, but they doing the same: Waiting for
> the DCC_OUTPUT_BUSY to be cleared and timeout after a specific amount of
> loops (but without writing the char in this case).
> [...]
Forget about that. The dcc_serial_putc() is broken in this patch. My ARMv5
*always* signals a DCC_OUTPUT_BUSY. If I ignore this bit and just wait about
750 µs between the chars it works as expected. Still have to find out, why it
always signals a DCC_OUTPUT_BUSY...
jbe
--
Pengutronix e.K. | Juergen Beisert |
Linux Solutions for Science and Industry | http://www.pengutronix.de/ |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC] ARM/serial: add a DCC based console driver
2012-03-13 13:24 ` Sascha Hauer
@ 2012-03-13 13:32 ` Juergen Beisert
0 siblings, 0 replies; 4+ messages in thread
From: Juergen Beisert @ 2012-03-13 13:32 UTC (permalink / raw)
To: barebox
Sascha Hauer wrote:
> [...]
> > Comments are welcome.
>
> You are probably not aware that we already have such a driver in
> drivers/serial/arm_dcc.c.
Ups, you are right. :)
jbe
--
Pengutronix e.K. | Juergen Beisert |
Linux Solutions for Science and Industry | Phone: +49-5121-206917-5128 |
Vertretung Sued/Muenchen, Germany | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de/ |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-03-13 13:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-13 13:16 [RFC] ARM/serial: add a DCC based console driver Juergen Beisert
2012-03-13 13:24 ` Sascha Hauer
2012-03-13 13:32 ` Juergen Beisert
2012-03-13 13:25 ` Juergen Beisert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox