Debian Codegraph @

src/mainboard/asrock/h77pro4-m/early_init.c

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