Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Raag Jadav <raag.jadav@intel.com>
To: Andi Shyti <andi.shyti@linux.intel.com>
Cc: jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com,
	rodrigo.vivi@intel.com, tursulin@ursulin.net, airlied@gmail.com,
	daniel@ffwll.ch, linux@roeck-us.net,
	intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
	anshuman.gupta@intel.com, badal.nilawar@intel.com,
	riana.tauro@intel.com, ashutosh.dixit@intel.com,
	karthik.poosa@intel.com, andriy.shevchenko@linux.intel.com
Subject: Re: [PATCH v3] drm/i915/hwmon: expose fan speed
Date: Thu, 8 Aug 2024 07:42:51 +0300	[thread overview]
Message-ID: <ZrRMyzUfNdjyL1y6@black.fi.intel.com> (raw)
In-Reply-To: <ZrN1i2snlz8tSA1M@ashyti-mobl2.lan>

On Wed, Aug 07, 2024 at 02:24:27PM +0100, Andi Shyti wrote:
> Hi Raag,
> 
> > +static umode_t
> > +hwm_fan_is_visible(const struct hwm_drvdata *ddat, u32 attr)
> > +{
> > +	struct i915_hwmon *hwmon = ddat->hwmon;
> > +
> > +	switch (attr) {
> > +	case hwmon_fan_input:
> > +		return i915_mmio_reg_valid(hwmon->rg.fan_speed) ? 0444 : 0;
> > +	default:
> > +		return 0;
> > +	}
> 
> Why do we need switch case here?

Just following the file conventions.

> Why can't this function become a single "return " line?
> 
> > +}
> > +
> > +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;
> > +	u32 reg_val, pulses, time, time_now;
> > +	intel_wakeref_t wakeref;
> > +	long rotations;
> > +	int ret = 0;
> > +
> > +	switch (attr) {
> > +	case hwmon_fan_input:
> > +		with_intel_runtime_pm(ddat->uncore->rpm, wakeref) {
> > +			mutex_lock(&hwmon->hwmon_lock);
> > +
> > +			reg_val = intel_uncore_read(ddat->uncore, hwmon->rg.fan_speed);
> > +			time_now = jiffies_to_msecs(jiffies);
> > +
> > +			/* Handle 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;
> > +
> > +			/*
> > +			 * HW register value is accumulated count of pulses from
> > +			 * PWM fan with the scale of 2 pulses per rotation.
> > +			 */
> > +			rotations = pulses >> 1;
> > +			time = time_now - fi->time_prev;
> > +
> > +			if (unlikely(!time)) {
> > +				ret = -EAGAIN;
> > +				mutex_unlock(&hwmon->hwmon_lock);
> > +				break;
> > +			}
> > +
> > +			/* Convert to minutes for calculating RPM */
> > +			*val = DIV_ROUND_UP(rotations * (60 * MSEC_PER_SEC), time);
> > +
> > +			fi->reg_val_prev = reg_val;
> > +			fi->time_prev = time_now;
> > +
> > +			mutex_unlock(&hwmon->hwmon_lock);
> > +		}
> > +		return ret;
> > +	default:
> > +		return -EOPNOTSUPP;
> > +	}
> 
> same here, can we make this function:
> 
> if (attr != hwmon_fan_input)
> 	return -EOPNOTSUPP;
> 
> and then save all the indentation.

Makes sense for hwm_fan_read(). Let me try this.

> Are we expecting more cases here?

Not for now.

Raag

  reply	other threads:[~2024-08-08  4:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-07 12:30 [PATCH v3] drm/i915/hwmon: expose fan speed Raag Jadav
2024-08-07 12:48 ` ✓ Fi.CI.BAT: success for drm/i915/hwmon: expose fan speed (rev3) Patchwork
2024-08-07 13:24 ` [PATCH v3] drm/i915/hwmon: expose fan speed Andi Shyti
2024-08-08  4:42   ` Raag Jadav [this message]
2024-08-08  5:19 ` ✗ Fi.CI.IGT: failure for drm/i915/hwmon: expose fan speed (rev3) Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZrRMyzUfNdjyL1y6@black.fi.intel.com \
    --to=raag.jadav@intel.com \
    --cc=airlied@gmail.com \
    --cc=andi.shyti@linux.intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=anshuman.gupta@intel.com \
    --cc=ashutosh.dixit@intel.com \
    --cc=badal.nilawar@intel.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=karthik.poosa@intel.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=riana.tauro@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=tursulin@ursulin.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox