Debian Codegraph @

src/mainboard/purism/librem_l1um_v2/bootblock.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <bootblock_common.h>
4 #include <superio/nuvoton/common/nuvoton.h>
5 #include <superio/nuvoton/nct6791d/nct6791d.h>
6 #include <superio/aspeed/common/aspeed.h>
7 #include <superio/aspeed/ast2400/ast2400.h>
8 #include <console/uart.h>
9 #include <console/console.h>
10 #include <device/pnp_ops.h>
11 #include <delay.h>
12 #include "gpio.h"
13 #include <gpio.h>
14 #include <timer.h>
15
16 static int64_t bmc_ready_elapsed = 0;
17
18 void bootblock_mainboard_early_init(void)
19 {
20 gpio_configure_pads(early_gpio_table, ARRAY_SIZE(early_gpio_table));
21
22 /*
23 * We must wait for the BMC firmware to be ready before proceeding past
24 * early init:
25 * - The BMC UART (the physical serial port) won't work until the BMC is
26 * configured
27 * - The BMC will reset the TPM configuration during startup,
28 * coreboot must not configure or communicate with the TPM before then
29 *
30 * This usually takes about 30 seconds for a boot right after power on.
31 */
32 struct stopwatch sw;
33 stopwatch_init_msecs_expire(&sw, 120 * 1000);
34 while (!stopwatch_expired(&sw)) {
35 /* Wait for J2 to go low - BMC ready signal from BMC firmware */
36 if (!gpio_get(GPP_J2))
37 break;
38 mdelay(1000);
39 }
40 /* Trace the time spent later once the console is up */
41 if (stopwatch_expired(&sw))
42 bmc_ready_elapsed = -1;
43 else
44 bmc_ready_elapsed = stopwatch_duration_msecs(&sw);
45
46 /*
47 * Disable the Nuvoton NCT6791D SuperIO UART1. It is enabled by
48 * default, but the AST2500's is connected to the serial port.
49 */
50 const pnp_devfn_t nvt_serial_dev = PNP_DEV(0x2E, NCT6791D_SP1);
51 nuvoton_pnp_enter_conf_state(nvt_serial_dev);
52 pnp_set_logical_device(nvt_serial_dev);
53 pnp_set_enable(nvt_serial_dev, 0);
54 nuvoton_pnp_exit_conf_state(nvt_serial_dev);
55
56 /* Enable AST2500 SuperIO UART1 */
57 const pnp_devfn_t ast_serial_dev = PNP_DEV(0x4E, AST2400_SUART1);
58 aspeed_enable_serial(ast_serial_dev, CONFIG_TTYS0_BASE);
59 }
60
61 void bootblock_mainboard_init(void)
62 {
63 if (bmc_ready_elapsed >= 0) {
64 printk(BIOS_INFO, "BMC became ready in early init after %lld ms\n",
65 bmc_ready_elapsed);
66 } else {
67 /* Better to boot than to render the system unusable, but some
68 peripherals may not work */
69 printk(BIOS_ERR, "BMC was not ready within timeout, booting anyway\n");
70 }
71 }