blob: 5866ca4d423c9475df4eb95a3bb1afd7d4081f83 [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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Stefan Reinauer509f7722012-12-07 17:31:37 -080018 */
19
Kyösti Mälkki1d7541f2014-02-17 21:34:42 +020020#ifndef CONSOLE_UART_H
21#define CONSOLE_UART_H
Stefan Reinauer509f7722012-12-07 17:31:37 -080022
Kyösti Mälkkif3390862014-02-26 15:19:04 +020023#include <rules.h>
Kyösti Mälkki0567c912014-02-14 10:31:38 +020024#include <stdint.h>
25
Kyösti Mälkki3ee16682014-02-17 19:37:52 +020026/* Return the clock frequency UART uses as reference clock for
27 * baudrate generator. */
28unsigned int uart_platform_refclk(void);
29
30/* Return the baudrate determined from option_table, or when that is
31 * not used, CONFIG_TTYS0_BAUD.
32 */
33unsigned int default_baudrate(void);
34
35/* Returns the divisor value for a given baudrate.
36 * The formula to satisfy is:
37 * refclk / divisor = baudrate * oversample
38 */
39unsigned int uart_baudrate_divisor(unsigned int baudrate,
40 unsigned int refclk, unsigned int oversample);
41
42
Kyösti Mälkki47707492014-02-15 07:53:18 +020043void uart_init(void);
Stefan Reinauer509f7722012-12-07 17:31:37 -080044void uart_tx_byte(unsigned char data);
45void uart_tx_flush(void);
Kyösti Mälkki47707492014-02-15 07:53:18 +020046unsigned char uart_rx_byte(void);
Stefan Reinauer509f7722012-12-07 17:31:37 -080047
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020048unsigned int uart_platform_base(int idx);
David Hendricksfdcef1a2013-02-15 19:29:12 -080049
Kyösti Mälkkic2610a42014-02-24 20:51:30 +020050#if !defined(__ROMCC__)
51static inline void *uart_platform_baseptr(int idx)
52{
53 return (void *)uart_platform_base(idx);
54}
Kyösti Mälkkic2610a42014-02-24 20:51:30 +020055
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020056void oxford_remap(unsigned int new_base);
Kyösti Mälkki1d7541f2014-02-17 21:34:42 +020057
Kyösti Mälkkif3390862014-02-26 15:19:04 +020058#define __CONSOLE_SERIAL_ENABLE__ CONFIG_CONSOLE_SERIAL && \
59 (ENV_BOOTBLOCK || ENV_ROMSTAGE || ENV_RAMSTAGE || \
60 (ENV_SMM && CONFIG_DEBUG_SMI))
61
62#if __CONSOLE_SERIAL_ENABLE__
63static inline void __uart_init(void) { uart_init(); }
64static inline void __uart_tx_byte(u8 data) { uart_tx_byte(data); }
65static inline void __uart_tx_flush(void) { uart_tx_flush(); }
66#else
67static inline void __uart_init(void) {}
68static inline void __uart_tx_byte(u8 data) {}
69static inline void __uart_tx_flush(void) {}
70#endif
71
72#endif /* __ROMCC__ */
73
Kyösti Mälkki1d7541f2014-02-17 21:34:42 +020074#endif /* CONSOLE_UART_H */