Skip to content

Instantly share code, notes, and snippets.

@stffrdhrn
Last active November 12, 2017 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stffrdhrn/a7c94c9fc76463da494349007a27dfc3 to your computer and use it in GitHub Desktop.
Save stffrdhrn/a7c94c9fc76463da494349007a27dfc3 to your computer and use it in GitHub Desktop.
diff --git a/drivers/tty/serial/uart-litex.c b/drivers/tty/serial/uart-litex.c
index c56a690757d4..6f908e96c76b 100644
--- a/drivers/tty/serial/uart-litex.c
+++ b/drivers/tty/serial/uart-litex.c
@@ -50,10 +50,6 @@
#define LITEX_STATUS_FRAME 0x40
#define LITEX_STATUS_PARITY 0x80
-#define LITEX_CONTROL_RST_TX 0x01
-#define LITEX_CONTROL_RST_RX 0x02
-#define LITEX_CONTROL_IE 0x10
-
static inline u32 uart_in32(u32 offset, struct uart_port *port)
{
return readb(port->membase + offset);
@@ -166,12 +162,8 @@ static irqreturn_t litex_uart_isr(int irq, void *dev_id)
static unsigned int litex_uart_tx_empty(struct uart_port *port)
{
- unsigned long flags;
- unsigned int ret;
-
- // TODO implement by reading LITEX_UART_TXFULL
-
- return TIOCSER_TEMT;
+ /* Not really empty but not-full */
+ return (uart_in32(LITEX_UART_TXFULL, port) & 0x1) ? 0 : TIOCSER_TEMT;
}
static unsigned int litex_uart_get_mctrl(struct uart_port *port)
@@ -228,11 +220,8 @@ static int litex_uart_startup(struct uart_port *port)
if (r == 0)
uart_out32(0x3, LITEX_UART_EV_ENABLE, port);
-#if 0 // TODO error
- uart_out32(LITEX_CONTROL_RST_RX | LITEX_CONTROL_RST_TX,
- LITEX_CONTROL, port);
- uart_out32(LITEX_CONTROL_IE, LITEX_CONTROL, port);
-#endif
+ /* Enable the interrupt events */
+ uart_out32(0x1, LITEX_UART_EV_ENABLE, port);
return 0;
}
@@ -397,18 +386,17 @@ static const struct uart_ops litex_uart_ops = {
#ifdef CONFIG_SERIAL_UART_LITEX_CONSOLE
static void litex_uart_console_wait_tx(struct uart_port *port)
{
- u8 val;
+ u32 full;
unsigned long timeout;
/*
* Spin waiting for TX fifo to have space available.
- * When using the Microblaze Debug Module this can take up to 1s
+ * Copied from Microblaze.
*/
timeout = jiffies + msecs_to_jiffies(1000);
-#if 0 // TODO TXFULL
while (1) {
- val = uart_in32(LITEX_STATUS, port);
- if ((val & LITEX_STATUS_TXFULL) == 0)
+ full = readl(LITEX_UART_TXFULL + port->membase);
+ if (!full)
break;
if (time_after(jiffies, timeout)) {
dev_warn(port->dev,
@@ -417,21 +405,6 @@ static void litex_uart_console_wait_tx(struct uart_port *port)
}
cpu_relax();
}
-#else
- while (1) {
- val = uart_in32(LITEX_UART_TXFULL, port);
- if ((val & 1) == 0)
- break;
- if (time_after(jiffies, timeout)) {
- dev_warn(port->dev,
- "timeout waiting for TX buffer empty\n");
- break;
- }
- cpu_relax();
- }
-
- // msleep(1);
-#endif
}
static void litex_uart_console_putchar(struct uart_port *port, int ch)
@@ -445,7 +418,7 @@ static void litex_uart_console_write(struct console *co, const char *s,
{
struct uart_port *port = &litex_uart_ports[co->index];
unsigned long flags;
- unsigned int ier;
+ u32 ier;
int locked = 1;
if (oops_in_progress) {
@@ -454,20 +427,17 @@ static void litex_uart_console_write(struct console *co, const char *s,
spin_lock_irqsave(&port->lock, flags);
/* save and disable interrupt */
-#if 0 // TODO interrupt
- ier = uart_in32(LITEX_STATUS, port) & LITEX_STATUS_IE;
- uart_out32(0, LITEX_CONTROL, port);
-#endif
+ ier = uart_in32(LITEX_UART_EV_ENABLE, port) & 0x1;
+ if (ier)
+ uart_out32(0, LITEX_UART_EV_ENABLE, port);
uart_console_write(port, s, count, litex_uart_console_putchar);
litex_uart_console_wait_tx(port);
/* restore interrupt state */
-#if 0 // TODO interrupt
if (ier)
- uart_out32(LITEX_CONTROL_IE, LITEX_CONTROL, port);
-#endif
+ uart_out32(ier, LITEX_UART_EV_ENABLE, port);
if (locked)
spin_unlock_irqrestore(&port->lock, flags);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment