[PATCH v5] drm/i915/hwmon: expose fan speed
Raag Jadav
raag.jadav at intel.com
Tue Aug 13 05:45:19 UTC 2024
On Mon, Aug 12, 2024 at 04:15:14PM +0300, Andy Shevchenko wrote:
> On Mon, Aug 12, 2024 at 01:45:38PM +0530, Raag Jadav wrote:
> > Add hwmon support for fan1_input attribute, which will expose fan speed
> > in RPM. With this in place we can monitor fan speed using lm-sensors tool.
> >
> > $ sensors
> > i915-pci-0300
> > Adapter: PCI adapter
> > in0: 653.00 mV
> > fan1: 3833 RPM
> > power1: N/A (max = 43.00 W)
> > energy1: 32.02 kJ
>
> ...
>
> > +static int
> > +hwm_fan_read(struct hwm_drvdata *ddat, u32 attr, long *val)
> > +{
> > + struct i915_hwmon *hwmon = ddat->hwmon;
> > + struct hwm_fan_info *fi = &ddat->fi;
> > + u64 rotations, time_now, time;
> > + intel_wakeref_t wakeref;
> > + u32 reg_val, pulses;
> > + int ret = 0;
> > +
> > + if (attr != hwmon_fan_input)
> > + return -EOPNOTSUPP;
> > +
> > + wakeref = intel_runtime_pm_get(ddat->uncore->rpm);
> > + mutex_lock(&hwmon->hwmon_lock);
> > +
> > + reg_val = intel_uncore_read(ddat->uncore, hwmon->rg.fan_speed);
> > + time_now = get_jiffies_64();
>
> > + /* Handle HW register overflow */
> > + if (reg_val >= fi->reg_val_prev)
> > + pulses = reg_val - fi->reg_val_prev;
> > + else
> > + pulses = UINT_MAX - fi->reg_val_prev + reg_val;
>
> Isn't it the abs_diff() reimplementation?
Not exactly. This is specific to 32 bit register overflow, so we count
from max value.
Raag
More information about the Intel-gfx
mailing list