From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 595A2C3DA4A for ; Thu, 8 Aug 2024 04:43:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6886910E4D2; Thu, 8 Aug 2024 04:43:01 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="hje+ZgCy"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id EEF5D10E0CC; Thu, 8 Aug 2024 04:42:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723092179; x=1754628179; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=4syzyV6hdGjV22Hiflj6sEtCj534I2q+jdzZRjAGewU=; b=hje+ZgCy0xygrnTQg5A3S9mGBcXKlDF/RvtZfaTlX2XYMShHcwF9Auq8 IrxiCb18vFcFMQwACv6a2FSnPKIxB7MpVtqxdSsC6mlZJabGZNfck7Mi9 KAymtDQ7MJ1MSoVGOra4CuhNS2cMcBKjGQxqhoRXW/4hi23wkzmtA6y/R z26zetP7rz17qVF99ppS5SlsGbmP2nUiecvGuAl7qRlky7Pj6T+oQsCvw VOJIfTy03pBsIk1esd7zTHbWk/1O8pCloVQ/SChgZG6qY1YM+yFTQwToc 8ygEKOdkq1MpuHIwrjUDqctkF1ka4JzMiaiVgbOdeRF8XPi8mAj3qnmrz A==; X-CSE-ConnectionGUID: ZHlkCxONR5CM2MPm7i0cRw== X-CSE-MsgGUID: D1qlO6BXQkOfsm3zhr1/JQ== X-IronPort-AV: E=McAfee;i="6700,10204,11157"; a="31867210" X-IronPort-AV: E=Sophos;i="6.09,271,1716274800"; d="scan'208";a="31867210" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2024 21:42:57 -0700 X-CSE-ConnectionGUID: KXtIwPg7SaG4OrINrtmQ+Q== X-CSE-MsgGUID: BT2jfhRmQaSIW27BmDM3lg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,271,1716274800"; d="scan'208";a="61203255" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa003.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2024 21:42:54 -0700 Date: Thu, 8 Aug 2024 07:42:51 +0300 From: Raag Jadav To: Andi Shyti 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 Message-ID: References: <20240807123018.827506-1-raag.jadav@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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