blob: 022a1aba7c7f15d60d5eb9c6850ec19b4b62f31f [file] [log] [blame]
Stefan Reinauer6626d6a2012-03-30 15:10:07 -07001/*
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 Reinauer6626d6a2012-03-30 15:10:07 -070014 */
15
Marc Jones04134a52013-10-30 16:18:07 -060016#include <stdint.h>
17#include <arch/io.h>
18#include "chip.h"
Stefan Reinauer6626d6a2012-03-30 15:10:07 -070019
Marc Jones04134a52013-10-30 16:18:07 -060020void sio1007_setreg(u16 lpc_port, u8 reg, u8 value, u8 mask)
Stefan Reinauer6626d6a2012-03-30 15:10:07 -070021{
22 u8 reg_value;
23
24 outb(reg, lpc_port);
25 reg_value = inb(lpc_port + 1);
26 reg_value &= ~mask;
27 reg_value |= (value & mask);
28 outb(reg_value, lpc_port + 1);
29}
30
Marc Jones04134a52013-10-30 16:18:07 -060031int sio1007_enable_uart_at(u16 port)
Stefan Reinauer6626d6a2012-03-30 15:10:07 -070032{
33 /* Enable config mode. */
34 outb(0x55, port);
35 if (inb(port) != 0x55)
36 return 0; /* There is no LPC device at this address. */
37
38 /* Registers 12 and 13 hold config address, look for a match. */
39 outb(0x12, port);
40 if (inb(port + 1) != (port & 0xff))
41 return 0;
42
43 outb(0x13, port);
44 if (inb(port + 1) != (port >> 8))
45 return 0;
46
47 /* This must be the sio1007, enable the UART. */
48 /* turn on power */
49 sio1007_setreg(port, 0x2, 1 << 3, 1 << 3);
50 /* enable high speed */
51 sio1007_setreg(port, 0xc, 1 << 6, 1 << 6);
52 /* set the base address */
53 sio1007_setreg(port, 0x24, CONFIG_TTYS0_BASE >> 2, 0xff);
54
55 /* Disable config mode. */
56 outb(0xaa, port);
57 return 1;
58}