Stefan Reinauer | 509f772 | 2012-12-07 17:31:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2012 The ChromiumOS Authors. All rights reserved. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Stefan Reinauer | 509f772 | 2012-12-07 17:31:37 -0800 | [diff] [blame] | 14 | */ |
| 15 | |
Kyösti Mälkki | 1d7541f | 2014-02-17 21:34:42 +0200 | [diff] [blame] | 16 | #ifndef CONSOLE_UART_H |
| 17 | #define CONSOLE_UART_H |
Stefan Reinauer | 509f772 | 2012-12-07 17:31:37 -0800 | [diff] [blame] | 18 | |
Kyösti Mälkki | f339086 | 2014-02-26 15:19:04 +0200 | [diff] [blame] | 19 | #include <rules.h> |
Kyösti Mälkki | 0567c91 | 2014-02-14 10:31:38 +0200 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | |
Kyösti Mälkki | 3ee1668 | 2014-02-17 19:37:52 +0200 | [diff] [blame] | 22 | /* Return the clock frequency UART uses as reference clock for |
| 23 | * baudrate generator. */ |
| 24 | unsigned int uart_platform_refclk(void); |
| 25 | |
| 26 | /* Return the baudrate determined from option_table, or when that is |
| 27 | * not used, CONFIG_TTYS0_BAUD. |
| 28 | */ |
| 29 | unsigned int default_baudrate(void); |
| 30 | |
| 31 | /* Returns the divisor value for a given baudrate. |
| 32 | * The formula to satisfy is: |
| 33 | * refclk / divisor = baudrate * oversample |
| 34 | */ |
| 35 | unsigned int uart_baudrate_divisor(unsigned int baudrate, |
| 36 | unsigned int refclk, unsigned int oversample); |
| 37 | |
Lee Leahy | 1487621 | 2016-05-04 13:13:20 -0700 | [diff] [blame] | 38 | /* Returns the oversample divisor multiplied by any other divisors that act |
| 39 | * on the input clock |
| 40 | */ |
| 41 | unsigned int uart_input_clock_divider(void); |
Kyösti Mälkki | 3ee1668 | 2014-02-17 19:37:52 +0200 | [diff] [blame] | 42 | |
Kyösti Mälkki | 70342a7 | 2014-03-14 22:28:29 +0200 | [diff] [blame] | 43 | void uart_init(int idx); |
| 44 | void uart_tx_byte(int idx, unsigned char data); |
| 45 | void uart_tx_flush(int idx); |
| 46 | unsigned char uart_rx_byte(int idx); |
Stefan Reinauer | 509f772 | 2012-12-07 17:31:37 -0800 | [diff] [blame] | 47 | |
Ronald G. Minnich | 2adb297 | 2014-10-16 10:53:48 +0000 | [diff] [blame] | 48 | uintptr_t uart_platform_base(int idx); |
David Hendricks | fdcef1a | 2013-02-15 19:29:12 -0800 | [diff] [blame] | 49 | |
Kyösti Mälkki | c2610a4 | 2014-02-24 20:51:30 +0200 | [diff] [blame] | 50 | #if !defined(__ROMCC__) |
| 51 | static inline void *uart_platform_baseptr(int idx) |
| 52 | { |
| 53 | return (void *)uart_platform_base(idx); |
| 54 | } |
Kyösti Mälkki | c2610a4 | 2014-02-24 20:51:30 +0200 | [diff] [blame] | 55 | |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame] | 56 | void oxford_remap(unsigned int new_base); |
Kyösti Mälkki | 1d7541f | 2014-02-17 21:34:42 +0200 | [diff] [blame] | 57 | |
Lee Leahy | f00e446 | 2017-03-07 13:17:49 -0800 | [diff] [blame] | 58 | #define __CONSOLE_SERIAL_ENABLE__ (CONFIG_CONSOLE_SERIAL && \ |
Aaron Durbin | fd6fb26 | 2015-05-13 13:37:43 -0500 | [diff] [blame] | 59 | (ENV_BOOTBLOCK || ENV_ROMSTAGE || ENV_RAMSTAGE || ENV_VERSTAGE || \ |
Lee Leahy | f00e446 | 2017-03-07 13:17:49 -0800 | [diff] [blame] | 60 | ENV_POSTCAR || (ENV_SMM && CONFIG_DEBUG_SMI))) |
Kyösti Mälkki | f339086 | 2014-02-26 15:19:04 +0200 | [diff] [blame] | 61 | |
| 62 | #if __CONSOLE_SERIAL_ENABLE__ |
Kyösti Mälkki | 70342a7 | 2014-03-14 22:28:29 +0200 | [diff] [blame] | 63 | static inline void __uart_init(void) { uart_init(CONFIG_UART_FOR_CONSOLE); } |
| 64 | static inline void __uart_tx_byte(u8 data) { uart_tx_byte(CONFIG_UART_FOR_CONSOLE, data); } |
| 65 | static inline void __uart_tx_flush(void) { uart_tx_flush(CONFIG_UART_FOR_CONSOLE); } |
Kyösti Mälkki | f339086 | 2014-02-26 15:19:04 +0200 | [diff] [blame] | 66 | #else |
| 67 | static inline void __uart_init(void) {} |
| 68 | static inline void __uart_tx_byte(u8 data) {} |
| 69 | static inline void __uart_tx_flush(void) {} |
| 70 | #endif |
| 71 | |
Kyösti Mälkki | f2f7f03 | 2014-04-04 15:05:28 +0300 | [diff] [blame] | 72 | #if CONFIG_GDB_STUB && (ENV_ROMSTAGE || ENV_RAMSTAGE) |
| 73 | #define CONFIG_UART_FOR_GDB CONFIG_UART_FOR_CONSOLE |
| 74 | static inline void __gdb_hw_init(void) { uart_init(CONFIG_UART_FOR_GDB); } |
| 75 | static inline void __gdb_tx_byte(u8 data) { uart_tx_byte(CONFIG_UART_FOR_GDB, data); } |
| 76 | static inline void __gdb_tx_flush(void) { uart_tx_flush(CONFIG_UART_FOR_GDB); } |
| 77 | static inline u8 __gdb_rx_byte(void) { return uart_rx_byte(CONFIG_UART_FOR_GDB); } |
| 78 | #endif |
| 79 | |
Kyösti Mälkki | f339086 | 2014-02-26 15:19:04 +0200 | [diff] [blame] | 80 | #endif /* __ROMCC__ */ |
| 81 | |
Kyösti Mälkki | 1d7541f | 2014-02-17 21:34:42 +0200 | [diff] [blame] | 82 | #endif /* CONSOLE_UART_H */ |