Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp356733rdb; Mon, 22 Jan 2024 06:28:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6NUI0iAaS5yp7YDiz9eetQsf0vldPPgtnvtKvob1rN3uHTBAMsgMRtIJrPYMRFtvGyjlG X-Received: by 2002:a05:6830:16c2:b0:6dd:de84:2626 with SMTP id l2-20020a05683016c200b006ddde842626mr4749284otr.58.1705933729000; Mon, 22 Jan 2024 06:28:49 -0800 (PST) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id v25-20020a05622a189900b0042a48d8ef0asi415726qtc.710.2024.01.22.06.28.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 06:28:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-33157-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-33157-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33157-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BD38E1C2235D for ; Mon, 22 Jan 2024 14:28:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E4FBF3D3AF; Mon, 22 Jan 2024 14:28:34 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 730453D540; Mon, 22 Jan 2024 14:28:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705933714; cv=none; b=AGnKKfnOEG+8Qo+0bZqSTanfNEj2yJzbVlirTrd8bvvJVfxrby80nxyYj55I30Rsc+31pjdTQBfFaK2/5mkBW5SajM/SpP4IPpzC+fcVOuqZ1CurKmIl+sk1PlFS2syxykpJL+yOFCqU7FPRTZZ2Bs4UMugKIIO2wYKUAcfCqVY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705933714; c=relaxed/simple; bh=wKYLc46OaXYdyZIR8EPFUIwqMGtJkElacXNktfcfIqg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TcHK4bcZlXXOIY+k3HvtWmSnjvuYllhRYcNSLDaojOOcIiK1BrS4y+bzjaInWhrbJNej/yjXrOPFpycx1bRxsbjxl6XIdXzf8Y/wXW6gNozsVMVSOSB9Lh2BjY1FRxuAYwNX+wc2qOWqBTibZaSo761AUKytrGo1oH/s5N6+SFk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3C2121FB; Mon, 22 Jan 2024 06:29:16 -0800 (PST) Received: from pluto (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 151A73F73F; Mon, 22 Jan 2024 06:28:28 -0800 (PST) Date: Mon, 22 Jan 2024 14:28:26 +0000 From: Cristian Marussi To: "Peng Fan (OSS)" Cc: sudeep.holla@arm.com, jdelvare@suse.com, linux@roeck-us.net, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Peng Fan Subject: Re: [PATCH] hwmon: scmi-hwmon: implement change_mode Message-ID: References: <20240122080441.1957022-1-peng.fan@oss.nxp.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Jan 22, 2024 at 10:59:18AM +0000, Cristian Marussi wrote: > On Mon, Jan 22, 2024 at 04:04:41PM +0800, Peng Fan (OSS) wrote: > > From: Peng Fan > > > > The sensor maybe disabled before kernel boot, so add change_mode > > to support configuring the sensor to enabled state. > > > > Hi Peng, > > minor remarks down below > > > Signed-off-by: Peng Fan > > --- > > drivers/hwmon/scmi-hwmon.c | 29 +++++++++++++++++++++++++++++ > > 1 file changed, 29 insertions(+) > > > > diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c > > index 364199b332c0..f7bd63d52d15 100644 > > --- a/drivers/hwmon/scmi-hwmon.c > > +++ b/drivers/hwmon/scmi-hwmon.c > > @@ -151,7 +151,36 @@ static int scmi_hwmon_thermal_get_temp(struct thermal_zone_device *tz, > > return ret; > > } > > > > +static int scmi_hwmon_thermal_change_mode(struct thermal_zone_device *tz, > > + enum thermal_device_mode new_mode) > > +{ > > + int ret; > > + u32 config; > > + enum thermal_device_mode cur_mode = THERMAL_DEVICE_DISABLED; > > + struct scmi_thermal_sensor *th_sensor = thermal_zone_device_priv(tz); > > + > > + ret = sensor_ops->config_get(th_sensor->ph, th_sensor->info->id, > > + &config); > > + if (ret) > > + return ret; > > + > > + if (config & BIT(0)) > > if SCMI_SENS_CFG_IS_ENABLED(config) > > > + cur_mode = THERMAL_DEVICE_ENABLED; > > + > > + if (cur_mode == new_mode) > > + return 0; > > + > > + if (new_mode == THERMAL_DEVICE_ENABLED) > > + config |= SCMI_SENS_CFG_SENSOR_ENABLED_MASK; > > + else > > + config &= ~SCMI_SENS_CFG_SENSOR_ENABLED_MASK; > > + > > Here you are ORing the enable bit to preserve the value obtained by > config_get (rightly so), BUT unfortunately looking at the spec > CONFIG_SET uses bits [10:9] for setting the rounding mode while > CONFIG_GET does NOT report (bits [10:2] are Reserved) so you are > in fact setting ROUNDING to 00 probably, meaning ROUND_DOWN. > > We could have to add (in the future not now) something in CONFIG_GET > to get the round mode (I'll speak with Souvik) BUT in the meantime I > wonder if it is not more safe here to just explicitly set the mode to > 10 to signify it is up to the platform to autonomously choose how to > round. (there are SCMI_SENS_CFG_ROUND_ macros and mask in > scmi_protocol.h) ..so after a quick check with ATG, this ROUNDING mode is indeed related to this specific CONFIG_SET request being issued...it is not a general sensor config, so it is not and will not be needed to be reported from CONFIG_GET (and was indeed clear from the spec my bad...). Moreover looking better at SENSOR_CONFIG_SET spec the sensor_update_interval field can be set to 0 if not required to be updated....so I suppose the better policy here is to just clear out all the bits [31:9] before setting the enable bit, while KEEPING the original timestamp bit untouched. A bit tricky...sorry for the confusion. Thanks, Cristian