blob: c577048fb5518a036495ee8829a451092804878b [file] [log] [blame]
Kyösti Mälkki3ee16682014-02-17 19:37:52 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18#include <console/console.h>
19#include <uart.h>
20#if CONFIG_USE_OPTION_TABLE
21#include <pc80/mc146818rtc.h>
22#include "option_table.h"
23#endif
24
25unsigned int default_baudrate(void)
26{
27#if !defined(__SMM__) && CONFIG_USE_OPTION_TABLE
28 static const unsigned baud[8] =
29 { 115200, 57600, 38400, 19200, 9600, 4800, 2400, 1200 };
30 unsigned b_index = 0;
31#if defined(__PRE_RAM__)
32 b_index = read_option(baud_rate, 0xff);
33#else
34 if (get_option(&b_index, "baud_rate") != CB_SUCCESS)
35 b_index = 0xff;
36#endif
37 if (b_index < 8)
38 return baud[b_index];
39#endif
40 return CONFIG_TTYS0_BAUD;
41}
42
43/* Calculate divisor. Do not floor but round to nearest integer. */
44unsigned int uart_baudrate_divisor(unsigned int baudrate,
45 unsigned int refclk, unsigned int oversample)
46{
47 return (1 + (2 * refclk) / (baudrate * oversample)) / 2;
48}