From 41e60b6ac97313f9227bece52f9b78d8a946b166 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Mon, 13 May 2019 16:33:18 +0900 Subject: [PATCH] serial: bcm283x_mu: Refactor RX buffer This patch changes maximum count of reading rx fifo by following emprical test, and applies circular queue to buffer. Change-Id: Id498ea9c0c22014f00af2b45ad64ad4c6e69a021 Signed-off-by: Dongwoo Lee --- drivers/serial/serial_bcm283x_mu.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/serial/serial_bcm283x_mu.c b/drivers/serial/serial_bcm283x_mu.c index 179bc36..58ef7db 100644 --- a/drivers/serial/serial_bcm283x_mu.c +++ b/drivers/serial/serial_bcm283x_mu.c @@ -83,12 +83,15 @@ out: static inline int bcm283x_mu_rx_buffer_full(struct bcm283x_mu_priv *priv) { - return !!(priv->rx_buffer_in_pos == BCM283X_MU_RX_BUFFER_LEN - 1); + if (!priv->rx_buffer_out_pos) + return priv->rx_buffer_in_pos == BCM283X_MU_RX_BUFFER_LEN - 1; + + return priv->rx_buffer_out_pos == priv->rx_buffer_in_pos + 1; } static inline int bcm283x_mu_rx_buffer_empty(struct bcm283x_mu_priv *priv) { - return !!(priv->rx_buffer_out_pos == BCM283X_MU_RX_BUFFER_INIT_POS); + return priv->rx_buffer_out_pos == BCM283X_MU_RX_BUFFER_INIT_POS; } static void bcm283x_mu_rx_buffer_put(struct bcm283x_mu_priv *priv, int data) @@ -96,7 +99,10 @@ static void bcm283x_mu_rx_buffer_put(struct bcm283x_mu_priv *priv, int data) if (bcm283x_mu_rx_buffer_empty(priv)) priv->rx_buffer_out_pos++; - priv->rx_buffer[++priv->rx_buffer_in_pos] = data; + priv->rx_buffer_in_pos++; + priv->rx_buffer_in_pos %= BCM283X_MU_RX_BUFFER_LEN; + + priv->rx_buffer[priv->rx_buffer_in_pos] = data; } static int bcm283x_mu_rx_buffer_get(struct bcm283x_mu_priv *priv) @@ -108,6 +114,7 @@ static int bcm283x_mu_rx_buffer_get(struct bcm283x_mu_priv *priv) priv->rx_buffer_out_pos = BCM283X_MU_RX_BUFFER_INIT_POS; } else { priv->rx_buffer_out_pos++; + priv->rx_buffer_out_pos %= BCM283X_MU_RX_BUFFER_LEN; } return data; @@ -117,19 +124,19 @@ static int bcm283x_mu_serial_getc(struct udevice *dev) { struct bcm283x_mu_priv *priv = dev_get_priv(dev); struct bcm283x_mu_regs *regs = priv->regs; - int max_count = 256; + int max_count = 32; while (readl(®s->lsr) & BCM283X_MU_LSR_RX_READY) { if (bcm283x_mu_rx_buffer_full(priv) || --max_count == 0) break; - bcm283x_mu_rx_buffer_put(priv, readl(®s->io)); + bcm283x_mu_rx_buffer_put(priv, (int)readl(®s->io)); } if (bcm283x_mu_rx_buffer_empty(priv)) return -EAGAIN; - return (int)bcm283x_mu_rx_buffer_get(priv); + return bcm283x_mu_rx_buffer_get(priv); } static int bcm283x_mu_serial_putc(struct udevice *dev, const char data) -- 2.7.4