Sumeet Pawnikar | 698ee27 | 2021-08-09 16:08:40 +0530 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
| 3 | #include <acpi/acpi_device.h> |
| 4 | #include <baseboard/variants.h> |
| 5 | #include <console/console.h> |
| 6 | #include <device/pci_ids.h> |
| 7 | #include <device/pci_ops.h> |
Subrata Banik | 06a8922 | 2021-09-09 21:58:48 +0530 | [diff] [blame] | 8 | #include <soc/gpio_soc_defs.h> |
Sumeet Pawnikar | 698ee27 | 2021-08-09 16:08:40 +0530 | [diff] [blame] | 9 | #include <soc/pci_devs.h> |
Subrata Banik | 06a8922 | 2021-09-09 21:58:48 +0530 | [diff] [blame] | 10 | #include <soc/soc_chip.h> |
Kyösti Mälkki | be7692a | 2021-11-03 17:54:14 +0200 | [diff] [blame] | 11 | #include <string.h> |
Sumeet Pawnikar | 698ee27 | 2021-08-09 16:08:40 +0530 | [diff] [blame] | 12 | #include <drivers/intel/dptf/chip.h> |
Subrata Banik | 06a8922 | 2021-09-09 21:58:48 +0530 | [diff] [blame] | 13 | #include "board_id.h" |
Sumeet Pawnikar | e06e43a | 2021-09-30 09:38:49 +0530 | [diff] [blame] | 14 | #include <intelblocks/power_limit.h> |
Sumeet Pawnikar | 698ee27 | 2021-08-09 16:08:40 +0530 | [diff] [blame] | 15 | |
| 16 | const struct cpu_power_limits limits[] = { |
Sumeet Pawnikar | e415df9 | 2021-09-30 09:51:42 +0530 | [diff] [blame] | 17 | /* SKU_ID, TDP (Watts), pl1_min, pl1_max, pl2_min, pl2_max, PL4 */ |
Sumeet Pawnikar | 698ee27 | 2021-08-09 16:08:40 +0530 | [diff] [blame] | 18 | /* PL2 values are for performance configuration */ |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 19 | { PCI_DID_INTEL_ADL_P_ID_7, 15, 3000, 15000, 55000, 55000, 123000 }, |
| 20 | { PCI_DID_INTEL_ADL_P_ID_6, 15, 3000, 15000, 55000, 55000, 123000 }, |
| 21 | { PCI_DID_INTEL_ADL_P_ID_5, 28, 4000, 28000, 64000, 64000, 140000 }, |
| 22 | { PCI_DID_INTEL_ADL_P_ID_3, 28, 4000, 28000, 64000, 64000, 140000 }, |
| 23 | { PCI_DID_INTEL_ADL_P_ID_3, 45, 5000, 45000, 115000, 115000, 215000 }, |
Vidya Gopalakrishnan | 7870a35 | 2022-05-22 10:42:39 +0530 | [diff] [blame] | 24 | { PCI_DID_INTEL_ADL_N_ID_1, 15, 3000, 15000, 35000, 35000, 83000 }, |
| 25 | { PCI_DID_INTEL_ADL_N_ID_2, 6, 3000, 6000, 25000, 25000, 78000 }, |
| 26 | { PCI_DID_INTEL_ADL_N_ID_3, 6, 3000, 6000, 25000, 25000, 78000 }, |
| 27 | { PCI_DID_INTEL_ADL_N_ID_4, 6, 3000, 6000, 25000, 25000, 78000 }, |
Sean Rhodes | 00b81ad | 2024-02-13 20:44:52 +0000 | [diff] [blame] | 28 | { PCI_DID_INTEL_ADL_N_ID_5, 6, 3000, 6000, 25000, 25000, 78000 }, |
Sumeet Pawnikar | 698ee27 | 2021-08-09 16:08:40 +0530 | [diff] [blame] | 29 | }; |
| 30 | |
Furquan Shaikh | 4f5e8e0 | 2021-09-22 23:38:17 -0700 | [diff] [blame] | 31 | WEAK_DEV_PTR(dptf_policy); |
Sumeet Pawnikar | 698ee27 | 2021-08-09 16:08:40 +0530 | [diff] [blame] | 32 | void variant_update_power_limits(void) |
| 33 | { |
Furquan Shaikh | 4f5e8e0 | 2021-09-22 23:38:17 -0700 | [diff] [blame] | 34 | const struct device *policy_dev = DEV_PTR(dptf_policy); |
Sumeet Pawnikar | 698ee27 | 2021-08-09 16:08:40 +0530 | [diff] [blame] | 35 | if (!policy_dev) |
| 36 | return; |
| 37 | |
Furquan Shaikh | 4f5e8e0 | 2021-09-22 23:38:17 -0700 | [diff] [blame] | 38 | struct drivers_intel_dptf_config *config = config_of(policy_dev); |
Sumeet Pawnikar | 698ee27 | 2021-08-09 16:08:40 +0530 | [diff] [blame] | 39 | |
| 40 | uint16_t mchid = pci_s_read_config16(PCI_DEV(0, 0, 0), PCI_DEVICE_ID); |
| 41 | |
Sumeet Pawnikar | e06e43a | 2021-09-30 09:38:49 +0530 | [diff] [blame] | 42 | u8 tdp = get_cpu_tdp(); |
| 43 | |
Sumeet Pawnikar | 698ee27 | 2021-08-09 16:08:40 +0530 | [diff] [blame] | 44 | for (size_t i = 0; i < ARRAY_SIZE(limits); i++) { |
Sumeet Pawnikar | e06e43a | 2021-09-30 09:38:49 +0530 | [diff] [blame] | 45 | if (mchid == limits[i].mchid && tdp == limits[i].cpu_tdp) { |
Sumeet Pawnikar | 698ee27 | 2021-08-09 16:08:40 +0530 | [diff] [blame] | 46 | struct dptf_power_limits *settings = &config->controls.power_limits; |
Sumeet Pawnikar | e415df9 | 2021-09-30 09:51:42 +0530 | [diff] [blame] | 47 | config_t *conf = config_of_soc(); |
| 48 | struct soc_power_limits_config *soc_config = conf->power_limits_config; |
Sumeet Pawnikar | 698ee27 | 2021-08-09 16:08:40 +0530 | [diff] [blame] | 49 | settings->pl1.min_power = limits[i].pl1_min_power; |
| 50 | settings->pl1.max_power = limits[i].pl1_max_power; |
| 51 | settings->pl2.min_power = limits[i].pl2_min_power; |
| 52 | settings->pl2.max_power = limits[i].pl2_max_power; |
Sumeet Pawnikar | e415df9 | 2021-09-30 09:51:42 +0530 | [diff] [blame] | 53 | soc_config->tdp_pl4 = DIV_ROUND_UP(limits[i].pl4_power, |
| 54 | MILLIWATTS_TO_WATTS); |
| 55 | printk(BIOS_INFO, "Overriding power limits PL1 (%u, %u) PL2 (%u, %u) PL4 (%u)\n", |
Sumeet Pawnikar | 698ee27 | 2021-08-09 16:08:40 +0530 | [diff] [blame] | 56 | limits[i].pl1_min_power, |
| 57 | limits[i].pl1_max_power, |
| 58 | limits[i].pl2_min_power, |
Sumeet Pawnikar | e415df9 | 2021-09-30 09:51:42 +0530 | [diff] [blame] | 59 | limits[i].pl2_max_power, |
| 60 | limits[i].pl4_power); |
Sumeet Pawnikar | 698ee27 | 2021-08-09 16:08:40 +0530 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
Subrata Banik | 06a8922 | 2021-09-09 21:58:48 +0530 | [diff] [blame] | 65 | static const struct typec_aux_bias_pads pad_config = { GPP_E23, GPP_E22 }; |
| 66 | |
| 67 | static const struct board_id_iom_port_config { |
| 68 | int board_id; |
| 69 | enum typec_port_index port; |
| 70 | } port_config[] = { |
| 71 | { ADL_P_LP4_1, TYPE_C_PORT_2 }, |
| 72 | { ADL_P_LP4_2, TYPE_C_PORT_2 }, |
| 73 | { ADL_P_DDR4_1, TYPE_C_PORT_2 }, |
| 74 | { ADL_P_DDR4_2, TYPE_C_PORT_2 }, |
| 75 | { ADL_P_LP5_1, TYPE_C_PORT_2 }, |
| 76 | { ADL_P_LP5_2, TYPE_C_PORT_2 }, |
| 77 | { ADL_M_LP4, TYPE_C_PORT_1 }, |
| 78 | { ADL_M_LP5, TYPE_C_PORT_0 }, |
| 79 | }; |
| 80 | |
| 81 | static void variant_update_typec_init_config(void) |
| 82 | { |
| 83 | /* Skip filling aux bias gpio pads for Windows SKUs */ |
Sean Rhodes | 9c40215 | 2024-02-19 11:45:26 +0000 | [diff] [blame^] | 84 | if (!(CONFIG(BOARD_INTEL_ADLRVP_P_EXT_EC) || CONFIG(BOARD_INTEL_ADLRVP_RPL_EXT_EC))) |
Subrata Banik | 06a8922 | 2021-09-09 21:58:48 +0530 | [diff] [blame] | 85 | return; |
| 86 | |
| 87 | config_t *config = config_of_soc(); |
| 88 | int board_id = get_board_id(); |
| 89 | for (int i = 0; i < ARRAY_SIZE(port_config); i++) { |
| 90 | if (board_id != port_config[i].board_id) |
| 91 | continue; |
| 92 | |
| 93 | memcpy(&config->typec_aux_bias_pads[port_config[i].port], &pad_config, |
| 94 | sizeof(pad_config)); |
| 95 | } |
| 96 | } |
| 97 | |
Sumeet Pawnikar | 698ee27 | 2021-08-09 16:08:40 +0530 | [diff] [blame] | 98 | void variant_devtree_update(void) |
| 99 | { |
| 100 | variant_update_power_limits(); |
Subrata Banik | 06a8922 | 2021-09-09 21:58:48 +0530 | [diff] [blame] | 101 | variant_update_typec_init_config(); |
Sumeet Pawnikar | 698ee27 | 2021-08-09 16:08:40 +0530 | [diff] [blame] | 102 | } |