| 1 |
|
| 2 |
|
| 3 |
#include <acpi/acpi_device.h> |
| 4 |
#include <acpi/acpigen.h> |
| 5 |
#include <acpi/acpigen_pci.h> |
| 6 |
#include <assert.h> |
| 7 |
#include <console/console.h> |
| 8 |
#include <device/device.h> |
| 9 |
#include <device/pci.h> |
| 10 |
#include <device/pci_ids.h> |
| 11 |
#include <device/pci_ops.h> |
| 12 |
#include "chip.h" |
| 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 |
static void pcie_rtd3_device_acpi_fill_ssdt(const struct device *dev) |
| 74 |
{ |
| 75 |
const struct drivers_pcie_rtd3_device_config *config = config_of(dev); |
| 76 |
|
| 77 |
struct acpi_gpio reset_gpio = config->reset_gpio; |
| 78 |
struct acpi_gpio enable_gpio = config->enable_gpio; |
| 79 |
const struct acpi_power_res_params power_res_params = { |
| 80 |
.reset_gpio = &reset_gpio, |
| 81 |
.reset_delay_ms = config->reset_delay_ms, |
| 82 |
.reset_off_delay_ms = config->reset_off_delay_ms, |
| 83 |
.enable_gpio = &enable_gpio, |
| 84 |
.enable_delay_ms = config->enable_delay_ms, |
| 85 |
.enable_off_delay_ms = config->enable_off_delay_ms, |
| 86 |
.use_gpio_for_status = true, |
| 87 |
}; |
| 88 |
const char *scope = acpi_device_scope(dev); |
| 89 |
const char *name = acpi_device_name(dev); |
| 90 |
|
| 91 |
assert(name); |
| 92 |
assert(scope); |
| 93 |
|
| 94 |
printk(BIOS_INFO, "%s.%s: Enable RTD3 for %s (%s)\n", scope, name, dev_path(dev), |
| 95 |
dev->chip_ops->name); |
| 96 |
|
| 97 |
acpigen_write_scope(scope); |
| 98 |
acpigen_write_device(acpi_device_name(dev)); |
| 99 |
|
| 100 |
acpi_device_add_power_res(&power_res_params); |
| 101 |
|
| 102 |
acpigen_write_ADR_pci_device(dev); |
| 103 |
acpigen_write_STA(acpi_device_status(dev)); |
| 104 |
|
| 105 |
|
| 106 |
if ((dev->class >> 16) == PCI_BASE_CLASS_STORAGE) { |
| 107 |
acpi_device_add_storage_d3_enable(NULL); |
| 108 |
|
| 109 |
printk(BIOS_INFO, "%s.%s: Added StorageD3Enable property\n", scope, name); |
| 110 |
} |
| 111 |
|
| 112 |
acpigen_write_device_end(); |
| 113 |
acpigen_write_scope_end(); |
| 114 |
|
| 115 |
|
| 116 |
pci_rom_ssdt(dev); |
| 117 |
} |
| 118 |
|
| 119 |
static const char *pcie_rtd3_device_acpi_name(const struct device *dev) |
| 120 |
{ |
| 121 |
const struct drivers_pcie_rtd3_device_config *config = config_of(dev); |
| 122 |
|
| 123 |
return config->name; |
| 124 |
} |
| 125 |
|
| 126 |
static struct device_operations pcie_rtd3_device_ops = { |
| 127 |
.read_resources = pci_dev_read_resources, |
| 128 |
.set_resources = pci_dev_set_resources, |
| 129 |
.enable_resources = pci_dev_enable_resources, |
| 130 |
.init = pci_dev_init, |
| 131 |
.ops_pci = &pci_dev_ops_pci, |
| 132 |
.write_acpi_tables = pci_rom_write_acpi_tables, |
| 133 |
.acpi_fill_ssdt = pcie_rtd3_device_acpi_fill_ssdt, |
| 134 |
.acpi_name = pcie_rtd3_device_acpi_name, |
| 135 |
}; |
| 136 |
|
| 137 |
static void pcie_rtd3_device_enable(struct device *dev) |
| 138 |
{ |
| 139 |
struct drivers_pcie_rtd3_device_config *config = dev ? dev->chip_info : NULL; |
| 140 |
|
| 141 |
if (!config) |
| 142 |
return; |
| 143 |
|
| 144 |
if (dev->path.type != DEVICE_PATH_PCI) { |
| 145 |
printk(BIOS_ERR, "%s: Invalid device type\n", dev_path(dev)); |
| 146 |
return; |
| 147 |
} |
| 148 |
|
| 149 |
dev->ops = &pcie_rtd3_device_ops; |
| 150 |
} |
| 151 |
|
| 152 |
struct chip_operations drivers_pcie_rtd3_device_ops = { |
| 153 |
.name = "PCIe Device w/ Runtime D3", |
| 154 |
.enable_dev = pcie_rtd3_device_enable |
| 155 |
}; |