payloads/edk2: Disable the CPU Timer Lib unless supported
[coreboot.git] / src / superio / smsc / sio1007 / early_serial.c
blobcdaf83d76e976b38de19285a380f95e29729c2cb
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <stdint.h>
4 #include <arch/io.h>
5 #include "sio1007.h"
7 void sio1007_setreg(u16 lpc_port, u8 reg, u8 value, u8 mask)
9 u8 reg_value;
11 outb(reg, lpc_port);
12 reg_value = inb(lpc_port + 1);
13 reg_value &= ~mask;
14 reg_value |= (value & mask);
15 outb(reg_value, lpc_port + 1);
18 int sio1007_enable_uart_at(u16 port)
20 /* Enable config mode. */
21 outb(0x55, port);
22 if (inb(port) != 0x55)
23 return 0; /* There is no LPC device at this address. */
25 /* Registers 12 and 13 hold config address, look for a match. */
26 outb(0x12, port);
27 if (inb(port + 1) != (port & 0xff))
28 return 0;
30 outb(0x13, port);
31 if (inb(port + 1) != (port >> 8))
32 return 0;
34 /* This must be the sio1007, enable the UART. */
35 /* turn on power */
36 sio1007_setreg(port, 0x2, 1 << 3, 1 << 3);
37 /* enable high speed */
38 sio1007_setreg(port, 0xc, 1 << 6, 1 << 6);
39 /* set the base address */
40 sio1007_setreg(port, 0x24, CONFIG_TTYS0_BASE >> 2, 0xff);
42 /* Disable config mode. */
43 outb(0xaa, port);
44 return 1;