diff options
Diffstat (limited to 'chip/lm4/uart.c')
-rw-r--r-- | chip/lm4/uart.c | 96 |
1 files changed, 56 insertions, 40 deletions
diff --git a/chip/lm4/uart.c b/chip/lm4/uart.c index 3595721441..bc5cadb3fe 100644 --- a/chip/lm4/uart.c +++ b/chip/lm4/uart.c @@ -5,7 +5,7 @@ /* UART module for Chrome EC */ -#include "board.h" +#include "common.h" #include "console.h" #include "gpio.h" #include "lpc.h" @@ -17,10 +17,8 @@ /* Baud rate for UARTs */ #define BAUD_RATE 115200 - static int init_done; - int uart_init_done(void) { return init_done; @@ -28,10 +26,12 @@ int uart_init_done(void) void uart_tx_start(void) { - /* Re-enable the transmit interrupt, then forcibly trigger the + /* + * Re-enable the transmit interrupt, then forcibly trigger the * interrupt. This works around a hardware problem with the * UART where the FIFO only triggers the interrupt when its - * threshold is _crossed_, not just met. */ + * threshold is _crossed_, not just met. + */ LM4_UART_IM(0) |= 0x20; task_trigger_irq(LM4_IRQ_UART0); } @@ -94,7 +94,9 @@ void uart_enable_interrupt(void) task_enable_irq(LM4_IRQ_UART0); } -/* Interrupt handler for UART0 */ +/** + * Interrupt handler for UART0 + */ static void uart_0_interrupt(void) { /* Clear transmit and receive interrupt status */ @@ -106,26 +108,31 @@ static void uart_0_interrupt(void) } DECLARE_IRQ(LM4_IRQ_UART0, uart_0_interrupt, 1); - -/* Interrupt handler for UART1 */ +/** + * Interrupt handler for UART1 + */ static void uart_1_interrupt(void) { /* Clear transmit and receive interrupt status */ LM4_UART_ICR(1) = 0x70; #ifdef CONFIG_LPC - /* If we have space in our FIFO and a character is pending in LPC, - * handle that character. */ + /* + * If we have space in our FIFO and a character is pending in LPC, + * handle that character. + */ if (!(LM4_UART_FR(1) & 0x20) && lpc_comx_has_char()) { /* Copy the next byte then disable transmit interrupt */ LM4_UART_DR(1) = lpc_comx_get_char(); LM4_UART_IM(1) &= ~0x20; } - /* Handle received character. There is no flow control on input; + /* + * Handle received character. There is no flow control on input; * received characters are blindly forwarded to LPC. This is ok * because LPC is much faster than UART, and we don't have flow control - * on the UART receive-side either. */ + * on the UART receive-side either. + */ if (!(LM4_UART_FR(1) & 0x10)) lpc_comx_put_char(LM4_UART_DR(1)); #endif @@ -133,8 +140,9 @@ static void uart_1_interrupt(void) /* Must be same prio as LPC interrupt handler so they don't preempt */ DECLARE_IRQ(LM4_IRQ_UART1, uart_1_interrupt, 2); - -/* Configure GPIOs for the UART module. */ +/** + * Configure GPIOs for the UART module. + */ static void configure_gpio(void) { #ifdef BOARD_link @@ -150,8 +158,7 @@ static void configure_gpio(void) #endif } - -int uart_init(void) +void uart_init(void) { volatile uint32_t scratch __attribute__((unused)); int ch; @@ -174,57 +181,53 @@ int uart_init(void) LM4_UART_FBRD(ch) = (((INTERNAL_CLOCK / 16) % BAUD_RATE) * 64 + BAUD_RATE / 2) / BAUD_RATE; - /* 8-N-1, FIFO enabled. Must be done after setting - * the divisor for the new divisor to take effect. */ + /* + * 8-N-1, FIFO enabled. Must be done after setting + * the divisor for the new divisor to take effect. + */ LM4_UART_LCRH(ch) = 0x70; - /* Interrupt when RX fifo at minimum (>= 1/8 full), and TX fifo - * when <= 1/4 full */ + /* + * Interrupt when RX fifo at minimum (>= 1/8 full), and TX fifo + * when <= 1/4 full + */ LM4_UART_IFLS(ch) = 0x01; - /* Unmask receive-FIFO, receive-timeout. We need + /* + * Unmask receive-FIFO, receive-timeout. We need * receive-timeout because the minimum RX FIFO depth is 1/8 = 2 * bytes; without the receive-timeout we'd never be notified - * about single received characters. */ + * about single received characters. + */ LM4_UART_IM(ch) = 0x50; /* Enable the port */ LM4_UART_CTL(ch) |= 0x0001; } - /* Enable interrupts for UART0 only. UART1 will have to wait until the + /* + * Enable interrupts for UART0 only. UART1 will have to wait until the * LPC bus is initialized. */ uart_clear_rx_fifo(0); task_enable_irq(LM4_IRQ_UART0); init_done = 1; - - return EC_SUCCESS; } - /*****************************************************************************/ /* COMx functions */ -/* Write a character to COMx, waiting for space in the output buffer if - * necessary. */ -static void uart_comx_putc_wait(int c) -{ - while (!uart_comx_putc_ok()) {} - uart_comx_putc(c); -} - - void uart_comx_enable(void) { uart_clear_rx_fifo(1); task_enable_irq(LM4_IRQ_UART1); } - int uart_comx_putc_ok(void) { if (LM4_UART_FR(1) & 0x20) { - /* FIFO is full, so enable transmit interrupt to let us know - * when it empties. */ + /* + * FIFO is full, so enable transmit interrupt to let us know + * when it empties. + */ LM4_UART_IM(1) |= 0x20; return 0; } else { @@ -232,16 +235,27 @@ int uart_comx_putc_ok(void) } } - void uart_comx_putc(int c) { LM4_UART_DR(1) = c; } - /*****************************************************************************/ /* Console commands */ +#ifdef CONFIG_CMD_COMXTEST + +/** + * Write a character to COMx, waiting for space in the output buffer if + * necessary. + */ +static void uart_comx_putc_wait(int c) +{ + while (!uart_comx_putc_ok()) + ; + uart_comx_putc(c); +} + static int command_comxtest(int argc, char **argv) { /* Put characters to COMX port */ @@ -261,3 +275,5 @@ DECLARE_CONSOLE_COMMAND(comxtest, command_comxtest, "[string]", "Write test data to COMx uart", NULL); + +#endif /* CONFIG_COMX_TEST */ |