Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpigen.h> |
| 4 | #include <console/console.h> |
| 5 | #include <device/device.h> |
| 6 | #include "chip.h" |
| 7 | |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame^] | 8 | enum dptf_participant { |
| 9 | DPTF_NONE, |
| 10 | DPTF_CPU, |
| 11 | DPTF_CHARGER, |
| 12 | DPTF_FAN, |
| 13 | DPTF_TEMP_SENSOR_0, |
| 14 | DPTF_TEMP_SENSOR_1, |
| 15 | DPTF_TEMP_SENSOR_2, |
| 16 | DPTF_TEMP_SENSOR_3, |
| 17 | DPTF_PARTICIPANT_COUNT, |
| 18 | }; |
| 19 | |
| 20 | /* Generic DPTF participants have a PTYP field to distinguish them */ |
| 21 | enum dptf_generic_participant_type { |
| 22 | DPTF_GENERIC_PARTICIPANT_TYPE_TSR = 0x3, |
| 23 | DPTF_GENERIC_PARTICIPANT_TYPE_CHARGER = 0xB, |
| 24 | }; |
| 25 | |
| 26 | #define DEFAULT_CHARGER_STR "Battery Charger" |
| 27 | |
| 28 | #define DPTF_DEVICE_HID_EISAID "INT3400" |
| 29 | #define GENERIC_HID_EISAID "INT3403" |
| 30 | #define FAN_HID_EISAID "INT3404" |
| 31 | |
| 32 | #define DPTF_DEVICE_HID "INTC1040" |
| 33 | #define GENERIC_HID "INTC1043" |
| 34 | #define FAN_HID "INTC1044" |
| 35 | |
| 36 | /* |
| 37 | * Helper method to determine if a device is "used" (called out anywhere as a source or a target |
| 38 | * of any policies, and therefore should be included in the ACPI tables. |
| 39 | */ |
| 40 | static bool is_participant_used(const struct drivers_intel_dptf_config *config, |
| 41 | enum dptf_participant participant) |
| 42 | { |
| 43 | return false; |
| 44 | } |
| 45 | |
Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 46 | static const char *dptf_acpi_name(const struct device *dev) |
| 47 | { |
| 48 | return "DPTF"; |
| 49 | } |
| 50 | |
| 51 | /* Add custom tables and methods to SSDT */ |
| 52 | static void dptf_fill_ssdt(const struct device *dev) |
| 53 | { |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame^] | 54 | struct drivers_intel_dptf_config *config = config_of(dev); |
Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 55 | |
| 56 | printk(BIOS_INFO, "\\_SB.DPTF: %s at %s\n", dev->chip_ops->name, dev_path(dev)); |
| 57 | } |
| 58 | |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame^] | 59 | static int get_STA_value(const struct drivers_intel_dptf_config *config, |
| 60 | enum dptf_participant participant) |
| 61 | { |
| 62 | return is_participant_used(config, participant) ? |
| 63 | ACPI_STATUS_DEVICE_ALL_ON : |
| 64 | ACPI_STATUS_DEVICE_ALL_OFF; |
| 65 | } |
| 66 | |
| 67 | static void dptf_write_generic_participant(const char *name, |
| 68 | enum dptf_generic_participant_type ptype, |
| 69 | const char *str, int sta_val) |
| 70 | { |
| 71 | /* Auto-incrementing UID for generic participants */ |
| 72 | static int generic_uid = 0; |
| 73 | |
| 74 | acpigen_write_device(name); |
| 75 | |
| 76 | if (CONFIG(DPTF_USE_EISA_HID)) { |
| 77 | acpigen_write_name("_HID"); |
| 78 | acpigen_emit_eisaid(GENERIC_HID_EISAID); |
| 79 | } else { |
| 80 | acpigen_write_name_string("_HID", GENERIC_HID); |
| 81 | } |
| 82 | |
| 83 | acpigen_write_name_integer("_UID", generic_uid++); |
| 84 | acpigen_write_STA(sta_val); |
| 85 | |
| 86 | if (str) |
| 87 | acpigen_write_name_string("_STR", str); |
| 88 | |
| 89 | acpigen_write_name_integer("PTYP", ptype); |
| 90 | |
| 91 | acpigen_pop_len(); /* Device */ |
| 92 | } |
| 93 | |
Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 94 | /* Add static definitions of DPTF devices into the DSDT */ |
| 95 | static void dptf_inject_dsdt(const struct device *dev) |
| 96 | { |
| 97 | const struct drivers_intel_dptf_config *config; |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame^] | 98 | enum dptf_participant participant; |
| 99 | struct device *parent; |
| 100 | char name[5]; |
| 101 | int i; |
Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 102 | |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame^] | 103 | /* The CPU device gets an _ADR that matches the ACPI PCI address for 00:04.00 */ |
| 104 | parent = dev && dev->bus ? dev->bus->dev : NULL; |
| 105 | if (!parent || parent->path.type != DEVICE_PATH_PCI) { |
| 106 | printk(BIOS_ERR, "%s: DPTF objects must live under 00:04.0 PCI device\n", |
| 107 | __func__); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | config = config_of(dev); |
Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 112 | acpigen_write_scope("\\_SB"); |
| 113 | |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame^] | 114 | /* DPTF CPU device - \_SB.TCPU */ |
| 115 | acpigen_write_device("TCPU"); |
| 116 | acpigen_write_ADR_pci_device(parent); |
| 117 | acpigen_write_STA(get_STA_value(config, DPTF_CPU)); |
| 118 | acpigen_pop_len(); /* Device */ |
| 119 | |
| 120 | /* Toplevel DPTF device - \_SB.DPTF*/ |
Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 121 | acpigen_write_device(acpi_device_name(dev)); |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame^] | 122 | if (CONFIG(DPTF_USE_EISA_HID)) { |
| 123 | acpigen_write_name("_HID"); |
| 124 | acpigen_emit_eisaid(DPTF_DEVICE_HID_EISAID); |
| 125 | } else { |
| 126 | acpigen_write_name_string("_HID", DPTF_DEVICE_HID); |
| 127 | } |
| 128 | |
Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 129 | acpigen_write_name_integer("_UID", 0); |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame^] | 130 | acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON); |
| 131 | |
| 132 | /* |
| 133 | * The following devices live underneath \_SB.DPTF: |
| 134 | * - Fan, \_SB.DPTF.TFN1 |
| 135 | * - Charger, \_SB.DPTF.TCHG |
| 136 | * - Temperature Sensors, \_SB.DPTF.TSRn |
| 137 | */ |
| 138 | |
| 139 | acpigen_write_device("TFN1"); |
| 140 | if (CONFIG(DPTF_USE_EISA_HID)) { |
| 141 | acpigen_write_name("_HID"); |
| 142 | acpigen_emit_eisaid(FAN_HID_EISAID); |
| 143 | } else { |
| 144 | acpigen_write_name_string("_HID", FAN_HID); |
| 145 | } |
| 146 | |
| 147 | acpigen_write_name_integer("_UID", 0); |
| 148 | acpigen_write_STA(get_STA_value(config, DPTF_FAN)); |
| 149 | acpigen_pop_len(); /* Device */ |
| 150 | |
| 151 | dptf_write_generic_participant("TCHG", DPTF_GENERIC_PARTICIPANT_TYPE_CHARGER, |
| 152 | DEFAULT_CHARGER_STR, get_STA_value(config, |
| 153 | DPTF_CHARGER)); |
| 154 | |
| 155 | for (i = 0, participant = DPTF_TEMP_SENSOR_0; i < 4; ++i, ++participant) { |
| 156 | snprintf(name, sizeof(name), "TSR%1d", i); |
| 157 | dptf_write_generic_participant(name, DPTF_GENERIC_PARTICIPANT_TYPE_TSR, |
| 158 | NULL, get_STA_value(config, participant)); |
| 159 | } |
Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 160 | |
| 161 | acpigen_pop_len(); /* DPTF Device */ |
| 162 | acpigen_pop_len(); /* Scope */ |
| 163 | } |
| 164 | |
| 165 | static struct device_operations dptf_ops = { |
| 166 | .read_resources = noop_read_resources, |
| 167 | .set_resources = noop_set_resources, |
| 168 | .acpi_name = dptf_acpi_name, |
| 169 | .acpi_fill_ssdt = dptf_fill_ssdt, |
| 170 | .acpi_inject_dsdt = dptf_inject_dsdt, |
| 171 | }; |
| 172 | |
| 173 | static void dptf_enable_dev(struct device *dev) |
| 174 | { |
| 175 | dev->ops = &dptf_ops; |
| 176 | } |
| 177 | |
| 178 | struct chip_operations drivers_intel_dptf_ops = { |
| 179 | CHIP_NAME("Intel DPTF") |
| 180 | .enable_dev = dptf_enable_dev, |
| 181 | }; |