static inline int bcm283x_mu_rx_buffer_full(struct bcm283x_mu_priv *priv)
{
- 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;
+ return !!(priv->rx_buffer_in_pos == BCM283X_MU_RX_BUFFER_LEN - 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)
if (bcm283x_mu_rx_buffer_empty(priv))
priv->rx_buffer_out_pos++;
- priv->rx_buffer_in_pos++;
- priv->rx_buffer_in_pos %= BCM283X_MU_RX_BUFFER_LEN;
-
- priv->rx_buffer[priv->rx_buffer_in_pos] = data;
+ priv->rx_buffer[++priv->rx_buffer_in_pos] = data;
}
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;
{
struct bcm283x_mu_priv *priv = dev_get_priv(dev);
struct bcm283x_mu_regs *regs = priv->regs;
- int max_count = 32;
+ int max_count = 256;
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, (int)readl(®s->io));
+ bcm283x_mu_rx_buffer_put(priv, readl(®s->io));
}
if (bcm283x_mu_rx_buffer_empty(priv))
return -EAGAIN;
- return bcm283x_mu_rx_buffer_get(priv);
+ return (int)bcm283x_mu_rx_buffer_get(priv);
}
static int bcm283x_mu_serial_putc(struct udevice *dev, const char data)