blob: 91d29cf61cf35f525da84b6bce4d7ead82a6aade [file] [log] [blame]
Angel Pons08b52802020-04-05 13:22:20 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Hannah Williams5e83e8b2018-02-09 18:35:17 -08002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
Marco Chen07c80b22020-12-21 22:10:21 +08004#include <baseboard/cbi_ssfc.h>
Hannah Williams5e83e8b2018-02-09 18:35:17 -08005#include <baseboard/variants.h>
6#include <boardid.h>
Karthikeyan Ramasubramanian02592ec2019-06-06 15:57:47 -06007#include <bootstate.h>
Hannah Williams5e83e8b2018-02-09 18:35:17 -08008#include <console/console.h>
9#include <device/device.h>
Furquan Shaikh617fcf32018-08-08 13:30:44 -070010#include <device/pci_def.h>
11#include <device/pci_ops.h>
Marco Chen07c80b22020-12-21 22:10:21 +080012#include <drivers/i2c/generic/chip.h>
Furquan Shaikh367956d52018-07-20 13:50:16 -070013#include <ec/google/chromeec/ec.h>
Hannah Williams5e83e8b2018-02-09 18:35:17 -080014#include <ec/ec.h>
Karthikeyan Ramasubramanian02592ec2019-06-06 15:57:47 -060015#include <intelblocks/xhci.h>
Hannah Williams5e83e8b2018-02-09 18:35:17 -080016#include <nhlt.h>
Furquan Shaikh367956d52018-07-20 13:50:16 -070017#include <smbios.h>
Aaron Durbin2fcc0342018-07-25 08:06:21 -060018#include <soc/cpu.h>
Hannah Williams5e83e8b2018-02-09 18:35:17 -080019#include <soc/gpio.h>
20#include <soc/nhlt.h>
Furquan Shaikh617fcf32018-08-08 13:30:44 -070021#include <soc/pci_devs.h>
22#include <stdint.h>
Hannah Williams5e83e8b2018-02-09 18:35:17 -080023#include <vendorcode/google/chromeos/chromeos.h>
24#include <variant/ec.h>
25#include <variant/gpio.h>
26
Marco Chen07c80b22020-12-21 22:10:21 +080027extern struct chip_operations drivers_i2c_generic_ops;
28extern struct chip_operations drivers_i2c_da7219_ops;
29
Furquan Shaikh617fcf32018-08-08 13:30:44 -070030static bool is_cnvi_held_in_reset(void)
31{
Kyösti Mälkkie7377552018-06-21 16:20:55 +030032 struct device *dev = pcidev_path_on_root(PCH_DEVFN_CNVI);
Furquan Shaikh617fcf32018-08-08 13:30:44 -070033 uint32_t reg = pci_read_config32(dev, PCI_VENDOR_ID);
34
35 /*
36 * If vendor/device ID for CNVi reads as 0xffffffff, then it is safe to
37 * assume that it is being held in reset.
38 */
39 if (reg == 0xffffffff)
40 return true;
41
42 return false;
43}
44
Furquan Shaikh65428992018-08-09 10:11:26 -070045static void disable_wifi_wake(void)
46{
47 static const struct pad_config wifi_wake_gpio[] = {
48 PAD_NC(GPIO_119, UP_20K),
49 };
50
51 gpio_configure_pads(wifi_wake_gpio, ARRAY_SIZE(wifi_wake_gpio));
52}
53
Marco Chen07c80b22020-12-21 22:10:21 +080054/*
55 * GPIO_137 for two audio codecs right now has the different configuration so
56 * if SSFC indicates that codec is different than default one then GPIO_137
57 * needs to be overridden for the corresponding second source.
58 */
59static void gpio_modification_by_ssfc(struct pad_config *table, size_t num)
60{
61 /* For RT5682, GPIO 137 should be set as EDGE_BOTH. */
62 const struct pad_config rt5682_gpio_137 = PAD_CFG_GPI_APIC_IOS(GPIO_137,
63 NONE, DEEP, EDGE_BOTH, INVERT, HIZCRx1, DISPUPD);
64
65 if (table == NULL || num == 0)
66 return;
67
68 /*
69 * Currently we only have the case of RT5682 as the second source. And
70 * in case of Ampton which used RT5682 as the default source, it didn't
71 * provide override_table right now so it will be returned ealier since
72 * table above is NULL.
73 */
74 if (ssfc_get_audio_codec() != SSFC_AUDIO_CODEC_RT5682)
75 return;
76
77 while (num--) {
78 if (table->pad == GPIO_137) {
79 *table = rt5682_gpio_137;
80 printk(BIOS_INFO,
81 "Configure GPIO 137 based on SSFC.\n");
82 return;
83 }
84
85 table++;
86 }
87}
88
Hannah Williams5e83e8b2018-02-09 18:35:17 -080089static void mainboard_init(void *chip_info)
90{
91 int boardid;
Furquan Shaikh06a41f12018-07-25 14:30:59 -070092 const struct pad_config *base_pads;
93 const struct pad_config *override_pads;
94 size_t base_num, override_num;
Hannah Williams5e83e8b2018-02-09 18:35:17 -080095
96 boardid = board_id();
97 printk(BIOS_INFO, "Board ID: %d\n", boardid);
98
Furquan Shaikh06a41f12018-07-25 14:30:59 -070099 base_pads = variant_base_gpio_table(&base_num);
100 override_pads = variant_override_gpio_table(&override_num);
Marco Chen07c80b22020-12-21 22:10:21 +0800101 gpio_modification_by_ssfc((struct pad_config *)override_pads,
102 override_num);
Furquan Shaikh06a41f12018-07-25 14:30:59 -0700103
104 gpio_configure_pads_with_override(base_pads, base_num,
105 override_pads, override_num);
Hannah Williams5e83e8b2018-02-09 18:35:17 -0800106
Furquan Shaikh65428992018-08-09 10:11:26 -0700107 if (!is_cnvi_held_in_reset())
108 disable_wifi_wake();
109
Hannah Williams5e83e8b2018-02-09 18:35:17 -0800110 mainboard_ec_init();
111}
112
113static unsigned long mainboard_write_acpi_tables(
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700114 const struct device *device, unsigned long current, acpi_rsdp_t *rsdp)
Hannah Williams5e83e8b2018-02-09 18:35:17 -0800115{
116 uintptr_t start_addr;
117 uintptr_t end_addr;
118 struct nhlt *nhlt;
119
120 start_addr = current;
121
122 nhlt = nhlt_init();
123
124 if (nhlt == NULL)
125 return start_addr;
126
127 variant_nhlt_init(nhlt);
128
129 end_addr = nhlt_soc_serialize(nhlt, start_addr);
130
131 if (end_addr != start_addr)
132 acpi_add_table(rsdp, (void *)start_addr);
133
134 return end_addr;
135}
136
Elyes HAOUASd129d432018-05-04 20:23:33 +0200137static void mainboard_enable(struct device *dev)
Hannah Williams5e83e8b2018-02-09 18:35:17 -0800138{
139 dev->ops->write_acpi_tables = mainboard_write_acpi_tables;
Nico Huber68680dd2020-03-31 17:34:52 +0200140 dev->ops->acpi_inject_dsdt = chromeos_dsdt_generator;
Hannah Williams5e83e8b2018-02-09 18:35:17 -0800141}
142
143struct chip_operations mainboard_ops = {
144 .init = mainboard_init,
145 .enable_dev = mainboard_enable,
146};
Furquan Shaikh367956d52018-07-20 13:50:16 -0700147
Aaron Durbin2fcc0342018-07-25 08:06:21 -0600148void __weak variant_update_devtree(struct device *dev)
149{
150 /* Place holder for common updates. */
151}
152
Furquan Shaikh617fcf32018-08-08 13:30:44 -0700153/*
154 * Check if CNVi PCI device is released from reset. If yes, then the system is
155 * booting with CNVi module. In this case, the PCIe device for WiFi needs to
156 * be disabled. If CNVi device is held in reset, then disable it.
157 */
158static void wifi_device_update(void)
159{
160 struct device *dev;
161 unsigned int devfn;
162
163 if (is_cnvi_held_in_reset())
164 devfn = PCH_DEVFN_CNVI;
165 else
166 devfn = PCH_DEVFN_PCIE1;
167
Kyösti Mälkkie7377552018-06-21 16:20:55 +0300168 dev = pcidev_path_on_root(devfn);
John Zhaoa2c0cf52018-08-20 10:27:39 -0700169 if (dev)
170 dev->enabled = 0;
Furquan Shaikh617fcf32018-08-08 13:30:44 -0700171}
172
Marco Chen07c80b22020-12-21 22:10:21 +0800173/*
174 * Base on SSFC value in the CBI from EC to enable one of audio codec sources in
175 * the device tree.
176 */
177static void audio_codec_device_update(void)
178{
179 struct device *audio_dev = NULL;
180 struct bus *audio_i2c_bus =
181 pcidev_path_on_root(PCH_DEVFN_I2C5)->link_list;
182 enum ssfc_audio_codec codec = ssfc_get_audio_codec();
183
184 while ((audio_dev = dev_bus_each_child(audio_i2c_bus, audio_dev))) {
185 if (audio_dev->chip_info == NULL)
186 continue;
187
188 if ((audio_dev->chip_ops == &drivers_i2c_da7219_ops) &&
189 (codec == SSFC_AUDIO_CODEC_DA7219)) {
190 printk(BIOS_INFO, "enable DA7219.\n");
191 continue;
192 }
193
194 if ((audio_dev->chip_ops == &drivers_i2c_generic_ops) &&
195 (codec == SSFC_AUDIO_CODEC_RT5682)) {
196 struct drivers_i2c_generic_config *cfg =
197 audio_dev->chip_info;
198
199 if (cfg != NULL && !strcmp(cfg->hid, "10EC5682")) {
200 printk(BIOS_INFO, "enable RT5682.\n");
201 continue;
202 }
203 }
204
205 audio_dev->enabled = 0;
206 }
207}
208
Aaron Durbin2fcc0342018-07-25 08:06:21 -0600209void mainboard_devtree_update(struct device *dev)
210{
Furquan Shaikh617fcf32018-08-08 13:30:44 -0700211 /* Apply common devtree updates. */
212 wifi_device_update();
Marco Chen07c80b22020-12-21 22:10:21 +0800213 audio_codec_device_update();
Furquan Shaikh617fcf32018-08-08 13:30:44 -0700214
Aaron Durbin2fcc0342018-07-25 08:06:21 -0600215 /* Defer to variant for board-specific updates. */
216 variant_update_devtree(dev);
217}
Wisley Chenbd3568a2018-11-06 17:38:57 +0800218
Karthikeyan Ramasubramanian02592ec2019-06-06 15:57:47 -0600219bool __weak variant_ext_usb_status(unsigned int port_type, unsigned int port_id)
220{
221 /* All externally visible USB ports are present */
222 return true;
223}
224
225static void disable_unused_devices(void *unused)
226{
227 usb_xhci_disable_unused(variant_ext_usb_status);
228}
229
230BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, disable_unused_devices, NULL);