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> |
Tim Wawrzynczak | d40a4c2 | 2021-02-25 13:14:49 -0700 | [diff] [blame] | 4 | #include <acpi/acpigen_pci.h> |
Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 5 | #include <console/console.h> |
| 6 | #include <device/device.h> |
Sumeet Pawnikar | a91d931 | 2021-08-30 23:19:38 +0530 | [diff] [blame] | 7 | #include <intelblocks/pmc_ipc.h> |
Sumeet Pawnikar | e0bff81 | 2021-09-23 21:49:29 +0530 | [diff] [blame] | 8 | #include <soc/pci_devs.h> |
Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 9 | #include "chip.h" |
Tim Wawrzynczak | 7f7c388 | 2021-04-09 12:15:21 -0600 | [diff] [blame] | 10 | #include "dptf.h" |
Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 11 | |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame] | 12 | /* Generic DPTF participants have a PTYP field to distinguish them */ |
| 13 | enum dptf_generic_participant_type { |
| 14 | DPTF_GENERIC_PARTICIPANT_TYPE_TSR = 0x3, |
Sumeet Pawnikar | e0bff81 | 2021-09-23 21:49:29 +0530 | [diff] [blame] | 15 | DPTF_GENERIC_PARTICIPANT_TYPE_TPCH = 0x5, |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame] | 16 | DPTF_GENERIC_PARTICIPANT_TYPE_CHARGER = 0xB, |
| 17 | }; |
| 18 | |
| 19 | #define DEFAULT_CHARGER_STR "Battery Charger" |
Sumeet Pawnikar | e0bff81 | 2021-09-23 21:49:29 +0530 | [diff] [blame] | 20 | #define DEFAULT_TPCH_STR "Intel PCH FIVR Participant" |
| 21 | |
| 22 | #define PMC_IPC_COMMAND_FIVR_SIZE 0x8 |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame] | 23 | |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame] | 24 | /* |
| 25 | * Helper method to determine if a device is "used" (called out anywhere as a source or a target |
| 26 | * of any policies, and therefore should be included in the ACPI tables. |
| 27 | */ |
| 28 | static bool is_participant_used(const struct drivers_intel_dptf_config *config, |
| 29 | enum dptf_participant participant) |
| 30 | { |
Tim Wawrzynczak | c41f7f1 | 2020-05-29 13:56:37 -0600 | [diff] [blame] | 31 | int i; |
| 32 | |
| 33 | /* Active? */ |
| 34 | for (i = 0; i < DPTF_MAX_ACTIVE_POLICIES; ++i) |
| 35 | if (config->policies.active[i].target == participant) |
| 36 | return true; |
| 37 | |
Tim Wawrzynczak | 7eb1136 | 2020-05-29 14:10:53 -0600 | [diff] [blame] | 38 | /* Passive? */ |
| 39 | for (i = 0; i < DPTF_MAX_PASSIVE_POLICIES; ++i) |
| 40 | if (config->policies.passive[i].source == participant || |
| 41 | config->policies.passive[i].target == participant) |
| 42 | return true; |
| 43 | |
Tim Wawrzynczak | 3a9cde9 | 2020-05-29 14:19:15 -0600 | [diff] [blame] | 44 | /* Critical? */ |
| 45 | for (i = 0; i < DPTF_MAX_CRITICAL_POLICIES; ++i) |
| 46 | if (config->policies.critical[i].source == participant) |
| 47 | return true; |
| 48 | |
Tim Wawrzynczak | c41f7f1 | 2020-05-29 13:56:37 -0600 | [diff] [blame] | 49 | /* Check fan as well (its use is implicit in the Active policy) */ |
| 50 | if (participant == DPTF_FAN && config->policies.active[0].target != DPTF_NONE) |
| 51 | return true; |
| 52 | |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame] | 53 | return false; |
| 54 | } |
| 55 | |
Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 56 | static const char *dptf_acpi_name(const struct device *dev) |
| 57 | { |
| 58 | return "DPTF"; |
| 59 | } |
| 60 | |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame] | 61 | static int get_STA_value(const struct drivers_intel_dptf_config *config, |
| 62 | enum dptf_participant participant) |
| 63 | { |
| 64 | return is_participant_used(config, participant) ? |
| 65 | ACPI_STATUS_DEVICE_ALL_ON : |
| 66 | ACPI_STATUS_DEVICE_ALL_OFF; |
| 67 | } |
| 68 | |
Tim Wawrzynczak | 7f7c388 | 2021-04-09 12:15:21 -0600 | [diff] [blame] | 69 | static void dptf_write_hid(bool is_eisa, const char *hid) |
| 70 | { |
| 71 | if (is_eisa) |
| 72 | acpigen_emit_eisaid(hid); |
| 73 | else |
| 74 | acpigen_write_string(hid); |
| 75 | } |
| 76 | |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 77 | /* Devices with GENERIC _HID (distinguished by PTYP) */ |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame] | 78 | static void dptf_write_generic_participant(const char *name, |
| 79 | enum dptf_generic_participant_type ptype, |
Tim Wawrzynczak | 7f7c388 | 2021-04-09 12:15:21 -0600 | [diff] [blame] | 80 | const char *str, int sta_val, |
| 81 | const struct dptf_platform_info *platform_info) |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame] | 82 | { |
| 83 | /* Auto-incrementing UID for generic participants */ |
| 84 | static int generic_uid = 0; |
| 85 | |
| 86 | acpigen_write_device(name); |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 87 | acpigen_write_name("_HID"); |
Tim Wawrzynczak | 7f7c388 | 2021-04-09 12:15:21 -0600 | [diff] [blame] | 88 | dptf_write_hid(platform_info->use_eisa_hids, platform_info->generic_hid); |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame] | 89 | |
| 90 | acpigen_write_name_integer("_UID", generic_uid++); |
| 91 | acpigen_write_STA(sta_val); |
| 92 | |
| 93 | if (str) |
| 94 | acpigen_write_name_string("_STR", str); |
| 95 | |
| 96 | acpigen_write_name_integer("PTYP", ptype); |
| 97 | |
| 98 | acpigen_pop_len(); /* Device */ |
| 99 | } |
| 100 | |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 101 | /* \_SB.PCI0.TCPU */ |
| 102 | static void write_tcpu(const struct device *pci_dev, |
| 103 | const struct drivers_intel_dptf_config *config) |
Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 104 | { |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 105 | /* DPTF CPU device - \_SB.PCI0.TCPU */ |
| 106 | acpigen_write_scope(TCPU_SCOPE); |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame] | 107 | acpigen_write_device("TCPU"); |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 108 | acpigen_write_ADR_pci_device(pci_dev); |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame] | 109 | acpigen_write_STA(get_STA_value(config, DPTF_CPU)); |
| 110 | acpigen_pop_len(); /* Device */ |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 111 | acpigen_pop_len(); /* TCPU Scope */ |
| 112 | } |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame] | 113 | |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 114 | /* \_SB.DPTF.TFN1 */ |
Tim Wawrzynczak | 7f7c388 | 2021-04-09 12:15:21 -0600 | [diff] [blame] | 115 | static void write_fan(const struct drivers_intel_dptf_config *config, |
| 116 | const struct dptf_platform_info *platform_info) |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 117 | { |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame] | 118 | acpigen_write_device("TFN1"); |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 119 | acpigen_write_name("_HID"); |
Tim Wawrzynczak | 7f7c388 | 2021-04-09 12:15:21 -0600 | [diff] [blame] | 120 | dptf_write_hid(platform_info->use_eisa_hids, platform_info->fan_hid); |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame] | 121 | acpigen_write_name_integer("_UID", 0); |
| 122 | acpigen_write_STA(get_STA_value(config, DPTF_FAN)); |
| 123 | acpigen_pop_len(); /* Device */ |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 124 | } |
| 125 | |
Sumeet R Pawnikar | 3657187 | 2021-05-11 20:05:20 +0530 | [diff] [blame] | 126 | /* \_SB.DPTF */ |
Sumeet Pawnikar | f96aa7a | 2021-07-05 21:09:53 +0530 | [diff] [blame] | 127 | static void write_imok(void) |
| 128 | { |
| 129 | acpigen_write_method("IMOK", 1); |
| 130 | /* Return (Arg0) */ |
| 131 | acpigen_emit_byte(RETURN_OP); |
| 132 | acpigen_emit_byte(ARG0_OP); |
| 133 | acpigen_write_method_end(); |
| 134 | } |
| 135 | /* \_SB.DPTF */ |
Sumeet R Pawnikar | 3657187 | 2021-05-11 20:05:20 +0530 | [diff] [blame] | 136 | static void write_oem_variables(const struct drivers_intel_dptf_config *config) |
| 137 | { |
| 138 | int i; |
| 139 | |
| 140 | acpigen_write_name("ODVX"); |
| 141 | acpigen_write_package(DPTF_OEM_VARIABLE_COUNT); |
| 142 | for (i = 0; i < DPTF_OEM_VARIABLE_COUNT; i++) |
| 143 | acpigen_write_dword(config->oem_data.oem_variables[i]); |
| 144 | acpigen_write_package_end(); |
| 145 | |
| 146 | /* |
| 147 | * Method (ODUP, 2) |
| 148 | * Arg0 = Index of ODVX to update |
| 149 | * Arg1 = Value to place in ODVX[Arg0] |
| 150 | */ |
| 151 | acpigen_write_method_serialized("ODUP", 2); |
| 152 | /* ODVX[Arg0] = Arg1 */ |
| 153 | acpigen_write_store(); |
| 154 | acpigen_emit_byte(ARG1_OP); |
| 155 | acpigen_emit_byte(INDEX_OP); |
| 156 | acpigen_emit_namestring("ODVX"); |
| 157 | acpigen_emit_byte(ARG0_OP); |
| 158 | acpigen_emit_byte(ZERO_OP); /* Ignore Index() Destination */ |
| 159 | acpigen_write_method_end(); |
| 160 | |
| 161 | /* |
| 162 | * Method (ODGT, 1) |
| 163 | * Arg0 = Index of ODVX to get |
| 164 | */ |
| 165 | acpigen_write_method_serialized("ODGT", 1); |
| 166 | /* Return (ODVX[Arg0]) */ |
| 167 | acpigen_emit_byte(RETURN_OP); |
| 168 | acpigen_emit_byte(DEREF_OP); |
| 169 | acpigen_emit_byte(INDEX_OP); |
| 170 | acpigen_emit_namestring("ODVX"); |
| 171 | acpigen_emit_byte(ARG0_OP); |
| 172 | acpigen_emit_byte(ZERO_OP); /* Ignore Index() Destination */ |
| 173 | acpigen_write_method_end(); |
| 174 | |
| 175 | /* Method (ODVP) { Return (ODVX) } */ |
| 176 | acpigen_write_method_serialized("ODVP", 0); |
| 177 | acpigen_emit_byte(RETURN_OP); |
| 178 | acpigen_emit_namestring("ODVX"); |
| 179 | acpigen_write_method_end(); |
| 180 | } |
| 181 | |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 182 | /* \_SB.DPTF.xxxx */ |
Tim Wawrzynczak | 7f7c388 | 2021-04-09 12:15:21 -0600 | [diff] [blame] | 183 | static void write_generic_devices(const struct drivers_intel_dptf_config *config, |
| 184 | const struct dptf_platform_info *platform_info) |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 185 | { |
| 186 | enum dptf_participant participant; |
| 187 | char name[ACPI_NAME_BUFFER_SIZE]; |
| 188 | int i; |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame] | 189 | |
| 190 | dptf_write_generic_participant("TCHG", DPTF_GENERIC_PARTICIPANT_TYPE_CHARGER, |
Tim Wawrzynczak | 7f7c388 | 2021-04-09 12:15:21 -0600 | [diff] [blame] | 191 | DEFAULT_CHARGER_STR, |
| 192 | get_STA_value(config, DPTF_CHARGER), |
| 193 | platform_info); |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame] | 194 | |
| 195 | for (i = 0, participant = DPTF_TEMP_SENSOR_0; i < 4; ++i, ++participant) { |
| 196 | snprintf(name, sizeof(name), "TSR%1d", i); |
| 197 | dptf_write_generic_participant(name, DPTF_GENERIC_PARTICIPANT_TYPE_TSR, |
Tim Wawrzynczak | 7f7c388 | 2021-04-09 12:15:21 -0600 | [diff] [blame] | 198 | NULL, get_STA_value(config, participant), |
| 199 | platform_info); |
Tim Wawrzynczak | ff2f6b2 | 2020-05-29 13:24:03 -0600 | [diff] [blame] | 200 | } |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 201 | } |
Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 202 | |
Sumeet Pawnikar | e0bff81 | 2021-09-23 21:49:29 +0530 | [diff] [blame] | 203 | static const char *get_pmc_ipcs_method(void) |
| 204 | { |
| 205 | const char *method = acpi_device_path_join( |
| 206 | pcidev_path_on_root(PCH_DEVFN_PMC), "IPCS"); |
| 207 | if (!method) { |
| 208 | printk(BIOS_ERR, "%s: Unable to find PMC device IPCS method\n", __func__); |
| 209 | return NULL; |
| 210 | } |
| 211 | return method; |
| 212 | } |
| 213 | |
| 214 | static void write_tpch_write_method(const char *tpch_write_method_name, |
Sumeet Pawnikar | a91d931 | 2021-08-30 23:19:38 +0530 | [diff] [blame] | 215 | unsigned int ipc_subcmd_ctrl_value) |
| 216 | { |
Sumeet Pawnikar | e0bff81 | 2021-09-23 21:49:29 +0530 | [diff] [blame] | 217 | /* Get IPCS method from the PMC device */ |
| 218 | const char *ipcs = get_pmc_ipcs_method(); |
| 219 | acpigen_write_method_serialized(tpch_write_method_name, 1); |
| 220 | acpigen_emit_namestring(ipcs); |
Sumeet Pawnikar | a91d931 | 2021-08-30 23:19:38 +0530 | [diff] [blame] | 221 | acpigen_write_integer(PMC_IPC_CMD_COMMAND_FIVR); |
| 222 | acpigen_write_integer(PMC_IPC_CMD_CMD_ID_FIVR_WRITE); |
Sumeet Pawnikar | e0bff81 | 2021-09-23 21:49:29 +0530 | [diff] [blame] | 223 | acpigen_write_integer(PMC_IPC_COMMAND_FIVR_SIZE); |
Sumeet Pawnikar | a91d931 | 2021-08-30 23:19:38 +0530 | [diff] [blame] | 224 | acpigen_write_integer(ipc_subcmd_ctrl_value); |
| 225 | acpigen_emit_byte(ARG0_OP); |
Sumeet Pawnikar | e0bff81 | 2021-09-23 21:49:29 +0530 | [diff] [blame] | 226 | acpigen_write_zero(); |
| 227 | acpigen_write_zero(); |
Sumeet Pawnikar | a91d931 | 2021-08-30 23:19:38 +0530 | [diff] [blame] | 228 | /* The reason for returning a value here is a W/A for the ESIF shell */ |
| 229 | acpigen_emit_byte(RETURN_OP); |
| 230 | acpigen_write_package(0); |
| 231 | acpigen_write_package_end(); |
| 232 | acpigen_write_method_end(); |
| 233 | } |
| 234 | |
Sumeet Pawnikar | e0bff81 | 2021-09-23 21:49:29 +0530 | [diff] [blame] | 235 | static void write_ppkg_package(const uint8_t i) |
| 236 | { |
| 237 | acpigen_write_store(); |
| 238 | acpigen_emit_byte(DEREF_OP); |
| 239 | acpigen_emit_byte(INDEX_OP); |
| 240 | acpigen_emit_byte(ARG0_OP); |
| 241 | acpigen_write_integer(i); |
| 242 | acpigen_emit_byte(ZERO_OP); |
| 243 | acpigen_emit_byte(INDEX_OP); |
| 244 | acpigen_emit_namestring("PPKG"); |
| 245 | acpigen_write_integer(i); |
| 246 | acpigen_emit_byte(ZERO_OP); |
| 247 | } |
| 248 | |
| 249 | /* |
| 250 | * Truncate Package received from IPC |
| 251 | * Arguments: |
| 252 | * Arg0: Package returned from the IPCS read call from the Pmc |
| 253 | * Return Value: |
| 254 | * Return Package with just the Status and ReadBuf0 |
| 255 | * Status returns 0 for success and 2 for device error |
| 256 | */ |
| 257 | static void write_pkgc_method(void) |
| 258 | { |
| 259 | acpigen_write_method_serialized("PKGC", 1); |
| 260 | acpigen_write_name("PPKG"); |
| 261 | acpigen_write_package(2); |
| 262 | acpigen_write_zero(); |
| 263 | acpigen_write_zero(); |
| 264 | acpigen_write_package_end(); |
| 265 | |
| 266 | write_ppkg_package(0); |
| 267 | write_ppkg_package(1); |
| 268 | |
| 269 | acpigen_write_return_namestr("PPKG"); |
| 270 | acpigen_write_method_end(); |
| 271 | } |
| 272 | |
| 273 | static void write_tpch_read_method(const char *tpch_read_method_name, |
| 274 | unsigned int ipc_subcmd_ctrl_value) |
| 275 | { |
| 276 | /* Get IPCS method from the PMC device */ |
| 277 | const char *ipcs = get_pmc_ipcs_method(); |
| 278 | acpigen_write_method_serialized(tpch_read_method_name, 0); |
| 279 | acpigen_write_store(); |
| 280 | acpigen_emit_namestring(ipcs); |
| 281 | acpigen_write_integer(PMC_IPC_CMD_COMMAND_FIVR); |
| 282 | acpigen_write_integer(PMC_IPC_CMD_CMD_ID_FIVR_READ); |
| 283 | acpigen_write_integer(PMC_IPC_COMMAND_FIVR_SIZE); |
| 284 | acpigen_write_integer(ipc_subcmd_ctrl_value); |
| 285 | acpigen_write_zero(); |
| 286 | acpigen_write_zero(); |
| 287 | acpigen_write_zero(); |
| 288 | acpigen_emit_byte(LOCAL0_OP); |
| 289 | |
| 290 | acpigen_write_store(); |
| 291 | acpigen_emit_namestring("PKGC"); |
| 292 | acpigen_emit_byte(LOCAL0_OP); |
| 293 | acpigen_emit_byte(LOCAL1_OP); |
| 294 | |
| 295 | acpigen_emit_byte(RETURN_OP); |
| 296 | acpigen_emit_byte(LOCAL1_OP); |
| 297 | acpigen_write_method_end(); |
| 298 | } |
| 299 | |
Sumeet Pawnikar | a91d931 | 2021-08-30 23:19:38 +0530 | [diff] [blame] | 300 | static void write_create_tpch(const struct dptf_platform_info *platform_info) |
| 301 | { |
| 302 | acpigen_write_device("TPCH"); |
| 303 | acpigen_write_name("_HID"); |
| 304 | dptf_write_hid(platform_info->use_eisa_hids, platform_info->tpch_device_hid); |
Sumeet Pawnikar | e0bff81 | 2021-09-23 21:49:29 +0530 | [diff] [blame] | 305 | acpigen_write_name_string("_STR", DEFAULT_TPCH_STR); |
| 306 | acpigen_write_name_integer("PTYP", DPTF_GENERIC_PARTICIPANT_TYPE_TPCH); |
Sumeet Pawnikar | a91d931 | 2021-08-30 23:19:38 +0530 | [diff] [blame] | 307 | acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON); |
| 308 | } |
| 309 | |
| 310 | static void write_tpch_methods(const struct dptf_platform_info *platform_info) |
| 311 | { |
| 312 | write_create_tpch(platform_info); |
| 313 | |
Sumeet Pawnikar | e0bff81 | 2021-09-23 21:49:29 +0530 | [diff] [blame] | 314 | const struct { |
| 315 | enum { READ, WRITE } type; |
| 316 | const char *method_name; |
| 317 | unsigned int subcommand; |
| 318 | } tpch_methods[] = { |
| 319 | { .type = WRITE, |
| 320 | .method_name = |
| 321 | platform_info->tpch_method_names.set_fivr_low_clock_method, |
| 322 | .subcommand = PMC_IPC_SUBCMD_RFI_CTRL0_LOGIC |
| 323 | }, |
| 324 | { .type = WRITE, |
| 325 | .method_name = |
| 326 | platform_info->tpch_method_names.set_fivr_high_clock_method, |
| 327 | .subcommand = PMC_IPC_SUBCMD_RFI_CTRL4_LOGIC |
| 328 | }, |
| 329 | { .type = READ, |
| 330 | .method_name = |
| 331 | platform_info->tpch_method_names.get_fivr_low_clock_method, |
| 332 | .subcommand = PMC_IPC_SUBCMD_RFI_CTRL0_LOGIC |
| 333 | }, |
| 334 | { .type = READ, |
| 335 | .method_name = |
| 336 | platform_info->tpch_method_names.get_fivr_high_clock_method, |
| 337 | .subcommand = PMC_IPC_SUBCMD_RFI_CTRL4_LOGIC |
| 338 | }, |
| 339 | { .type = READ, |
| 340 | .method_name = |
| 341 | platform_info->tpch_method_names.get_fivr_ssc_method, |
| 342 | .subcommand = PMC_IPC_SUBCMD_EMI_CTRL0_LOGIC |
| 343 | }, |
| 344 | { .type = READ, |
| 345 | .method_name = |
| 346 | platform_info->tpch_method_names.get_fivr_switching_fault_status, |
| 347 | .subcommand = PMC_IPC_SUBCMD_FFFC_FAULT_STATUS |
| 348 | }, |
| 349 | { .type = READ, |
| 350 | .method_name = |
| 351 | platform_info->tpch_method_names.get_fivr_switching_freq_mhz, |
| 352 | .subcommand = PMC_IPC_SUBCMD_FFFC_RFI_STATUS |
| 353 | }, |
| 354 | }; |
| 355 | |
| 356 | write_pkgc_method(); |
| 357 | for (size_t i = 0; i < ARRAY_SIZE(tpch_methods); i++) { |
| 358 | if (tpch_methods[i].type == READ) { |
| 359 | write_tpch_read_method(tpch_methods[i].method_name, |
| 360 | tpch_methods[i].subcommand); |
| 361 | } else if (tpch_methods[i].type == WRITE) { |
| 362 | write_tpch_write_method(tpch_methods[i].method_name, |
| 363 | tpch_methods[i].subcommand); |
| 364 | } |
| 365 | } |
Sumeet Pawnikar | a91d931 | 2021-08-30 23:19:38 +0530 | [diff] [blame] | 366 | |
| 367 | acpigen_write_device_end(); /* TPCH Device */ |
| 368 | } |
| 369 | |
| 370 | /* \_SB.DPTF - note: leaves the Scope open for child devices */ |
Tim Wawrzynczak | 7f7c388 | 2021-04-09 12:15:21 -0600 | [diff] [blame] | 371 | static void write_open_dptf_device(const struct device *dev, |
| 372 | const struct dptf_platform_info *platform_info) |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 373 | { |
| 374 | acpigen_write_scope("\\_SB"); |
| 375 | acpigen_write_device(acpi_device_name(dev)); |
| 376 | acpigen_write_name("_HID"); |
Tim Wawrzynczak | 7f7c388 | 2021-04-09 12:15:21 -0600 | [diff] [blame] | 377 | dptf_write_hid(platform_info->use_eisa_hids, platform_info->dptf_device_hid); |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 378 | acpigen_write_name_integer("_UID", 0); |
| 379 | acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON); |
| 380 | } |
| 381 | |
| 382 | /* Add minimal definitions of DPTF devices into the SSDT */ |
| 383 | static void write_device_definitions(const struct device *dev) |
| 384 | { |
Tim Wawrzynczak | 7f7c388 | 2021-04-09 12:15:21 -0600 | [diff] [blame] | 385 | const struct dptf_platform_info *platform_info = get_dptf_platform_info(); |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 386 | const struct drivers_intel_dptf_config *config; |
| 387 | struct device *parent; |
| 388 | |
| 389 | /* The CPU device gets an _ADR that matches the ACPI PCI address for 00:04.00 */ |
| 390 | parent = dev && dev->bus ? dev->bus->dev : NULL; |
| 391 | if (!parent || parent->path.type != DEVICE_PATH_PCI) { |
| 392 | printk(BIOS_ERR, "%s: DPTF objects must live under 00:04.0 PCI device\n", |
| 393 | __func__); |
| 394 | return; |
| 395 | } |
| 396 | |
| 397 | config = config_of(dev); |
| 398 | write_tcpu(parent, config); |
Tim Wawrzynczak | 7f7c388 | 2021-04-09 12:15:21 -0600 | [diff] [blame] | 399 | write_open_dptf_device(dev, platform_info); |
| 400 | write_fan(config, platform_info); |
Sumeet R Pawnikar | 3657187 | 2021-05-11 20:05:20 +0530 | [diff] [blame] | 401 | write_oem_variables(config); |
Sumeet Pawnikar | f96aa7a | 2021-07-05 21:09:53 +0530 | [diff] [blame] | 402 | write_imok(); |
Tim Wawrzynczak | 7f7c388 | 2021-04-09 12:15:21 -0600 | [diff] [blame] | 403 | write_generic_devices(config, platform_info); |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 404 | |
Sumeet Pawnikar | a91d931 | 2021-08-30 23:19:38 +0530 | [diff] [blame] | 405 | if (CONFIG(DRIVERS_INTEL_DPTF_SUPPORTS_TPCH)) |
| 406 | write_tpch_methods(platform_info); |
| 407 | |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 408 | acpigen_pop_len(); /* DPTF Device (write_open_dptf_device) */ |
Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 409 | acpigen_pop_len(); /* Scope */ |
| 410 | } |
| 411 | |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 412 | /* Emites policy definitions for each policy type */ |
| 413 | static void write_policies(const struct drivers_intel_dptf_config *config) |
| 414 | { |
| 415 | dptf_write_enabled_policies(config->policies.active, DPTF_MAX_ACTIVE_POLICIES, |
| 416 | config->policies.passive, DPTF_MAX_PASSIVE_POLICIES, |
| 417 | config->policies.critical, DPTF_MAX_CRITICAL_POLICIES); |
| 418 | |
| 419 | dptf_write_active_policies(config->policies.active, |
| 420 | DPTF_MAX_ACTIVE_POLICIES); |
| 421 | |
| 422 | dptf_write_passive_policies(config->policies.passive, |
| 423 | DPTF_MAX_PASSIVE_POLICIES); |
| 424 | |
| 425 | dptf_write_critical_policies(config->policies.critical, |
| 426 | DPTF_MAX_CRITICAL_POLICIES); |
| 427 | } |
| 428 | |
| 429 | /* Writes other static tables that are used by DPTF */ |
| 430 | static void write_controls(const struct drivers_intel_dptf_config *config) |
| 431 | { |
| 432 | dptf_write_charger_perf(config->controls.charger_perf, DPTF_MAX_CHARGER_PERF_STATES); |
| 433 | dptf_write_fan_perf(config->controls.fan_perf, DPTF_MAX_FAN_PERF_STATES); |
| 434 | dptf_write_power_limits(&config->controls.power_limits); |
| 435 | } |
| 436 | |
| 437 | /* Options to control the behavior of devices */ |
| 438 | static void write_options(const struct drivers_intel_dptf_config *config) |
| 439 | { |
| 440 | enum dptf_participant p; |
| 441 | int i; |
| 442 | |
| 443 | /* Fan options */ |
Tim Wawrzynczak | 3a658ad | 2020-07-24 18:58:24 -0600 | [diff] [blame] | 444 | dptf_write_scope(DPTF_FAN); |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 445 | dptf_write_fan_options(config->options.fan.fine_grained_control, |
| 446 | config->options.fan.step_size, |
| 447 | config->options.fan.low_speed_notify); |
Tim Wawrzynczak | 3a658ad | 2020-07-24 18:58:24 -0600 | [diff] [blame] | 448 | acpigen_pop_len(); /* Scope */ |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 449 | |
| 450 | /* TSR options */ |
| 451 | for (p = DPTF_TEMP_SENSOR_0, i = 0; p <= DPTF_TEMP_SENSOR_3; ++p, ++i) { |
Tim Wawrzynczak | c6a593b | 2020-07-14 13:19:03 -0600 | [diff] [blame] | 452 | if (is_participant_used(config, p) && (config->options.tsr[i].hysteresis || |
| 453 | config->options.tsr[i].desc)) { |
| 454 | dptf_write_scope(p); |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 455 | dptf_write_tsr_hysteresis(config->options.tsr[i].hysteresis); |
| 456 | dptf_write_STR(config->options.tsr[i].desc); |
Tim Wawrzynczak | c6a593b | 2020-07-14 13:19:03 -0600 | [diff] [blame] | 457 | acpigen_pop_len(); /* Scope */ |
Tim Wawrzynczak | 5212ece6 | 2020-07-16 11:54:04 -0600 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | /* Add custom tables and methods to SSDT */ |
| 463 | static void dptf_fill_ssdt(const struct device *dev) |
| 464 | { |
| 465 | struct drivers_intel_dptf_config *config = config_of(dev); |
| 466 | |
| 467 | write_device_definitions(dev); |
| 468 | write_policies(config); |
| 469 | write_controls(config); |
| 470 | write_options(config); |
| 471 | |
| 472 | printk(BIOS_INFO, DPTF_DEVICE_PATH ": %s at %s\n", dev->chip_ops->name, dev_path(dev)); |
| 473 | } |
| 474 | |
Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 475 | static struct device_operations dptf_ops = { |
| 476 | .read_resources = noop_read_resources, |
| 477 | .set_resources = noop_set_resources, |
| 478 | .acpi_name = dptf_acpi_name, |
| 479 | .acpi_fill_ssdt = dptf_fill_ssdt, |
Tim Wawrzynczak | 103bd5e | 2020-05-29 13:11:00 -0600 | [diff] [blame] | 480 | }; |
| 481 | |
| 482 | static void dptf_enable_dev(struct device *dev) |
| 483 | { |
| 484 | dev->ops = &dptf_ops; |
| 485 | } |
| 486 | |
| 487 | struct chip_operations drivers_intel_dptf_ops = { |
| 488 | CHIP_NAME("Intel DPTF") |
| 489 | .enable_dev = dptf_enable_dev, |
| 490 | }; |