[U-Boot] [PATCH v2 3/3] sandbox: Add serial test

Patrice Chotard patrice.chotard at st.com
Wed Aug 1 15:58:53 UTC 2018


Signed-off-by: Patrice Chotard <patrice.chotard at st.com>
---

Changes in v2:
  - Add sandbox serial test

 drivers/serial/sandbox.c | 14 ++++++++++++++
 include/common.h         |  1 +
 test/dm/Makefile         |  1 +
 test/dm/serial.c         | 26 ++++++++++++++++++++++++++
 4 files changed, 42 insertions(+)
 create mode 100644 test/dm/serial.c

diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c
index a60dabe58835..94b4fdfb1714 100644
--- a/drivers/serial/sandbox.c
+++ b/drivers/serial/sandbox.c
@@ -143,6 +143,19 @@ static int sandbox_serial_getc(struct udevice *dev)
 	return result;
 }
 
+static int sandbox_serial_setconfig(struct udevice *dev, uint serial_config)
+{
+	u8 parity = SERIAL_GET_PARITY(serial_config);
+	u8 bits = SERIAL_GET_BITS(serial_config);
+	u8 stop = SERIAL_GET_STOP(serial_config);
+
+	if (bits != SERIAL_8_BITS || stop != SERIAL_ONE_STOP ||
+	    parity != SERIAL_PAR_NONE)
+		return -ENOTSUPP; /* not supported in driver*/
+
+	return 0;
+}
+
 static const char * const ansi_colour[] = {
 	"black", "red", "green", "yellow", "blue", "megenta", "cyan",
 	"white",
@@ -173,6 +186,7 @@ static const struct dm_serial_ops sandbox_serial_ops = {
 	.putc = sandbox_serial_putc,
 	.pending = sandbox_serial_pending,
 	.getc = sandbox_serial_getc,
+	.setconfig = sandbox_serial_setconfig,
 };
 
 static const struct udevice_id sandbox_serial_ids[] = {
diff --git a/include/common.h b/include/common.h
index 940161f1758b..5c952af5e319 100644
--- a/include/common.h
+++ b/include/common.h
@@ -359,6 +359,7 @@ void	serial_putc_raw(const char);
 void	serial_puts   (const char *);
 int	serial_getc   (void);
 int	serial_tstc   (void);
+int	serial_setconfig(uint config);
 
 /* $(CPU)/speed.c */
 int	get_clocks (void);
diff --git a/test/dm/Makefile b/test/dm/Makefile
index d2ed96c61533..97517c7f825e 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -44,4 +44,5 @@ obj-$(CONFIG_DM_VIDEO) += video.o
 obj-$(CONFIG_ADC) += adc.o
 obj-$(CONFIG_SPMI) += spmi.o
 obj-$(CONFIG_WDT) += wdt.o
+obj-$(CONFIG_DM_SERIAL) += serial.o
 endif
diff --git a/test/dm/serial.c b/test/dm/serial.c
new file mode 100644
index 000000000000..4d8422eebd34
--- /dev/null
+++ b/test/dm/serial.c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018, STMicroelectronics
+ */
+
+#include <common.h>
+#include <serial.h>
+#include <dm.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+static int dm_test_serial(struct unit_test_state *uts)
+{
+	struct udevice *dev_serial;
+
+	ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial",
+					      &dev_serial));
+
+	ut_assertok(serial_tstc());
+
+	ut_assertok(serial_setconfig(SERIAL_DEFAULT_CONFIG));
+
+	return 0;
+}
+
+DM_TEST(dm_test_serial, DM_TESTF_SCAN_FDT);
-- 
1.9.1



More information about the U-Boot mailing list