soc/intel/xeon_sp/spr: Drop microcode constraints
[coreboot2.git] / src / include / console / uart.h
blob3f9e5b01da0c3a7582d754c075599c67c2f7012d
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #ifndef CONSOLE_UART_H
4 #define CONSOLE_UART_H
6 #include <stdint.h>
8 /* Return the clock frequency UART uses as reference clock for
9 * baudrate generator. */
10 unsigned int uart_platform_refclk(void);
12 #if CONFIG(UART_OVERRIDE_BAUDRATE)
13 /* Return the baudrate, define this in your platform when using the above
14 configuration. */
15 unsigned int get_uart_baudrate(void);
16 #else
17 static inline unsigned int get_uart_baudrate(void)
19 return CONFIG_TTYS0_BAUD;
21 #endif
23 #if CONFIG(OVERRIDE_UART_FOR_CONSOLE)
24 /* Return the index of uart port, define this in your platform
25 * when need to use variables to override the index.
27 unsigned int get_uart_for_console(void);
28 #else
29 static inline unsigned int get_uart_for_console(void)
31 return CONFIG_UART_FOR_CONSOLE;
33 #endif
35 /* Returns the divisor value for a given baudrate.
36 * The formula to satisfy is:
37 * refclk / divisor = baudrate * oversample
39 unsigned int uart_baudrate_divisor(unsigned int baudrate,
40 unsigned int refclk, unsigned int oversample);
42 /* Returns the oversample divisor multiplied by any other divisors that act
43 * on the input clock
45 unsigned int uart_input_clock_divider(void);
47 /* Bitbang out one byte on an 8n1 UART through the output function set_tx(). */
48 void uart_bitbang_tx_byte(unsigned char data, void (*set_tx)(int line_state));
50 void uart_init(unsigned int idx);
51 void uart_tx_byte(unsigned int idx, unsigned char data);
52 void uart_tx_flush(unsigned int idx);
53 unsigned char uart_rx_byte(unsigned int idx);
55 uintptr_t uart_platform_base(unsigned int idx);
57 static inline void *uart_platform_baseptr(unsigned int idx)
59 return (void *)uart_platform_base(idx);
62 void oxford_remap(unsigned int new_base);
64 #define __CONSOLE_SERIAL_ENABLE__ (CONFIG(CONSOLE_SERIAL) && \
65 (ENV_BOOTBLOCK || ENV_SEPARATE_ROMSTAGE || ENV_RAMSTAGE || ENV_SEPARATE_VERSTAGE \
66 || ENV_POSTCAR || (ENV_SMM && CONFIG(DEBUG_SMI))))
68 #if __CONSOLE_SERIAL_ENABLE__
69 static inline void __uart_init(void)
71 uart_init(get_uart_for_console());
73 static inline void __uart_tx_byte(u8 data)
75 uart_tx_byte(get_uart_for_console(), data);
77 static inline void __uart_tx_flush(void)
79 uart_tx_flush(get_uart_for_console());
81 #else
82 static inline void __uart_init(void) {}
83 static inline void __uart_tx_byte(u8 data) {}
84 static inline void __uart_tx_flush(void) {}
85 #endif
87 #if CONFIG(GDB_STUB) && (ENV_ROMSTAGE_OR_BEFORE || ENV_RAMSTAGE)
88 #define CONF_UART_FOR_GDB CONFIG_UART_FOR_CONSOLE
89 static inline void __gdb_hw_init(void) { uart_init(CONF_UART_FOR_GDB); }
90 static inline void __gdb_tx_byte(u8 data)
92 uart_tx_byte(CONF_UART_FOR_GDB, data);
94 static inline void __gdb_tx_flush(void) { uart_tx_flush(CONF_UART_FOR_GDB); }
95 static inline u8 __gdb_rx_byte(void)
97 return uart_rx_byte(CONF_UART_FOR_GDB);
99 #endif
101 #endif /* CONSOLE_UART_H */