Angel Pons | 08b5280 | 2020-04-05 13:22:20 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Marco Chen | 07c80b2 | 2020-12-21 22:10:21 +0800 | [diff] [blame] | 4 | #include <baseboard/cbi_ssfc.h> |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 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> |
Marco Chen | 07c80b2 | 2020-12-21 22:10:21 +0800 | [diff] [blame] | 12 | #include <drivers/i2c/generic/chip.h> |
Furquan Shaikh | 367956d5 | 2018-07-20 13:50:16 -0700 | [diff] [blame] | 13 | #include <ec/google/chromeec/ec.h> |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 14 | #include <ec/ec.h> |
Karthikeyan Ramasubramanian | 02592ec | 2019-06-06 15:57:47 -0600 | [diff] [blame] | 15 | #include <intelblocks/xhci.h> |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 16 | #include <nhlt.h> |
Furquan Shaikh | 367956d5 | 2018-07-20 13:50:16 -0700 | [diff] [blame] | 17 | #include <smbios.h> |
Aaron Durbin | 2fcc034 | 2018-07-25 08:06:21 -0600 | [diff] [blame] | 18 | #include <soc/cpu.h> |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 19 | #include <soc/gpio.h> |
| 20 | #include <soc/nhlt.h> |
Furquan Shaikh | 617fcf3 | 2018-08-08 13:30:44 -0700 | [diff] [blame] | 21 | #include <soc/pci_devs.h> |
| 22 | #include <stdint.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 | |
Marco Chen | 07c80b2 | 2020-12-21 22:10:21 +0800 | [diff] [blame] | 27 | extern struct chip_operations drivers_i2c_generic_ops; |
Eric Lai | 598f2ba | 2021-04-15 11:43:02 +0800 | [diff] [blame] | 28 | extern struct chip_operations drivers_i2c_cs42l42_ops; |
Marco Chen | 07c80b2 | 2020-12-21 22:10:21 +0800 | [diff] [blame] | 29 | extern struct chip_operations drivers_i2c_da7219_ops; |
| 30 | |
Furquan Shaikh | 617fcf3 | 2018-08-08 13:30:44 -0700 | [diff] [blame] | 31 | static bool is_cnvi_held_in_reset(void) |
| 32 | { |
Kyösti Mälkki | e737755 | 2018-06-21 16:20:55 +0300 | [diff] [blame] | 33 | struct device *dev = pcidev_path_on_root(PCH_DEVFN_CNVI); |
Furquan Shaikh | 617fcf3 | 2018-08-08 13:30:44 -0700 | [diff] [blame] | 34 | uint32_t reg = pci_read_config32(dev, PCI_VENDOR_ID); |
| 35 | |
| 36 | /* |
| 37 | * If vendor/device ID for CNVi reads as 0xffffffff, then it is safe to |
| 38 | * assume that it is being held in reset. |
| 39 | */ |
| 40 | if (reg == 0xffffffff) |
| 41 | return true; |
| 42 | |
| 43 | return false; |
| 44 | } |
| 45 | |
Furquan Shaikh | 6542899 | 2018-08-09 10:11:26 -0700 | [diff] [blame] | 46 | static void disable_wifi_wake(void) |
| 47 | { |
| 48 | static const struct pad_config wifi_wake_gpio[] = { |
| 49 | PAD_NC(GPIO_119, UP_20K), |
| 50 | }; |
| 51 | |
| 52 | gpio_configure_pads(wifi_wake_gpio, ARRAY_SIZE(wifi_wake_gpio)); |
| 53 | } |
| 54 | |
Marco Chen | 07c80b2 | 2020-12-21 22:10:21 +0800 | [diff] [blame] | 55 | /* |
| 56 | * GPIO_137 for two audio codecs right now has the different configuration so |
| 57 | * if SSFC indicates that codec is different than default one then GPIO_137 |
| 58 | * needs to be overridden for the corresponding second source. |
| 59 | */ |
| 60 | static void gpio_modification_by_ssfc(struct pad_config *table, size_t num) |
| 61 | { |
| 62 | /* For RT5682, GPIO 137 should be set as EDGE_BOTH. */ |
| 63 | const struct pad_config rt5682_gpio_137 = PAD_CFG_GPI_APIC_IOS(GPIO_137, |
| 64 | NONE, DEEP, EDGE_BOTH, INVERT, HIZCRx1, DISPUPD); |
| 65 | |
| 66 | if (table == NULL || num == 0) |
| 67 | return; |
| 68 | |
| 69 | /* |
| 70 | * Currently we only have the case of RT5682 as the second source. And |
| 71 | * in case of Ampton which used RT5682 as the default source, it didn't |
Martin Roth | 50863da | 2021-10-01 14:37:30 -0600 | [diff] [blame] | 72 | * provide override_table right now so it will be returned earlier since |
Marco Chen | 07c80b2 | 2020-12-21 22:10:21 +0800 | [diff] [blame] | 73 | * table above is NULL. |
| 74 | */ |
| 75 | if (ssfc_get_audio_codec() != SSFC_AUDIO_CODEC_RT5682) |
| 76 | return; |
| 77 | |
| 78 | while (num--) { |
| 79 | if (table->pad == GPIO_137) { |
| 80 | *table = rt5682_gpio_137; |
| 81 | printk(BIOS_INFO, |
| 82 | "Configure GPIO 137 based on SSFC.\n"); |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | table++; |
| 87 | } |
| 88 | } |
| 89 | |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 90 | static void mainboard_init(void *chip_info) |
| 91 | { |
| 92 | int boardid; |
Furquan Shaikh | 06a41f1 | 2018-07-25 14:30:59 -0700 | [diff] [blame] | 93 | const struct pad_config *base_pads; |
| 94 | const struct pad_config *override_pads; |
| 95 | size_t base_num, override_num; |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 96 | |
| 97 | boardid = board_id(); |
| 98 | printk(BIOS_INFO, "Board ID: %d\n", boardid); |
| 99 | |
Furquan Shaikh | 06a41f1 | 2018-07-25 14:30:59 -0700 | [diff] [blame] | 100 | base_pads = variant_base_gpio_table(&base_num); |
| 101 | override_pads = variant_override_gpio_table(&override_num); |
Marco Chen | 07c80b2 | 2020-12-21 22:10:21 +0800 | [diff] [blame] | 102 | gpio_modification_by_ssfc((struct pad_config *)override_pads, |
| 103 | override_num); |
Furquan Shaikh | 06a41f1 | 2018-07-25 14:30:59 -0700 | [diff] [blame] | 104 | |
| 105 | gpio_configure_pads_with_override(base_pads, base_num, |
| 106 | override_pads, override_num); |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 107 | |
Furquan Shaikh | 6542899 | 2018-08-09 10:11:26 -0700 | [diff] [blame] | 108 | if (!is_cnvi_held_in_reset()) |
| 109 | disable_wifi_wake(); |
| 110 | |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 111 | mainboard_ec_init(); |
| 112 | } |
| 113 | |
| 114 | static unsigned long mainboard_write_acpi_tables( |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 115 | const struct device *device, unsigned long current, acpi_rsdp_t *rsdp) |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 116 | { |
| 117 | uintptr_t start_addr; |
| 118 | uintptr_t end_addr; |
| 119 | struct nhlt *nhlt; |
| 120 | |
| 121 | start_addr = current; |
| 122 | |
| 123 | nhlt = nhlt_init(); |
| 124 | |
| 125 | if (nhlt == NULL) |
| 126 | return start_addr; |
| 127 | |
| 128 | variant_nhlt_init(nhlt); |
| 129 | |
| 130 | end_addr = nhlt_soc_serialize(nhlt, start_addr); |
| 131 | |
| 132 | if (end_addr != start_addr) |
| 133 | acpi_add_table(rsdp, (void *)start_addr); |
| 134 | |
| 135 | return end_addr; |
| 136 | } |
| 137 | |
Elyes HAOUAS | d129d43 | 2018-05-04 20:23:33 +0200 | [diff] [blame] | 138 | static void mainboard_enable(struct device *dev) |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 139 | { |
| 140 | dev->ops->write_acpi_tables = mainboard_write_acpi_tables; |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 141 | dev->ops->acpi_inject_dsdt = chromeos_dsdt_generator; |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | struct chip_operations mainboard_ops = { |
| 145 | .init = mainboard_init, |
| 146 | .enable_dev = mainboard_enable, |
| 147 | }; |
Furquan Shaikh | 367956d5 | 2018-07-20 13:50:16 -0700 | [diff] [blame] | 148 | |
Aaron Durbin | 2fcc034 | 2018-07-25 08:06:21 -0600 | [diff] [blame] | 149 | void __weak variant_update_devtree(struct device *dev) |
| 150 | { |
| 151 | /* Place holder for common updates. */ |
| 152 | } |
| 153 | |
Furquan Shaikh | 617fcf3 | 2018-08-08 13:30:44 -0700 | [diff] [blame] | 154 | /* |
| 155 | * Check if CNVi PCI device is released from reset. If yes, then the system is |
| 156 | * booting with CNVi module. In this case, the PCIe device for WiFi needs to |
| 157 | * be disabled. If CNVi device is held in reset, then disable it. |
| 158 | */ |
| 159 | static void wifi_device_update(void) |
| 160 | { |
| 161 | struct device *dev; |
| 162 | unsigned int devfn; |
| 163 | |
| 164 | if (is_cnvi_held_in_reset()) |
| 165 | devfn = PCH_DEVFN_CNVI; |
| 166 | else |
| 167 | devfn = PCH_DEVFN_PCIE1; |
| 168 | |
Kyösti Mälkki | e737755 | 2018-06-21 16:20:55 +0300 | [diff] [blame] | 169 | dev = pcidev_path_on_root(devfn); |
John Zhao | a2c0cf5 | 2018-08-20 10:27:39 -0700 | [diff] [blame] | 170 | if (dev) |
| 171 | dev->enabled = 0; |
Furquan Shaikh | 617fcf3 | 2018-08-08 13:30:44 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Marco Chen | 07c80b2 | 2020-12-21 22:10:21 +0800 | [diff] [blame] | 174 | /* |
| 175 | * Base on SSFC value in the CBI from EC to enable one of audio codec sources in |
| 176 | * the device tree. |
| 177 | */ |
| 178 | static void audio_codec_device_update(void) |
| 179 | { |
| 180 | struct device *audio_dev = NULL; |
| 181 | struct bus *audio_i2c_bus = |
| 182 | pcidev_path_on_root(PCH_DEVFN_I2C5)->link_list; |
| 183 | enum ssfc_audio_codec codec = ssfc_get_audio_codec(); |
| 184 | |
| 185 | while ((audio_dev = dev_bus_each_child(audio_i2c_bus, audio_dev))) { |
| 186 | if (audio_dev->chip_info == NULL) |
| 187 | continue; |
| 188 | |
| 189 | if ((audio_dev->chip_ops == &drivers_i2c_da7219_ops) && |
| 190 | (codec == SSFC_AUDIO_CODEC_DA7219)) { |
| 191 | printk(BIOS_INFO, "enable DA7219.\n"); |
| 192 | continue; |
| 193 | } |
| 194 | |
| 195 | if ((audio_dev->chip_ops == &drivers_i2c_generic_ops) && |
| 196 | (codec == SSFC_AUDIO_CODEC_RT5682)) { |
| 197 | struct drivers_i2c_generic_config *cfg = |
| 198 | audio_dev->chip_info; |
| 199 | |
| 200 | if (cfg != NULL && !strcmp(cfg->hid, "10EC5682")) { |
| 201 | printk(BIOS_INFO, "enable RT5682.\n"); |
| 202 | continue; |
| 203 | } |
| 204 | } |
Eric Lai | 598f2ba | 2021-04-15 11:43:02 +0800 | [diff] [blame] | 205 | |
| 206 | if ((audio_dev->chip_ops == &drivers_i2c_cs42l42_ops) && |
| 207 | (codec == SSFC_AUDIO_CODEC_CS42L42)) { |
| 208 | printk(BIOS_INFO, "enable CS42L42.\n"); |
| 209 | continue; |
| 210 | } |
| 211 | |
Eric Lai | 5c633dc | 2021-04-14 11:43:17 +0800 | [diff] [blame] | 212 | printk(BIOS_INFO, "%s has been disabled\n", audio_dev->chip_ops->name); |
Marco Chen | 07c80b2 | 2020-12-21 22:10:21 +0800 | [diff] [blame] | 213 | audio_dev->enabled = 0; |
| 214 | } |
| 215 | } |
| 216 | |
Aaron Durbin | 2fcc034 | 2018-07-25 08:06:21 -0600 | [diff] [blame] | 217 | void mainboard_devtree_update(struct device *dev) |
| 218 | { |
Furquan Shaikh | 617fcf3 | 2018-08-08 13:30:44 -0700 | [diff] [blame] | 219 | /* Apply common devtree updates. */ |
| 220 | wifi_device_update(); |
Marco Chen | 07c80b2 | 2020-12-21 22:10:21 +0800 | [diff] [blame] | 221 | audio_codec_device_update(); |
Furquan Shaikh | 617fcf3 | 2018-08-08 13:30:44 -0700 | [diff] [blame] | 222 | |
Aaron Durbin | 2fcc034 | 2018-07-25 08:06:21 -0600 | [diff] [blame] | 223 | /* Defer to variant for board-specific updates. */ |
| 224 | variant_update_devtree(dev); |
| 225 | } |
Wisley Chen | bd3568a | 2018-11-06 17:38:57 +0800 | [diff] [blame] | 226 | |
Karthikeyan Ramasubramanian | 02592ec | 2019-06-06 15:57:47 -0600 | [diff] [blame] | 227 | bool __weak variant_ext_usb_status(unsigned int port_type, unsigned int port_id) |
| 228 | { |
| 229 | /* All externally visible USB ports are present */ |
| 230 | return true; |
| 231 | } |
| 232 | |
| 233 | static void disable_unused_devices(void *unused) |
| 234 | { |
| 235 | usb_xhci_disable_unused(variant_ext_usb_status); |
| 236 | } |
| 237 | |
| 238 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, disable_unused_devices, NULL); |