• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <stdint.h>
4 #include <arch/io.h>
5 #include "sio1007.h"
6 
sio1007_setreg(u16 lpc_port,u8 reg,u8 value,u8 mask)7 void sio1007_setreg(u16 lpc_port, u8 reg, u8 value, u8 mask)
8 {
9 	u8 reg_value;
10 
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);
16 }
17 
sio1007_enable_uart_at(u16 port)18 int sio1007_enable_uart_at(u16 port)
19 {
20 	/* Enable config mode. */
21 	outb(0x55, port);
22 	if (inb(port) != 0x55)
23 		return 0; /* There is no LPC device at this address. */
24 
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;
29 
30 	outb(0x13, port);
31 	if (inb(port + 1) != (port >> 8))
32 		return 0;
33 
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);
41 
42 	/* Disable config mode. */
43 	outb(0xaa, port);
44 	return 1;
45 }
46