U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 1/7] dm: serial: Add ->getconfig() callback
Date: Tue, 20 Nov 2018 23:52:32 +0200	[thread overview]
Message-ID: <20181120215238.21551-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20181120215238.21551-1-andriy.shevchenko@linux.intel.com>

In some cases it would be good to know the settings, such as parity,
of current serial console. One example might be an ACPI SPCR table
to generate using these parameters.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/serial/sandbox.c       | 13 +++++++++++++
 drivers/serial/serial-uclass.c | 16 ++++++++++++++++
 include/common.h               |  1 +
 include/serial.h               | 26 +++++++++++++++++++++++---
 test/dm/serial.c               |  7 +++++++
 5 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c
index 4a05ea44ce..76d26d3c59 100644
--- a/drivers/serial/sandbox.c
+++ b/drivers/serial/sandbox.c
@@ -163,6 +163,18 @@ DEBUG_UART_FUNCS
 
 #endif /* CONFIG_DEBUG_UART_SANDBOX */
 
+static int sandbox_serial_getconfig(struct udevice *dev, uint *serial_config)
+{
+	uint config = SERIAL_DEFAULT_CONFIG;
+
+	if (!serial_config)
+		return -EINVAL;
+
+	*serial_config = config;
+
+	return 0;
+}
+
 static int sandbox_serial_setconfig(struct udevice *dev, uint serial_config)
 {
 	u8 parity = SERIAL_GET_PARITY(serial_config);
@@ -207,6 +219,7 @@ static const struct dm_serial_ops sandbox_serial_ops = {
 	.putc = sandbox_serial_putc,
 	.pending = sandbox_serial_pending,
 	.getc = sandbox_serial_getc,
+	.getconfig = sandbox_serial_getconfig,
 	.setconfig = sandbox_serial_setconfig,
 };
 
diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index 665cca85cb..d5a3b1255f 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -294,6 +294,20 @@ void serial_setbrg(void)
 		ops->setbrg(gd->cur_serial_dev, gd->baudrate);
 }
 
