aboutsummaryrefslogtreecommitdiff
path: root/src/mainboard/google/skyrim/bootblock.c
blob: d285d7f48df6f7c084d39007c482cb7c90a70784 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* SPDX-License-Identifier: GPL-2.0-only */

#include <amdblocks/espi.h>
#include <amdblocks/reset.h>
#include <bootblock_common.h>
#include <baseboard/variants.h>
#include <console/console.h>
#include <ec/google/chromeec/ec.h>
#include <pc80/mc146818rtc.h>
#include <soc/espi.h>
#include <string.h>

#define CMOS_EXTENDED_ADDR(x)          (128 + (x))
#define CMOS_MEM_RESTORE_OFFSET        0x0D
#define CMOS_BITMAP_SKIP_RESET_TOGGLE  0x10
#define HYNIX_PART_NAME                "H9JCNNNCP3MLYR-N6E"
#define HYNIX_PART_LEN                 18

/* Ensure SKIP_RESET_TOGGLE CMOS bit set for specific Hynix part on Frostflow, cleared otherwise */
static void hynix_dram_cmos_check(void)
{
	char cbi_part_number[DIMM_INFO_PART_NUMBER_SIZE];
	bool skip_reset_toggle, cmos_bit_set;
	unsigned char byte_value;

	byte_value = cmos_read(CMOS_EXTENDED_ADDR(CMOS_MEM_RESTORE_OFFSET));
	cmos_bit_set = (byte_value & CMOS_BITMAP_SKIP_RESET_TOGGLE) != 0;

	if (CONFIG(BOARD_GOOGLE_FROSTFLOW)) {

		printk(BIOS_SPEW, "Checking DRAM part #\n");
		if (google_chromeec_cbi_get_dram_part_num(
				cbi_part_number, sizeof(cbi_part_number)) == 0) {

			skip_reset_toggle = strncmp(cbi_part_number, HYNIX_PART_NAME, HYNIX_PART_LEN) == 0;
			if (skip_reset_toggle) {
				printk(BIOS_SPEW, "SKIP_RESET_TOGGLE needed, checking CMOS bit is set\n");
				if (!cmos_bit_set) {
					printk(BIOS_SPEW, "Bit is unset; setting and rebooting\n");
					cmos_write((byte_value | CMOS_BITMAP_SKIP_RESET_TOGGLE),
							CMOS_EXTENDED_ADDR(CMOS_MEM_RESTORE_OFFSET));
					warm_reset();
				}
				printk(BIOS_SPEW, "Bit already set; nothing to do.\n");
				return;
			}
		} else {
			printk(BIOS_ERR, "Unable to read DRAM part # from CBI; CMOS bit will be cleared if set\n");
		}
	}
	/* Ensure SKIP_RESET_TOGGLE bit cleared if not FF, not bad DRAM part, or error reading part # */
	if (cmos_bit_set) {
		printk(BIOS_SPEW, "CMOS SKIP_RESET_TOGGLE bit is set; clearing and rebooting\n");
		cmos_write((byte_value & ~CMOS_BITMAP_SKIP_RESET_TOGGLE),
					CMOS_EXTENDED_ADDR(CMOS_MEM_RESTORE_OFFSET));
		warm_reset();
	} else {
		printk(BIOS_SPEW, "No change to CMOS SKIP_RESET_TOGGLE bit is needed\n");
	}
}

void mb_set_up_early_espi(void)
{
	size_t num_gpios;
	const struct soc_amd_gpio *gpios;

	variant_espi_gpio_table(&gpios, &num_gpios);
	gpio_configure_pads(gpios, num_gpios);

	espi_switch_to_spi1_pads();
}

void bootblock_mainboard_early_init(void)
{
	size_t num_gpios, override_num_gpios;
	const struct soc_amd_gpio *gpios, *override_gpios;

	variant_tpm_gpio_table(&gpios, &num_gpios);
	gpio_configure_pads(gpios, num_gpios);

	variant_early_gpio_table(&gpios, &num_gpios);
	variant_early_override_gpio_table(&override_gpios, &override_num_gpios);
	gpio_configure_pads_with_override(gpios, num_gpios, override_gpios, override_num_gpios);
}

void bootblock_mainboard_init(void)
{
	size_t num_gpios;
	const struct soc_amd_gpio *gpios;

	hynix_dram_cmos_check();

	variant_bootblock_gpio_table(&gpios, &num_gpios);
	gpio_configure_pads(gpios, num_gpios);
}