blob: df8f0436573a4b52da0d2d96dff5022b0e8bc43e [file] [log] [blame]
Michael Büchler4f1378e2020-09-06 19:59:18 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <stdint.h>
Michael Büchler4f1378e2020-09-06 19:59:18 +02004#include <bootblock_common.h>
5#include <device/pci_ops.h>
6#include <device/pnp_ops.h>
Michael Büchler4f1378e2020-09-06 19:59:18 +02007#include <option.h>
8#include <southbridge/intel/bd82x6x/pch.h>
9#include <superio/nuvoton/common/nuvoton.h>
10#include <superio/nuvoton/nct6776/nct6776.h>
11
12#define GLOBAL_DEV PNP_DEV(0x2e, 0)
13#define SERIAL_DEV PNP_DEV(0x2e, NCT6776_SP1)
14#define GPIO6789_DEV PNP_DEV(0x2e, NCT6776_GPIO6789_V)
15
16/* As defined in cmos.layout */
17enum cpu_fan_tach_src {
18 CPU_FAN_HEADER_NONE,
19 CPU_FAN_HEADER_1,
20 CPU_FAN_HEADER_2,
21 CPU_FAN_HEADER_BOTH
22};
23
Michael Büchler4f1378e2020-09-06 19:59:18 +020024/*
25 * The tachometer signal that goes to CPUFANIN of the Super I/O is set via
26 * GPIOs.
27 *
28 * When GP77 (register E1h[7]) is '0', CPU_FAN1 is connected.
29 * When GP76 (register E1h[6]) is '0', CPU_FAN2 is connected.
30 * When both are '0' and both fans are connected, wrong readings will
31 * be reported.
32 */
33static u8 get_cpufanin_gpio_config(void)
34{
35 switch (get_uint_option("cpu_fan_tach_src", CPU_FAN_HEADER_1)) {
36 case CPU_FAN_HEADER_NONE:
37 return 0xff;
38 case CPU_FAN_HEADER_1:
39 default:
40 return 0x7f;
41 case CPU_FAN_HEADER_2:
42 return 0xbf;
43 case CPU_FAN_HEADER_BOTH:
44 return 0x3f;
45 }
46};
47
48void bootblock_mainboard_early_init(void)
49{
50 nuvoton_pnp_enter_conf_state(GLOBAL_DEV);
51
52 /* Configure Super I/O pins */
53 pnp_write_config(GLOBAL_DEV, 0x1b, 0x68);
54 pnp_write_config(GLOBAL_DEV, 0x1c, 0x80);
55 pnp_write_config(GLOBAL_DEV, 0x24, 0x5c);
56 pnp_write_config(GLOBAL_DEV, 0x27, 0xc0);
57 pnp_write_config(GLOBAL_DEV, 0x2a, 0x62);
58 pnp_write_config(GLOBAL_DEV, 0x2b, 0x08);
59 pnp_write_config(GLOBAL_DEV, 0x2c, 0x80);
60
61 /* GP77 and GP76 are outputs. They set the tachometer input on CPUFANIN. */
62 pnp_set_logical_device(GPIO6789_DEV);
63 pnp_write_config(GPIO6789_DEV, 0xe0, 0x3f);
64 pnp_write_config(GPIO6789_DEV, 0xe1, get_cpufanin_gpio_config());
65
66 nuvoton_pnp_exit_conf_state(GLOBAL_DEV);
67
68 /* Enable UART */
69 nuvoton_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
70}