aboutsummaryrefslogtreecommitdiff
path: root/src/mainboard/google/zork/variants/baseboard/ramstage_common.c
blob: 298837b54ba48a0eeb15266e5e3e7c638d935147 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* SPDX-License-Identifier: GPL-2.0-or-later */

#include <acpi/acpi_device.h>
#include <baseboard/variants.h>
#include <console/console.h>
#include <device/device.h>
#include <drivers/amd/i2s_machine_dev/chip.h>
#include <drivers/i2c/generic/chip.h>
#include <drivers/usb/acpi/chip.h>
#include <ec/google/chromeec/ec.h>
#include <soc/gpio.h>
#include <soc/pci_devs.h>

extern struct chip_operations drivers_amd_i2s_machine_dev_ops;
extern struct chip_operations drivers_i2c_generic_ops;


static void update_hp_int_odl(void)
{

	static const struct device_path rt5682_path[] = {
		{
			.type = DEVICE_PATH_PCI,
			.pci.devfn = LPC_DEVFN
		},
		{
			.type = DEVICE_PATH_PNP,
			.pnp.port = 0xc09,
			.pnp.device = 0x0
		},
		{
			.type = DEVICE_PATH_GENERIC,
			.generic.id = 0,
			.generic.subid = 0
		},
		{
			.type = DEVICE_PATH_I2C,
			.i2c.device = 0x1a
		}
	};

	const struct device *rt5682_dev;
	struct drivers_i2c_generic_config *cfg;
	struct acpi_gpio *gpio;

	if (!variant_uses_codec_gpi())
		return;

	rt5682_dev = find_dev_nested_path(
		pci_root_bus(), rt5682_path, ARRAY_SIZE(rt5682_path));
	if (!rt5682_dev) {
		printk(BIOS_ERR, "%s: Failed to find audio device\n",
				__func__);
		return;
	}

	if (rt5682_dev->chip_ops != &drivers_i2c_generic_ops) {
		printk(BIOS_ERR, "%s: Incorrect device found\n", __func__);
		return;
	}

	cfg = config_of(rt5682_dev);
	gpio = &cfg->irq_gpio;
	gpio->pins[0] = 62;

}

void variant_audio_update(void)
{
	const struct device *gpp_a_dev;
	const struct device *acp_dev;
	struct device *machine_dev = NULL;

	if (variant_uses_v3_schematics())
		return;

	gpp_a_dev = pcidev_path_on_root(PCIE_GPP_A_DEVFN);
	if (gpp_a_dev == NULL)
		return;

	acp_dev = pcidev_path_behind(gpp_a_dev->link_list, AUDIO_DEVFN);
	if (acp_dev == NULL)
		return;

	while ((machine_dev = dev_bus_each_child(acp_dev->link_list, machine_dev)) != NULL) {
		struct drivers_amd_i2s_machine_dev_config *cfg;
		struct acpi_gpio *gpio;

		if (machine_dev->chip_info == NULL)
			continue;

		if (machine_dev->chip_ops != &drivers_amd_i2s_machine_dev_ops)
			continue;

		cfg = machine_dev->chip_info;
		gpio = &cfg->dmic_select_gpio;

		if (CONFIG(BOARD_GOOGLE_BASEBOARD_TREMBYLE))
			gpio->pins[0] = GPIO_13;
		else
			gpio->pins[0] = GPIO_6;

		break;
	}

	update_hp_int_odl();
}

static const struct device_path xhci0_bt_path[] = {
	{
		.type = DEVICE_PATH_PCI,
		.pci.devfn = PCIE_GPP_A_DEVFN
	},
	{
		.type = DEVICE_PATH_PCI,
		.pci.devfn = XHCI0_DEVFN
	},
	{
		.type = DEVICE_PATH_USB,
		.usb.port_type = 0,
		.usb.port_id = 0
	},
	{
		.type = DEVICE_PATH_USB,
		.usb.port_type = 2,
		.usb.port_id = 5
	}
};

static const struct device_path xhci1_bt_path[] = {
	{
		.type = DEVICE_PATH_PCI,
		.pci.devfn = PCIE_GPP_A_DEVFN
	},
	{
		.type = DEVICE_PATH_PCI,
		.pci.devfn = XHCI1_DEVFN
	},
	{
		.type = DEVICE_PATH_USB,
		.usb.port_type = 0,
		.usb.port_id = 0
	},
	{
		.type = DEVICE_PATH_USB,
		.usb.port_type = 2,
		.usb.port_id = 1
	}
};

/*
 * Removes reset_gpio from bluetooth device in device tree.
 *
 * The bluetooth device may be on XHCI0 or XHCI1 depending on SOC.
 * There's no harm in removing from both here.
 */
static void baseboard_remove_bluetooth_reset_gpio(void)
{
	const struct device *xhci0_bt_dev, *xhci1_bt_dev;
	struct drivers_usb_acpi_config *xhci0_bt_cfg, *xhci1_bt_cfg;

	xhci0_bt_dev = find_dev_nested_path(
		pci_root_bus(), xhci0_bt_path, ARRAY_SIZE(xhci0_bt_path));
	if (!xhci0_bt_dev) {
		printk(BIOS_ERR, "%s: Failed to find bluetooth device on XHCI0!", __func__);
		return;
	}
	/* config_of dies on failure, so a NULL check is not required */
	xhci0_bt_cfg = config_of(xhci0_bt_dev);
	xhci0_bt_cfg->reset_gpio.pin_count = 0;

	/* There's no bluetooth device on XHCI1 on Dalboz */
	if (CONFIG(BOARD_GOOGLE_BASEBOARD_DALBOZ))
		return;

	xhci1_bt_dev = find_dev_nested_path(
		pci_root_bus(), xhci1_bt_path, ARRAY_SIZE(xhci1_bt_path));
	if (!xhci1_bt_dev) {
		printk(BIOS_ERR, "%s: Failed to find bluetooth device on XHCI1!", __func__);
		return;
	}
	xhci1_bt_cfg = config_of(xhci1_bt_dev);
	xhci1_bt_cfg->reset_gpio.pin_count = 0;
}

void variant_bluetooth_update(void)
{
	if (CONFIG(BOARD_GOOGLE_BASEBOARD_DALBOZ) || variant_uses_v3_schematics())
		return;

	baseboard_remove_bluetooth_reset_gpio();
}