* [PATCH 0/3] sandbox: Minor improvements to serial driver
@ 2020-11-09 3:36 Simon Glass
2020-11-09 3:36 ` [PATCH 1/3] serial: sandbox: Drop unnecessary #ifdefs Simon Glass
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Simon Glass @ 2020-11-09 3:36 UTC (permalink / raw)
To: u-boot
This series updates the sandbox serial driver to clean up the code a
little.
Simon Glass (3):
serial: sandbox: Drop unnecessary #ifdefs
sandbox: serial: Convert to livetree
sandbox: serial: Update to use membuff
drivers/serial/sandbox.c | 63 ++++++++++++++--------------------------
1 file changed, 22 insertions(+), 41 deletions(-)
--
2.29.2.222.g5d2a92d10f8-goog
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] serial: sandbox: Drop unnecessary #ifdefs
2020-11-09 3:36 [PATCH 0/3] sandbox: Minor improvements to serial driver Simon Glass
@ 2020-11-09 3:36 ` Simon Glass
2020-11-09 3:36 ` [PATCH 2/3] sandbox: serial: Convert to livetree Simon Glass
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Simon Glass @ 2020-11-09 3:36 UTC (permalink / raw)
To: u-boot
CONFIG_OF_CONTROL is always enabled for sandbox (as it should be for all
boards), so we can drop it. Also use IS_ENABLED() for the SPL check.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
drivers/serial/sandbox.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c
index db2fbac6295..e3967deaaf2 100644
--- a/drivers/serial/sandbox.c
+++ b/drivers/serial/sandbox.c
@@ -22,8 +22,6 @@
DECLARE_GLOBAL_DATA_PTR;
-#if CONFIG_IS_ENABLED(OF_CONTROL)
-
/*
*
* serial_buf: A buffer that holds keyboard characters for the
@@ -122,9 +120,8 @@ static int sandbox_serial_pending(struct udevice *dev, bool input)
return 0;
os_usleep(100);
-#ifndef CONFIG_SPL_BUILD
- video_sync_all();
-#endif
+ if (!IS_ENABLED(CONFIG_SPL_BUILD))
+ video_sync_all();
if (next_index == serial_buf_read)
return 1; /* buffer full */
@@ -146,7 +143,6 @@ static int sandbox_serial_getc(struct udevice *dev)
serial_buf_read = increment_buffer_index(serial_buf_read);
return result;
}
-#endif /* CONFIG_IS_ENABLED(OF_CONTROL) */
#ifdef CONFIG_DEBUG_UART_SANDBOX
@@ -211,7 +207,6 @@ static int sandbox_serial_getinfo(struct udevice *dev,
return 0;
}
-#if CONFIG_IS_ENABLED(OF_CONTROL)
static const char * const ansi_colour[] = {
"black", "red", "green", "yellow", "blue", "megenta", "cyan",
"white",
@@ -277,5 +272,3 @@ U_BOOT_DEVICE(serial_sandbox_non_fdt) = {
.platdata = &platdata_non_fdt,
};
#endif
-
-#endif /* CONFIG_IS_ENABLED(OF_CONTROL) */
--
2.29.2.222.g5d2a92d10f8-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] sandbox: serial: Convert to livetree
2020-11-09 3:36 [PATCH 0/3] sandbox: Minor improvements to serial driver Simon Glass
2020-11-09 3:36 ` [PATCH 1/3] serial: sandbox: Drop unnecessary #ifdefs Simon Glass
@ 2020-11-09 3:36 ` Simon Glass
2020-11-09 3:36 ` [PATCH 3/3] sandbox: serial: Update to use membuff Simon Glass
2020-12-10 0:26 ` [PATCH 1/3] serial: sandbox: Drop unnecessary #ifdefs Simon Glass
3 siblings, 0 replies; 5+ messages in thread
From: Simon Glass @ 2020-11-09 3:36 UTC (permalink / raw)
To: u-boot
Use a livetree function to read the colour.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
drivers/serial/sandbox.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c
index e3967deaaf2..8c74c3a1b8c 100644
--- a/drivers/serial/sandbox.c
+++ b/drivers/serial/sandbox.c
@@ -12,7 +12,6 @@
#include <common.h>
#include <console.h>
#include <dm.h>
-#include <fdtdec.h>
#include <lcd.h>
#include <os.h>
#include <serial.h>
@@ -221,8 +220,7 @@ static int sandbox_serial_ofdata_to_platdata(struct udevice *dev)
if (CONFIG_IS_ENABLED(OF_PLATDATA))
return 0;
plat->colour = -1;
- colour = fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
- "sandbox,text-colour", NULL);
+ colour = dev_read_string(dev, "sandbox,text-colour");
if (colour) {
for (i = 0; i < ARRAY_SIZE(ansi_colour); i++) {
if (!strcmp(colour, ansi_colour[i])) {
--
2.29.2.222.g5d2a92d10f8-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] sandbox: serial: Update to use membuff
2020-11-09 3:36 [PATCH 0/3] sandbox: Minor improvements to serial driver Simon Glass
2020-11-09 3:36 ` [PATCH 1/3] serial: sandbox: Drop unnecessary #ifdefs Simon Glass
2020-11-09 3:36 ` [PATCH 2/3] sandbox: serial: Convert to livetree Simon Glass
@ 2020-11-09 3:36 ` Simon Glass
2020-12-10 0:26 ` [PATCH 1/3] serial: sandbox: Drop unnecessary #ifdefs Simon Glass
3 siblings, 0 replies; 5+ messages in thread
From: Simon Glass @ 2020-11-09 3:36 UTC (permalink / raw)
To: u-boot
Rather than implementing our own circular queue, use membuff. This allows
us to read multiple bytes at once into the serial input.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
drivers/serial/sandbox.c | 48 ++++++++++++++++------------------------
1 file changed, 19 insertions(+), 29 deletions(-)
diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c
index 8c74c3a1b8c..8e269a205d7 100644
--- a/drivers/serial/sandbox.c
+++ b/drivers/serial/sandbox.c
@@ -21,24 +21,18 @@
DECLARE_GLOBAL_DATA_PTR;
-/*
- *
- * serial_buf: A buffer that holds keyboard characters for the
- * Sandbox U-Boot.
- *
- * invariants:
- * serial_buf_write == serial_buf_read -> empty buffer
- * (serial_buf_write + 1) % 16 == serial_buf_read -> full buffer
- */
-static unsigned char serial_buf[16];
-static unsigned int serial_buf_write;
-static unsigned int serial_buf_read;
-
struct sandbox_serial_platdata {
int colour; /* Text colour to use for output, -1 for none */
};
+/**
+ * struct sandbox_serial_priv - Private data for this driver
+ *
+ * @buf: holds input characters available to be read by this driver
+ */
struct sandbox_serial_priv {
+ struct membuff buf;
+ char serial_buf[16];
bool start_of_line;
};
@@ -71,6 +65,7 @@ static int sandbox_serial_probe(struct udevice *dev)
if (state->term_raw != STATE_TERM_RAW)
disable_ctrlc(1);
+ membuff_init(&priv->buf, priv->serial_buf, sizeof(priv->serial_buf));
return 0;
}
@@ -104,16 +99,12 @@ static int sandbox_serial_putc(struct udevice *dev, const char ch)
return 0;
}
-static unsigned int increment_buffer_index(unsigned int index)
-{
- return (index + 1) % ARRAY_SIZE(serial_buf);
-}
-
static int sandbox_serial_pending(struct udevice *dev, bool input)
{
- const unsigned int next_index =
- increment_buffer_index(serial_buf_write);
+ struct sandbox_serial_priv *priv = dev_get_priv(dev);
ssize_t count;
+ char *data;
+ int avail;
if (!input)
return 0;
@@ -121,26 +112,25 @@ static int sandbox_serial_pending(struct udevice *dev, bool input)
os_usleep(100);
if (!IS_ENABLED(CONFIG_SPL_BUILD))
video_sync_all();
- if (next_index == serial_buf_read)
+ avail = membuff_putraw(&priv->buf, 100, false, &data);
+ if (!avail)
return 1; /* buffer full */
- count = os_read(0, &serial_buf[serial_buf_write], 1);
- if (count == 1)
- serial_buf_write = next_index;
+ count = os_read(0, data, avail);
+ if (count > 0)
+ membuff_putraw(&priv->buf, count, true, &data);
- return serial_buf_write != serial_buf_read;
+ return membuff_avail(&priv->buf);
}
static int sandbox_serial_getc(struct udevice *dev)
{
- int result;
+ struct sandbox_serial_priv *priv = dev_get_priv(dev);
if (!sandbox_serial_pending(dev, true))
return -EAGAIN; /* buffer empty */
- result = serial_buf[serial_buf_read];
- serial_buf_read = increment_buffer_index(serial_buf_read);
- return result;
+ return membuff_getbyte(&priv->buf);
}
#ifdef CONFIG_DEBUG_UART_SANDBOX
--
2.29.2.222.g5d2a92d10f8-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 1/3] serial: sandbox: Drop unnecessary #ifdefs
2020-11-09 3:36 [PATCH 0/3] sandbox: Minor improvements to serial driver Simon Glass
` (2 preceding siblings ...)
2020-11-09 3:36 ` [PATCH 3/3] sandbox: serial: Update to use membuff Simon Glass
@ 2020-12-10 0:26 ` Simon Glass
3 siblings, 0 replies; 5+ messages in thread
From: Simon Glass @ 2020-12-10 0:26 UTC (permalink / raw)
To: u-boot
CONFIG_OF_CONTROL is always enabled for sandbox (as it should be for all
boards), so we can drop it. Also use IS_ENABLED() for the SPL check.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
drivers/serial/sandbox.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
Applied to u-boot-dm, thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-12-10 0:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-09 3:36 [PATCH 0/3] sandbox: Minor improvements to serial driver Simon Glass
2020-11-09 3:36 ` [PATCH 1/3] serial: sandbox: Drop unnecessary #ifdefs Simon Glass
2020-11-09 3:36 ` [PATCH 2/3] sandbox: serial: Convert to livetree Simon Glass
2020-11-09 3:36 ` [PATCH 3/3] sandbox: serial: Update to use membuff Simon Glass
2020-12-10 0:26 ` [PATCH 1/3] serial: sandbox: Drop unnecessary #ifdefs Simon Glass
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.