Angel Pons | 08b5280 | 2020-04-05 13:22:20 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 3 | |
| 4 | #include <arch/acpi.h> |
| 5 | #include <baseboard/variants.h> |
| 6 | #include <boardid.h> |
Karthikeyan Ramasubramanian | 02592ec | 2019-06-06 15:57:47 -0600 | [diff] [blame] | 7 | #include <bootstate.h> |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 8 | #include <console/console.h> |
| 9 | #include <device/device.h> |
Furquan Shaikh | 617fcf3 | 2018-08-08 13:30:44 -0700 | [diff] [blame] | 10 | #include <device/pci_def.h> |
| 11 | #include <device/pci_ops.h> |
Furquan Shaikh | 367956d5 | 2018-07-20 13:50:16 -0700 | [diff] [blame] | 12 | #include <ec/google/chromeec/ec.h> |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 13 | #include <ec/ec.h> |
Karthikeyan Ramasubramanian | 02592ec | 2019-06-06 15:57:47 -0600 | [diff] [blame] | 14 | #include <intelblocks/xhci.h> |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 15 | #include <nhlt.h> |
Furquan Shaikh | 367956d5 | 2018-07-20 13:50:16 -0700 | [diff] [blame] | 16 | #include <smbios.h> |
Aaron Durbin | 2fcc034 | 2018-07-25 08:06:21 -0600 | [diff] [blame] | 17 | #include <soc/cpu.h> |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 18 | #include <soc/gpio.h> |
| 19 | #include <soc/nhlt.h> |
Furquan Shaikh | 617fcf3 | 2018-08-08 13:30:44 -0700 | [diff] [blame] | 20 | #include <soc/pci_devs.h> |
| 21 | #include <stdint.h> |
Furquan Shaikh | 367956d5 | 2018-07-20 13:50:16 -0700 | [diff] [blame] | 22 | #include <string.h> |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 23 | #include <vendorcode/google/chromeos/chromeos.h> |
| 24 | #include <variant/ec.h> |
| 25 | #include <variant/gpio.h> |
| 26 | |
Furquan Shaikh | 617fcf3 | 2018-08-08 13:30:44 -0700 | [diff] [blame] | 27 | static bool is_cnvi_held_in_reset(void) |
| 28 | { |
Kyösti Mälkki | e737755 | 2018-06-21 16:20:55 +0300 | [diff] [blame] | 29 | struct device *dev = pcidev_path_on_root(PCH_DEVFN_CNVI); |
Furquan Shaikh | 617fcf3 | 2018-08-08 13:30:44 -0700 | [diff] [blame] | 30 | uint32_t reg = pci_read_config32(dev, PCI_VENDOR_ID); |
| 31 | |
| 32 | /* |
| 33 | * If vendor/device ID for CNVi reads as 0xffffffff, then it is safe to |
| 34 | * assume that it is being held in reset. |
| 35 | */ |
| 36 | if (reg == 0xffffffff) |
| 37 | return true; |
| 38 | |
| 39 | return false; |
| 40 | } |
| 41 | |
Furquan Shaikh | 6542899 | 2018-08-09 10:11:26 -0700 | [diff] [blame] | 42 | static void disable_wifi_wake(void) |
| 43 | { |
| 44 | static const struct pad_config wifi_wake_gpio[] = { |
| 45 | PAD_NC(GPIO_119, UP_20K), |
| 46 | }; |
| 47 | |
| 48 | gpio_configure_pads(wifi_wake_gpio, ARRAY_SIZE(wifi_wake_gpio)); |
| 49 | } |
| 50 | |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 51 | static void mainboard_init(void *chip_info) |
| 52 | { |
| 53 | int boardid; |
Furquan Shaikh | 06a41f1 | 2018-07-25 14:30:59 -0700 | [diff] [blame] | 54 | const struct pad_config *base_pads; |
| 55 | const struct pad_config *override_pads; |
| 56 | size_t base_num, override_num; |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 57 | |
| 58 | boardid = board_id(); |
| 59 | printk(BIOS_INFO, "Board ID: %d\n", boardid); |
| 60 | |
Furquan Shaikh | 06a41f1 | 2018-07-25 14:30:59 -0700 | [diff] [blame] | 61 | base_pads = variant_base_gpio_table(&base_num); |
| 62 | override_pads = variant_override_gpio_table(&override_num); |
| 63 | |
| 64 | gpio_configure_pads_with_override(base_pads, base_num, |
| 65 | override_pads, override_num); |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 66 | |
Furquan Shaikh | 6542899 | 2018-08-09 10:11:26 -0700 | [diff] [blame] | 67 | if (!is_cnvi_held_in_reset()) |
| 68 | disable_wifi_wake(); |
| 69 | |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 70 | mainboard_ec_init(); |
| 71 | } |
| 72 | |
| 73 | static unsigned long mainboard_write_acpi_tables( |
Elyes HAOUAS | d129d43 | 2018-05-04 20:23:33 +0200 | [diff] [blame] | 74 | struct device *device, unsigned long current, acpi_rsdp_t *rsdp) |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 75 | { |
| 76 | uintptr_t start_addr; |
| 77 | uintptr_t end_addr; |
| 78 | struct nhlt *nhlt; |
| 79 | |
| 80 | start_addr = current; |
| 81 | |
| 82 | nhlt = nhlt_init(); |
| 83 | |
| 84 | if (nhlt == NULL) |
| 85 | return start_addr; |
| 86 | |
| 87 | variant_nhlt_init(nhlt); |
| 88 | |
| 89 | end_addr = nhlt_soc_serialize(nhlt, start_addr); |
| 90 | |
| 91 | if (end_addr != start_addr) |
| 92 | acpi_add_table(rsdp, (void *)start_addr); |
| 93 | |
| 94 | return end_addr; |
| 95 | } |
| 96 | |
Elyes HAOUAS | d129d43 | 2018-05-04 20:23:33 +0200 | [diff] [blame] | 97 | static void mainboard_enable(struct device *dev) |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 98 | { |
| 99 | dev->ops->write_acpi_tables = mainboard_write_acpi_tables; |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 100 | dev->ops->acpi_inject_dsdt = chromeos_dsdt_generator; |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | struct chip_operations mainboard_ops = { |
| 104 | .init = mainboard_init, |
| 105 | .enable_dev = mainboard_enable, |
| 106 | }; |
Furquan Shaikh | 367956d5 | 2018-07-20 13:50:16 -0700 | [diff] [blame] | 107 | |
Aaron Durbin | 2fcc034 | 2018-07-25 08:06:21 -0600 | [diff] [blame] | 108 | void __weak variant_update_devtree(struct device *dev) |
| 109 | { |
| 110 | /* Place holder for common updates. */ |
| 111 | } |
| 112 | |
Furquan Shaikh | 617fcf3 | 2018-08-08 13:30:44 -0700 | [diff] [blame] | 113 | /* |
| 114 | * Check if CNVi PCI device is released from reset. If yes, then the system is |
| 115 | * booting with CNVi module. In this case, the PCIe device for WiFi needs to |
| 116 | * be disabled. If CNVi device is held in reset, then disable it. |
| 117 | */ |
| 118 | static void wifi_device_update(void) |
| 119 | { |
| 120 | struct device *dev; |
| 121 | unsigned int devfn; |
| 122 | |
| 123 | if (is_cnvi_held_in_reset()) |
| 124 | devfn = PCH_DEVFN_CNVI; |
| 125 | else |
| 126 | devfn = PCH_DEVFN_PCIE1; |
| 127 | |
Kyösti Mälkki | e737755 | 2018-06-21 16:20:55 +0300 | [diff] [blame] | 128 | dev = pcidev_path_on_root(devfn); |
John Zhao | a2c0cf5 | 2018-08-20 10:27:39 -0700 | [diff] [blame] | 129 | if (dev) |
| 130 | dev->enabled = 0; |
Furquan Shaikh | 617fcf3 | 2018-08-08 13:30:44 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Aaron Durbin | 2fcc034 | 2018-07-25 08:06:21 -0600 | [diff] [blame] | 133 | void mainboard_devtree_update(struct device *dev) |
| 134 | { |
Furquan Shaikh | 617fcf3 | 2018-08-08 13:30:44 -0700 | [diff] [blame] | 135 | /* Apply common devtree updates. */ |
| 136 | wifi_device_update(); |
| 137 | |
Aaron Durbin | 2fcc034 | 2018-07-25 08:06:21 -0600 | [diff] [blame] | 138 | /* Defer to variant for board-specific updates. */ |
| 139 | variant_update_devtree(dev); |
| 140 | } |
Wisley Chen | bd3568a | 2018-11-06 17:38:57 +0800 | [diff] [blame] | 141 | |
| 142 | const char *smbios_mainboard_manufacturer(void) |
| 143 | { |
| 144 | static char oem_name[32]; |
| 145 | static const char *manuf; |
| 146 | |
| 147 | if (manuf) |
| 148 | return manuf; |
| 149 | |
| 150 | if (google_chromeec_cbi_get_oem_name(&oem_name[0], |
| 151 | ARRAY_SIZE(oem_name)) < 0) { |
| 152 | printk(BIOS_ERR, "Couldn't obtain OEM name from CBI\n"); |
| 153 | manuf = CONFIG_MAINBOARD_SMBIOS_MANUFACTURER; |
| 154 | } else { |
| 155 | manuf = &oem_name[0]; |
| 156 | } |
| 157 | |
| 158 | return manuf; |
| 159 | } |
Karthikeyan Ramasubramanian | 02592ec | 2019-06-06 15:57:47 -0600 | [diff] [blame] | 160 | |
| 161 | bool __weak variant_ext_usb_status(unsigned int port_type, unsigned int port_id) |
| 162 | { |
| 163 | /* All externally visible USB ports are present */ |
| 164 | return true; |
| 165 | } |
| 166 | |
| 167 | static void disable_unused_devices(void *unused) |
| 168 | { |
| 169 | usb_xhci_disable_unused(variant_ext_usb_status); |
| 170 | } |
| 171 | |
| 172 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, disable_unused_devices, NULL); |