platform/x86/intel/pmc: Add PSON residency counter
authorRajvi Jingar <rajvi.jingar@linux.intel.com>
Tue, 19 Dec 2023 04:22:10 +0000 (20:22 -0800)
committerHans de Goede <hdegoede@redhat.com>
Tue, 19 Dec 2023 15:48:17 +0000 (16:48 +0100)
Tiger Lake platform onwards, devices have the capability to track the
duration of time that their Power Supply Units (PSUs) are turned off
during S0ix. This patch adds a debugfs file `pson_residency_usec` to
provide access to this counter.

Signed-off-by: Michael Bottini <michael.a.bottini@linux.intel.com>
Signed-off-by: Rajvi Jingar <rajvi.jingar@linux.intel.com>
Signed-off-by: David E. Box <david.e.box@linux.intel.com>
Link: https://lore.kernel.org/r/20231219042216.2592029-2-rajvi.jingar@linux.intel.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
drivers/platform/x86/intel/pmc/core.c
drivers/platform/x86/intel/pmc/core.h

index 983e3a8f49100233f7949e0e171345509e0d3b97..91e5e500eb416d633fa60587189801a48ca7eae1 100644 (file)
@@ -208,6 +208,20 @@ static int pmc_core_dev_state_get(void *data, u64 *val)
 
 DEFINE_DEBUGFS_ATTRIBUTE(pmc_core_dev_state, pmc_core_dev_state_get, NULL, "%llu\n");
 
+static int pmc_core_pson_residency_get(void *data, u64 *val)
+{
+       struct pmc *pmc = data;
+       const struct pmc_reg_map *map = pmc->map;
+       u32 value;
+
+       value = pmc_core_reg_read(pmc, map->pson_residency_offset);
+       *val = (u64)value * map->pson_residency_counter_step;
+
+       return 0;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(pmc_core_pson_residency, pmc_core_pson_residency_get, NULL, "%llu\n");
+
 static int pmc_core_check_read_lock_bit(struct pmc *pmc)
 {
        u32 value;
@@ -1092,6 +1106,24 @@ int get_primary_reg_base(struct pmc *pmc)
        return 0;
 }
 
+static bool pmc_core_is_pson_residency_enabled(struct pmc_dev *pmcdev)
+{
+       struct platform_device *pdev = pmcdev->pdev;
+       struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
+       u8 val;
+
+       if (!adev)
+               return false;
+
+       if (fwnode_property_read_u8(acpi_fwnode_handle(adev),
+                                   "intel-cec-pson-switching-enabled-in-s0",
+                                   &val))
+               return false;
+
+       return val == 1;
+}
+
+
 static void pmc_core_dbgfs_unregister(struct pmc_dev *pmcdev)
 {
        debugfs_remove_recursive(pmcdev->dbgfs_dir);
@@ -1162,6 +1194,11 @@ static void pmc_core_dbgfs_register(struct pmc_dev *pmcdev)
                                    &pmc_core_substate_req_regs_fops);
        }
 
+       if (primary_pmc->map->pson_residency_offset && pmc_core_is_pson_residency_enabled(pmcdev)) {
+               debugfs_create_file("pson_residency_usec", 0444,
+                                   pmcdev->dbgfs_dir, primary_pmc, &pmc_core_pson_residency);
+       }
+
        if (pmcdev->has_die_c6) {
                debugfs_create_file("die_c6_us_show", 0444,
                                    pmcdev->dbgfs_dir, pmcdev,
index 6d7673145f90ec92c278e56c3e9dedbe82cfaba6..91cb34a6505cc6791a5a2a42b7a850e9f66ff1a4 100644 (file)
@@ -323,6 +323,8 @@ struct pmc_reg_map {
        const u32 lpm_live_status_offset;
        const u32 etr3_offset;
        const u8  *lpm_reg_index;
+       const u32 pson_residency_offset;
+       const u32 pson_residency_counter_step;
 };
 
 /**