blob: 8458086d49adc0d8ca39934d1cb0e8da3e937dab [file] [log] [blame]
Stefan Reinauer509f7722012-12-07 17:31:37 -08001/*
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 Reinauer509f7722012-12-07 17:31:37 -080014 */
15
Kyösti Mälkki1d7541f2014-02-17 21:34:42 +020016#ifndef CONSOLE_UART_H
17#define CONSOLE_UART_H
Stefan Reinauer509f7722012-12-07 17:31:37 -080018
Kyösti Mälkkif3390862014-02-26 15:19:04 +020019#include <rules.h>
Kyösti Mälkki0567c912014-02-14 10:31:38 +020020#include <stdint.h>
21
Kyösti Mälkki3ee16682014-02-17 19:37:52 +020022/* Return the clock frequency UART uses as reference clock for
23 * baudrate generator. */
24unsigned 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 */
29unsigned 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 */
35unsigned int uart_baudrate_divisor(unsigned int baudrate,
36 unsigned int refclk, unsigned int oversample);
37
38
Kyösti Mälkki70342a72014-03-14 22:28:29 +020039void uart_init(int idx);
40void uart_tx_byte(int idx, unsigned char data);
41void uart_tx_flush(int idx);
42unsigned char uart_rx_byte(int idx);
Stefan Reinauer509f7722012-12-07 17:31:37 -080043
Ronald G. Minnich2adb2972014-10-16 10:53:48 +000044uintptr_t uart_platform_base(int idx);
David Hendricksfdcef1a2013-02-15 19:29:12 -080045
Kyösti Mälkkic2610a42014-02-24 20:51:30 +020046#if !defined(__ROMCC__)
47static inline void *uart_platform_baseptr(int idx)
48{
49 return (void *)uart_platform_base(idx);
50}
Kyösti Mälkkic2610a42014-02-24 20:51:30 +020051
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020052void oxford_remap(unsigned int new_base);
Kyösti Mälkki1d7541f2014-02-17 21:34:42 +020053
Kyösti Mälkkif3390862014-02-26 15:19:04 +020054#define __CONSOLE_SERIAL_ENABLE__ CONFIG_CONSOLE_SERIAL && \
Aaron Durbinfd6fb262015-05-13 13:37:43 -050055 (ENV_BOOTBLOCK || ENV_ROMSTAGE || ENV_RAMSTAGE || ENV_VERSTAGE || \
Aaron Durbin8c8e2b72015-10-14 10:08:10 -050056 (ENV_SMM && CONFIG_DEBUG_SMI))
Kyösti Mälkkif3390862014-02-26 15:19:04 +020057
58#if __CONSOLE_SERIAL_ENABLE__
Kyösti Mälkki70342a72014-03-14 22:28:29 +020059static inline void __uart_init(void) { uart_init(CONFIG_UART_FOR_CONSOLE); }
60static inline void __uart_tx_byte(u8 data) { uart_tx_byte(CONFIG_UART_FOR_CONSOLE, data); }
61static inline void __uart_tx_flush(void) { uart_tx_flush(CONFIG_UART_FOR_CONSOLE); }
Kyösti Mälkkif3390862014-02-26 15:19:04 +020062#else
63static inline void __uart_init(void) {}
64static inline void __uart_tx_byte(u8 data) {}
65static inline void __uart_tx_flush(void) {}
66#endif
67
Kyösti Mälkkif2f7f032014-04-04 15:05:28 +030068#if CONFIG_GDB_STUB && (ENV_ROMSTAGE || ENV_RAMSTAGE)
69#define CONFIG_UART_FOR_GDB CONFIG_UART_FOR_CONSOLE
70static inline void __gdb_hw_init(void) { uart_init(CONFIG_UART_FOR_GDB); }
71static inline void __gdb_tx_byte(u8 data) { uart_tx_byte(CONFIG_UART_FOR_GDB, data); }
72static inline void __gdb_tx_flush(void) { uart_tx_flush(CONFIG_UART_FOR_GDB); }
73static inline u8 __gdb_rx_byte(void) { return uart_rx_byte(CONFIG_UART_FOR_GDB); }
74#endif
75
Kyösti Mälkkif3390862014-02-26 15:19:04 +020076#endif /* __ROMCC__ */
77
Kyösti Mälkki1d7541f2014-02-17 21:34:42 +020078#endif /* CONSOLE_UART_H */