summaryrefslogtreecommitdiff
path: root/src/mainboard/apple/macbookpro10_1/early_init.c
blob: 39596fd827fba4fe1ec27afc0a4e7b5d04e487c7 (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
96
97
98
99
100
101
102
103
104
105
/* SPDX-License-Identifier: GPL-2.0-only */

#include <device/pci_ops.h>
#include <northbridge/intel/sandybridge/sandybridge.h>
#include <northbridge/intel/sandybridge/raminit_native.h>
#include <southbridge/intel/bd82x6x/pch.h>
#include <drivers/apple/hybrid_graphics/hybrid_graphics.h>
#include <cbfs.h>
#include <southbridge/intel/common/gpio.h>

const struct southbridge_usb_port mainboard_usb_ports[] = {
	{ 1, 0,  0 }, /* Ext A (XHCI/EHCI) */
	{ 1, 0,  1 }, /* Ext B (XHCI) */
	{ 1, 0,  2 }, /* Ext C (XHCI/EHCI) */
	{ 1, 0,  3 }, /* Ext D (XHCI) */
	{ 0, 0, -1 }, /* Unused */
	{ 1, 0, -1 }, /* SD */
	{ 1, 0, -1 }, /* Wi-Fi */
	{ 1, 0, -1 }, /* USB Hub (All LS/FS Devices) */
	{ 1, 0, -1 }, /* Camera */
	{ 1, 0,  4 }, /* Ext B (EHCI) */
	{ 1, 0,  5 }, /* Ext D (EHCI) */
	{ 1, 0, -1 }, /* BT */
	{ 0, 0, -1 }, /* Unused */
	{ 0, 0, -1 }, /* Unused */
};

void mainboard_early_init(int s3resume)
{
	bool igd, peg;
	u32 reg32;

	early_hybrid_graphics(&igd, &peg);

	/* Hide disabled devices */
	reg32 = pci_read_config32(HOST_BRIDGE, DEVEN);
	reg32 &= ~(DEVEN_PEG10 | DEVEN_IGD);

	if (peg)
		reg32 |= DEVEN_PEG10;

	if (igd) {
		reg32 |= DEVEN_IGD;
	} else {
		/* Disable IGD VGA decode, no GTT or GFX stolen */
		pci_write_config16(HOST_BRIDGE, GGC, 2);
	}

	pci_write_config32(HOST_BRIDGE, DEVEN, reg32);
}

static uint8_t *get_spd_data(int spd_index)
{
	uint8_t *spd_file;
	size_t spd_file_len;

	printk(BIOS_DEBUG, "spd index %d\n", spd_index);
	spd_file = cbfs_map("spd.bin", &spd_file_len);
	if (!spd_file)
		die("SPD data not found.");

	if (spd_file_len < spd_index * 256)
		die("Missing SPD data.");

	return spd_file + spd_index * 256;
}

void mainboard_get_spd(spd_raw_data *spd, bool id_only)
{
	uint8_t *memory;
	const int spd_gpio_vector[] = {71, 70, 69, 68, -1};
	int ramcfg = get_gpios(spd_gpio_vector);
	int spd_index = -1;

	/*
	 * GPIO68 GPIO69 GPIO70 GPIO71 Memory           Supported
	 * 0      0      0      0      4G Hynix 1600S   No
	 * 0      0      0      1      1G Samsung 1600  No
	 * 0      0      1      0      4G Samsung 1600S No
	 * 0      0      1      1      1G Hynix 1600    No
	 * 0      1      0      0      4G Elpida 1600S  No
	 * 0      1      0      1      2G Samsung 1600  No
	 * 0      1      1      0      2G Samsung 1333  No
	 * 0      1      1      1      2G Hynix 1600    Yes
	 * 1      0      0      0      4G Samsung 1600  No
	 * 1      0      0      1      4G Hynix 1600    Yes
	 * 1      0      1      0      2G Elpida 1600S  No
	 * 1      0      1      1      2G Elpida 1600   No
	 * 1      1      0      0      4G Elpida 1600   No
	 * 1      1      0      1      2G Samsung 1600S No
	 * 1      1      1      0      2G Hynix 1600S   No
	 */

	if (ramcfg == 7)
		spd_index = 0;
	else if (ramcfg == 9)
		spd_index = 1;

	if (spd_index == -1)
		die("Unsupported memory, RAMCFG=%d\n", ramcfg);

	memory = get_spd_data(spd_index);
	memcpy(&spd[0], memory, 256);
	memcpy(&spd[2], memory, 256);
}