| 1 |
|
| 2 |
|
| 3 |
#include <acpi/acpi.h> |
| 4 |
#include <baseboard/cbi_ssfc.h> |
| 5 |
#include <baseboard/variants.h> |
| 6 |
#include <boardid.h> |
| 7 |
#include <bootstate.h> |
| 8 |
#include <console/console.h> |
| 9 |
#include <device/device.h> |
| 10 |
#include <device/pci_def.h> |
| 11 |
#include <device/pci_ops.h> |
| 12 |
#include <drivers/i2c/generic/chip.h> |
| 13 |
#include <ec/google/chromeec/ec.h> |
| 14 |
#include <ec/ec.h> |
| 15 |
#include <intelblocks/xhci.h> |
| 16 |
#include <nhlt.h> |
| 17 |
#include <soc/cpu.h> |
| 18 |
#include <soc/gpio.h> |
| 19 |
#include <soc/nhlt.h> |
| 20 |
#include <soc/pci_devs.h> |
| 21 |
#include <stdint.h> |
| 22 |
#include <variant/ec.h> |
| 23 |
#include <variant/gpio.h> |
| 24 |
|
| 25 |
extern struct chip_operations drivers_i2c_generic_ops; |
| 26 |
extern struct chip_operations drivers_i2c_cs42l42_ops; |
| 27 |
extern struct chip_operations drivers_i2c_da7219_ops; |
| 28 |
|
| 29 |
static bool is_cnvi_held_in_reset(void) |
| 30 |
{ |
| 31 |
struct device *dev = pcidev_path_on_root(PCH_DEVFN_CNVI); |
| 32 |
uint32_t reg = pci_read_config32(dev, PCI_VENDOR_ID); |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
if (reg == 0xffffffff) |
| 39 |
return true; |
| 40 |
|
| 41 |
return false; |
| 42 |
} |
| 43 |
|
| 44 |
static void disable_wifi_wake(void) |
| 45 |
{ |
| 46 |
static const struct pad_config wifi_wake_gpio[] = { |
| 47 |
PAD_NC(GPIO_119, UP_20K), |
| 48 |
}; |
| 49 |
|
| 50 |
gpio_configure_pads(wifi_wake_gpio, ARRAY_SIZE(wifi_wake_gpio)); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
static void gpio_modification_by_ssfc(struct pad_config *table, size_t num) |
| 59 |
{ |
| 60 |
|
| 61 |
const struct pad_config rt5682_gpio_137 = PAD_CFG_GPI_APIC_IOS(GPIO_137, |
| 62 |
NONE, DEEP, EDGE_BOTH, INVERT, HIZCRx1, DISPUPD); |
| 63 |
enum ssfc_audio_codec codec = ssfc_get_audio_codec(); |
| 64 |
|
| 65 |
if (table == NULL || num == 0) |
| 66 |
return; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
if ((codec != SSFC_AUDIO_CODEC_RT5682) && |
| 75 |
(codec != SSFC_AUDIO_CODEC_RT5682_VS)) |
| 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 |
|
| 90 |
static void mainboard_init(void *chip_info) |
| 91 |
{ |
| 92 |
int boardid; |
| 93 |
const struct pad_config *base_pads; |
| 94 |
const struct pad_config *override_pads; |
| 95 |
size_t base_num, override_num; |
| 96 |
|
| 97 |
boardid = board_id(); |
| 98 |
printk(BIOS_INFO, "Board ID: %d\n", boardid); |
| 99 |
|
| 100 |
base_pads = baseboard_gpio_table(&base_num); |
| 101 |
override_pads = variant_override_gpio_table(&override_num); |
| 102 |
gpio_modification_by_ssfc((struct pad_config *)override_pads, |
| 103 |
override_num); |
| 104 |
|
| 105 |
gpio_configure_pads_with_override(base_pads, base_num, |
| 106 |
override_pads, override_num); |
| 107 |
|
| 108 |
if (!is_cnvi_held_in_reset()) |
| 109 |
disable_wifi_wake(); |
| 110 |
|
| 111 |
mainboard_ec_init(); |
| 112 |
} |
| 113 |
|
| 114 |
static unsigned long mainboard_write_acpi_tables( |
| 115 |
const struct device *device, unsigned long current, acpi_rsdp_t *rsdp) |
| 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 |
|
| 138 |
static void mainboard_enable(struct device *dev) |
| 139 |
{ |
| 140 |
dev->ops->write_acpi_tables = mainboard_write_acpi_tables; |
| 141 |
} |
| 142 |
|
| 143 |
struct chip_operations mainboard_ops = { |
| 144 |
.init = mainboard_init, |
| 145 |
.enable_dev = mainboard_enable, |
| 146 |
}; |
| 147 |
|
| 148 |
void __weak variant_update_devtree(struct device *dev) |
| 149 |
{ |
| 150 |
|
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
static 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 |
|
| 168 |
dev = pcidev_path_on_root(devfn); |
| 169 |
if (dev) |
| 170 |
dev->enabled = 0; |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
static 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)->downstream; |
| 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 |
struct drivers_i2c_generic_config *cfg = |
| 196 |
audio_dev->chip_info; |
| 197 |
|
| 198 |
if ((cfg != NULL && !strcmp(cfg->hid, "10EC5682")) && |
| 199 |
(codec == SSFC_AUDIO_CODEC_RT5682)) { |
| 200 |
printk(BIOS_INFO, "enable RT5682 VD.\n"); |
| 201 |
continue; |
| 202 |
} |
| 203 |
|
| 204 |
if ((cfg != NULL && !strcmp(cfg->hid, "10EC5682")) && |
| 205 |
(codec == SSFC_AUDIO_CODEC_RT5682_VS)) { |
| 206 |
cfg->hid = "RTL5682"; |
| 207 |
printk(BIOS_INFO, "enable RT5682 VS.\n"); |
| 208 |
continue; |
| 209 |
} |
| 210 |
|
| 211 |
if ((cfg != NULL && !strcmp(cfg->hid, "RTL5682")) && |
| 212 |
(codec == SSFC_AUDIO_CODEC_RT5682_VS)) { |
| 213 |
printk(BIOS_INFO, "enable RT5682 VS.\n"); |
| 214 |
continue; |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
if ((audio_dev->chip_ops == &drivers_i2c_cs42l42_ops) && |
| 219 |
(codec == SSFC_AUDIO_CODEC_CS42L42)) { |
| 220 |
printk(BIOS_INFO, "enable CS42L42.\n"); |
| 221 |
continue; |
| 222 |
} |
| 223 |
|
| 224 |
printk(BIOS_INFO, "%s has been disabled\n", audio_dev->chip_ops->name); |
| 225 |
audio_dev->enabled = 0; |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
void mainboard_devtree_update(struct device *dev) |
| 230 |
{ |
| 231 |
|
| 232 |
wifi_device_update(); |
| 233 |
audio_codec_device_update(); |
| 234 |
|
| 235 |
|
| 236 |
variant_update_devtree(dev); |
| 237 |
} |
| 238 |
|
| 239 |
bool __weak variant_ext_usb_status(unsigned int port_type, unsigned int port_id) |
| 240 |
{ |
| 241 |
|
| 242 |
return true; |
| 243 |
} |
| 244 |
|
| 245 |
static void disable_unused_devices(void *unused) |
| 246 |
{ |
| 247 |
usb_xhci_disable_unused(variant_ext_usb_status); |
| 248 |
} |
| 249 |
|
| 250 |
BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, disable_unused_devices, NULL); |