+int serial_getconfig(uint *config)
+{
+	struct dm_serial_ops *ops;
+
+	if (!gd->cur_serial_dev)
+		return 0;
+
+	ops = serial_get_ops(gd->cur_serial_dev);
+	if (ops->getconfig)
+		return ops->getconfig(gd->cur_serial_dev, config);
+
+	return 0;
+}
+
 int serial_setconfig(uint config)
 {
 	struct dm_serial_ops *ops;
@@ -419,6 +433,8 @@ static int serial_post_probe(struct udevice *dev)
 		ops->pending += gd->reloc_off;
 	if (ops->clear)
 		ops->clear += gd->reloc_off;
+	if (ops->getconfig)
+		ops->getconfig += gd->reloc_off;
 	if (ops->setconfig)
 		ops->setconfig += gd->reloc_off;
 #if CONFIG_POST & CONFIG_SYS_POST_UART
diff --git a/include/common.h b/include/common.h
index 8b9f859c07..675495bde5 100644
--- a/include/common.h
+++ b/include/common.h
@@ -356,6 +356,7 @@ void	serial_putc_raw(const char);
 void	serial_puts   (const char *);
 int	serial_getc   (void);
 int	serial_tstc   (void);
+int	serial_getconfig(uint *config);
 int	serial_setconfig(uint config);
 
 /* $(CPU)/speed.c */
diff --git a/include/serial.h b/include/serial.h
index 020cd392e8..bc6d28ea86 100644
--- a/include/serial.h
+++ b/include/serial.h
@@ -75,6 +75,8 @@ enum serial_par {
 
 #define SERIAL_PAR_SHIFT	0
 #define SERIAL_PAR_MASK		(0x03 << SERIAL_PAR_SHIFT)
+#define SERIAL_SET_PARITY(parity) \
+	((parity << SERIAL_PAR_SHIFT) & SERIAL_PAR_MASK)
 #define SERIAL_GET_PARITY(config) \
 	((config & SERIAL_PAR_MASK) >> SERIAL_PAR_SHIFT)
 
@@ -87,6 +89,8 @@ enum serial_bits {
 
 #define SERIAL_BITS_SHIFT	2
 #define SERIAL_BITS_MASK	(0x3 << SERIAL_BITS_SHIFT)
+#define SERIAL_SET_BITS(bits) \
+	((bits << SERIAL_BITS_SHIFT) & SERIAL_BITS_MASK)
 #define SERIAL_GET_BITS(config) \
 	((config & SERIAL_BITS_MASK) >> SERIAL_BITS_SHIFT)
 
@@ -99,6 +103,8 @@ enum serial_stop {
 
 #define SERIAL_STOP_SHIFT	4
 #define SERIAL_STOP_MASK	(0x3 << SERIAL_STOP_SHIFT)
+#define SERIAL_SET_STOP(stop) \
+	((stop << SERIAL_STOP_SHIFT) & SERIAL_STOP_MASK)
 #define SERIAL_GET_STOP(config) \
 	((config & SERIAL_STOP_MASK) >> SERIAL_STOP_SHIFT)
 
@@ -107,9 +113,10 @@ enum serial_stop {
 		      bits << SERIAL_BITS_SHIFT | \
 		      stop << SERIAL_STOP_SHIFT)
 
-#define SERIAL_DEFAULT_CONFIG	SERIAL_PAR_NONE << SERIAL_PAR_SHIFT | \
-				SERIAL_8_BITS << SERIAL_BITS_SHIFT | \
-				SERIAL_ONE_STOP << SERIAL_STOP_SHIFT
+#define SERIAL_DEFAULT_CONFIG \
+			(SERIAL_PAR_NONE << SERIAL_PAR_SHIFT | \
+			 SERIAL_8_BITS << SERIAL_BITS_SHIFT | \
+			 SERIAL_ONE_STOP << SERIAL_STOP_SHIFT)
 
 /**
  * struct struct dm_serial_ops - Driver model serial operations
@@ -188,6 +195,19 @@ struct dm_serial_ops {
 	int (*loop)(struct udevice *dev, int on);
 #endif
 
+	/**
+	 * getconfig() - Get the uart configuration
+	 * (parity, 5/6/7/8 bits word length, stop bits)
+	 *
+	 * Get a current config for this device.
+	 *
+	 * @dev: Device pointer
+	 * @parity: parity to use
+	 * @bits: bits number to use
+	 * @stop: stop bits number to use
+	 * @return 0 if OK, -ve on error
+	 */
+	int (*getconfig)(struct udevice *dev, uint *serial_config);
 	/**
 	 * setconfig() - Set up the uart configuration
 	 * (parity, 5/6/7/8 bits word length, stop bits)
diff --git a/test/dm/serial.c b/test/dm/serial.c
index 5c603e1f42..7a1a1526a4 100644
--- a/test/dm/serial.c
+++ b/test/dm/serial.c
@@ -12,6 +12,7 @@
 static int dm_test_serial(struct unit_test_state *uts)
 {
 	struct udevice *dev_serial;
+	uint value_serial;
 
 	ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial",
 					      &dev_serial));
@@ -22,6 +23,12 @@ static int dm_test_serial(struct unit_test_state *uts)
 	 * sandbox_serial driver
 	 */
 	ut_assertok(serial_setconfig(SERIAL_DEFAULT_CONFIG));
+	ut_assertok(serial_getconfig(&value_serial));
+	ut_assert(value_serial == SERIAL_DEFAULT_CONFIG);
+	/*
+	 * test with a parameter which is NULL pointer
+	 */
+	ut_asserteq(-EINVAL, serial_getconfig(NULL));
 	/*
 	 * test with a serial config which is not supported by
 	 * sandbox_serial driver: test with wrong parity
-- 
2.19.1

  reply	other threads:[~2018-11-20 21:52 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-20 21:52 [U-Boot] [PATCH v3 0/7] ACPI: Generate SPCR table Andy Shevchenko
2018-11-20 21:52 ` Andy Shevchenko [this message]
2018-11-27  1:02   ` [U-Boot] [PATCH v3 1/7] dm: serial: Add ->getconfig() callback Simon Glass
2018-11-27 16:02     ` Andy Shevchenko
2018-12-03 16:18       ` Andy Shevchenko
2018-12-05 12:55       ` Simon Glass
2018-12-05 14:01         ` Andy Shevchenko
2018-12-05 15:58           ` Simon Glass
2018-12-05 23:11             ` sjg at google.com
2018-11-20 21:52 ` [U-Boot] [PATCH v3 2/7] dm: serial: Introduce ->getinfo() callback Andy Shevchenko
2018-12-05 12:55   ` Simon Glass
2018-12-05 23:11     ` sjg at google.com
2018-11-20 21:52 ` [U-Boot] [PATCH v3 3/7] serial: ns16550: Group reg_* members of ns16550_platdata Andy Shevchenko
2018-12-05 12:55   ` Simon Glass
2018-12-05 23:11     ` sjg at google.com
2018-11-20 21:52 ` [U-Boot] [PATCH v3 4/7] serial: ns16550: Read reg-io-width from device tree Andy Shevchenko
2018-12-05 12:55   ` Simon Glass
2018-12-05 23:11     ` sjg at google.com
2018-11-20 21:52 ` [U-Boot] [PATCH v3 5/7] serial: ns16550: Provide ->getinfo() implementation Andy Shevchenko
2018-12-05 12:55   ` Simon Glass
2018-12-05 23:11     ` sjg at google.com
2018-11-20 21:52 ` [U-Boot] [PATCH v3 6/7] x86: acpi: Add SPCR table description Andy Shevchenko
2018-12-05 23:11   ` sjg at google.com
2018-11-20 21:52 ` [U-Boot] [PATCH v3 7/7] x86: acpi: Generate SPCR table Andy Shevchenko
2018-12-05 12:55   ` Simon Glass
2018-12-05 23:11     ` sjg at google.com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181120215238.21551-2-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox