blob: e5cda068e17d051062f5ffcdbecc5d90190d9ed9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bin Meng5afa22a2016-02-17 00:16:25 -08002/*
3 * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com>
Bin Meng5afa22a2016-02-17 00:16:25 -08004 */
5
Bin Meng5afa22a2016-02-17 00:16:25 -08006#include <dm.h>
7#include <errno.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Bin Meng5afa22a2016-02-17 00:16:25 -08009#include <pci.h>
10#include <smsc_sio1007.h>
11#include <asm/ibmpc.h>
Simon Glass63e08a22016-03-11 22:06:57 -070012#include <asm/lpc_common.h>
Bin Meng5afa22a2016-02-17 00:16:25 -080013#include <asm/pci.h>
14#include <asm/arch/pch.h>
15
16#define SIO1007_RUNTIME_IOPORT 0x180
17
18int board_early_init_f(void)
19{
20 struct udevice *pch;
21 int ret;
22
Michal Suchanekac12a2f2022-10-12 21:57:59 +020023 ret = uclass_first_device_err(UCLASS_PCH, &pch);
Bin Meng5afa22a2016-02-17 00:16:25 -080024 if (ret)
25 return ret;
Bin Meng5afa22a2016-02-17 00:16:25 -080026
27 /* Initialize LPC interface to turn on superio chipset decode range */
28 dm_pci_write_config16(pch, LPC_IO_DEC, COMA_DEC_RANGE | COMB_DEC_RANGE);
29 dm_pci_write_config16(pch, LPC_EN, KBC_LPC_EN | COMA_LPC_EN);
30 dm_pci_write_config32(pch, LPC_GEN1_DEC, GEN_DEC_RANGE_256B |
31 (SIO1007_IOPORT3 & 0xff00) | GEN_DEC_RANGE_EN);
32 dm_pci_write_config32(pch, LPC_GEN2_DEC, GEN_DEC_RANGE_16B |
33 SIO1007_RUNTIME_IOPORT | GEN_DEC_RANGE_EN);
34
35 /* Enable legacy serial port at 0x3f8 */
36 sio1007_enable_serial(SIO1007_IOPORT3, 0, UART0_BASE, UART0_IRQ);
37
38 /* Enable SIO1007 runtime I/O port at 0x180 */
39 sio1007_enable_runtime(SIO1007_IOPORT3, SIO1007_RUNTIME_IOPORT);
40
41 /*
42 * On Cougar Canyon 2 board, the RS232 transiver connected to serial
43 * port 0 (0x3f8) is controlled by a GPIO pin (GPIO10) on the SIO1007.
44 * Set the pin value to 1 to enable the RS232 transiver.
45 */
46 sio1007_gpio_config(SIO1007_IOPORT3, 0, GPIO_DIR_OUTPUT,
47 GPIO_POL_NO_INVERT, GPIO_TYPE_PUSH_PULL);
48 sio1007_gpio_set_value(SIO1007_RUNTIME_IOPORT, 0, 1);
49
50 return 0;
51}