Add an interface to obtain hwmon energy values. This is used by selftest to verify power consumption
v2 : use i915_hwmon prefix (Anshuman) v3 : re-use is_visible function of energy to remove redundant code (Anshuman) Signed-off-by: Riana Tauro <riana.ta...@intel.com> --- drivers/gpu/drm/i915/i915_hwmon.c | 17 +++++++++++++++++ drivers/gpu/drm/i915/i915_hwmon.h | 1 + 2 files changed, 18 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_hwmon.c b/drivers/gpu/drm/i915/i915_hwmon.c index c588a17f97e9..d45d1cbce886 100644 --- a/drivers/gpu/drm/i915/i915_hwmon.c +++ b/drivers/gpu/drm/i915/i915_hwmon.c @@ -442,6 +442,23 @@ hwm_energy_read(struct hwm_drvdata *ddat, u32 attr, long *val) } } +/* + * i915_hwmon_get_energy - obtains energy value + * Returns: 0 on success or a negative error code + */ +int +i915_hwmon_get_energy(struct drm_i915_private *i915, long *energy) +{ + struct i915_hwmon *hwmon = i915->hwmon; + struct hwm_drvdata *ddat = &hwmon->ddat; + + if (!hwm_energy_is_visible(ddat, hwmon_energy_input)) + return -EOPNOTSUPP; + + hwm_energy(ddat, energy); + return 0; +} + static umode_t hwm_curr_is_visible(const struct hwm_drvdata *ddat, u32 attr) { diff --git a/drivers/gpu/drm/i915/i915_hwmon.h b/drivers/gpu/drm/i915/i915_hwmon.h index 7ca9cf2c34c9..a6c8efeb868d 100644 --- a/drivers/gpu/drm/i915/i915_hwmon.h +++ b/drivers/gpu/drm/i915/i915_hwmon.h @@ -12,6 +12,7 @@ struct drm_i915_private; #if IS_REACHABLE(CONFIG_HWMON) void i915_hwmon_register(struct drm_i915_private *i915); void i915_hwmon_unregister(struct drm_i915_private *i915); +int i915_hwmon_get_energy(struct drm_i915_private *i915, long *energy); #else static inline void i915_hwmon_register(struct drm_i915_private *i915) { }; static inline void i915_hwmon_unregister(struct drm_i915_private *i915) { }; -- 2.25.1