From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A8B022A4E8 for ; Sun, 10 Aug 2025 06:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754808472; cv=none; b=t3qmCF0ETS4TsikLgnHnKWrw8E8kp1ATNYUHUORHJrqCNHCnIbttbnNzKFnw+gyveXNOhMd1rKbdcdZ5VuRlnJwQraAS16HjbOV6nuHzZrTgMddiXCaWFNVJMttbJKCUZu0zX/jYcg+/+ivlix0CoqxpTy1jfoo32nr3UANtIHw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754808472; c=relaxed/simple; bh=dagAYUKfMf7MQB3tjh0eU5W/hnyL6zIsoo1NhGvUigg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=LgjfmmLN1tiTg+u1u9xc9SUlwkN5OO7zWgAP3hbYLOYPFerxPVjA0CS9NuSZwVE9BNtiGVZePSGSg4BV0KZ1UWmJaaKxAplERPOPdNbys1xleU6+IDz2h4MHxRvVD7ppWzMTstWZBWS1C1yOXeSEvvSTRVeGiv2vZ6OKtFUD6Yc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=DQxdilTd; arc=none smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="DQxdilTd" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-617b36cc489so6650927a12.0 for ; Sat, 09 Aug 2025 23:47:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1754808467; x=1755413267; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=sC8ppSX1H/0TCM/Y3FF+igzDwHvNt7j5FKY8GrjOIKg=; b=DQxdilTdy7VTW3wQiFxUXJ4/o5yAvKO6L20sAYRURUdpsoPabe9Wmgad7FkgzrcKVO PrJutt/t627s8WKngiENHad6DMnNYyQkXj/MekcMGG/9BZpvofcS9GxKeUx2Igiw1efu wAK+wxUB0veaNSpVgzD6BHQwD8L9wXgMYXNBObRMtnC8JOzbBn/k1frO3BzHvE9H6w2g GqywEEuBOjYik8fHcmz36tZADocyZjJXY5tFBGDR3uJkqdCCLyJeq99FWQn15X/DwBW7 JvxlladAmIVmqLb/htNsOFcpa2bi4noZ382DYsKPmr/CUlAlLVCfc4Nm+L7uXUGv9PtS bsQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754808467; x=1755413267; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sC8ppSX1H/0TCM/Y3FF+igzDwHvNt7j5FKY8GrjOIKg=; b=XtIphKpLDwQLXMAoy1toMgnTqPT3ujWd3VJWSxUuo+crtZURVxXEmOo8Ytlr58x9q1 1xu4HdQOrOWJx9N3jaH0gQLg6FgCme0Tlfd8U/6NLv0Cp43gpiYUgUxjAtuRRe8CQ1M/ zaCnNRTE1kc17hcGCrJJCsJ21TudKHRpV+nz5rvvx2XlOwPzBFHREmrlVGbjyxy0vjPj Q8Pdrp54KxUV1HrOhju1dViZnqHHhmzN7IB9rZXws21A2w0DhdtW6e0V6IDOU0TYHuFq np36AnjjoX1TZllybCV38syxprZSbCeD0qH+w+BcT5iR2LpBRmhcNASxBqnYlBNiIgSl ZkoA== X-Forwarded-Encrypted: i=1; AJvYcCXmhOnkW9UwF3jdFRJ+m+5LFOXs8jaGHW1D4rlCAZX3kEWhmajczvji0fTrZmzCig61Xu7/ERgsFe5o@vger.kernel.org X-Gm-Message-State: AOJu0YyymGK7cj2VLPGE4fLmQlacC6ebpcFOsRr/KCtlLffznOR66XAU olSUi6YfTIvqrLIWo0FIp3NMvJZv6X1C+4dSQHRvS+OSuGppmTfZvoRJm16dMjhZe+E= X-Gm-Gg: ASbGncu7zwM6TCHvIyxRtF72g1mNp4mQP/3kSCxluJ0C4n8+rQhh1L8XwH4YFmkPqpT dBrBjH0myk6QmGT+BULvv1j6pex610abQO0rhbgzNz7t0nPQB8ObU7xGkr3wDdffPMIm/ghUW9G jA/kHRJmCbBGMl6fIk/UeeDt+nPEVu26MMLlQdN758VG3otHekfoQiIgiXcr1WAi7iWZRkGn/V8 ENzChxD/8ZHQxzMq0PDWdwjUxEOKrWaJOq08y6xHExojsnbQfpOwVV44l7miTRPHkan9Eeke/fD WtcpZ8GpRVKffALZ9tIJcBPDIbNkU8z0HPQi7brPyQCT/XU29+8vEurobtKalfK6d5SxiDTHWHZ NtJa7l+jOFogZxkABuTh3rHTGRe2PYRk+8ljrc5CoJg== X-Google-Smtp-Source: AGHT+IH/7dzLzWQyWlGILSjoAFS8eflMGUJjXYYLSezW9ohIbVGYZPagLxPqBOuF4SYx6XNBcYwt7w== X-Received: by 2002:a05:6402:51cb:b0:615:c767:5ba1 with SMTP id 4fb4d7f45d1cf-617e2b661aemr7951088a12.3.1754808467315; Sat, 09 Aug 2025 23:47:47 -0700 (PDT) Received: from [192.168.50.4] ([82.78.167.188]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-615a8ffbdb4sm16219007a12.52.2025.08.09.23.47.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 09 Aug 2025 23:47:46 -0700 (PDT) Message-ID: <1cc60291-194d-4d8c-ad0d-f83651ba4fc5@tuxon.dev> Date: Sun, 10 Aug 2025 09:47:44 +0300 Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 2/4] thermal: renesas: rzg3s: Add thermal driver for the Renesas RZ/G3S SoC To: =?UTF-8?Q?Niklas_S=C3=B6derlund?= Cc: rafael@kernel.org, daniel.lezcano@linaro.org, rui.zhang@intel.com, lukasz.luba@arm.com, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, geert+renesas@glider.be, magnus.damm@gmail.com, p.zabel@pengutronix.de, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Claudiu Beznea References: <20250324135701.179827-1-claudiu.beznea.uj@bp.renesas.com> <20250324135701.179827-3-claudiu.beznea.uj@bp.renesas.com> <20250705120617.GA671672@ragnatech.se> From: Claudiu Beznea Content-Language: en-US In-Reply-To: <20250705120617.GA671672@ragnatech.se> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi, Niklas, On 05.07.2025 15:06, Niklas Söderlund wrote: > Hi Claudiu, > > Thanks for your work. > > Sorry for late review, Geert only alerted me to the series a few days > ago. > > On 2025-03-24 15:56:59 +0200, Claudiu wrote: >> From: Claudiu Beznea >> >> The Renesas RZ/G3S SoC features a Thermal Sensor Unit (TSU) that reports >> the junction temperature. The temperature is reported through a dedicated >> ADC channel. Add a driver for the Renesas RZ/G3S TSU. >> >> Signed-off-by: Claudiu Beznea >> --- >> [ ...] >> +static int rzg3s_thermal_get_temp(struct thermal_zone_device *tz, int *temp) >> +{ >> + struct rzg3s_thermal_priv *priv = thermal_zone_device_priv(tz); >> + int ts_code_ave = 0; >> + int ret, val; >> + >> + if (priv->mode != THERMAL_DEVICE_ENABLED) >> + return -EAGAIN; >> + >> + for (u8 i = 0; i < TSU_READ_STEPS; i++) { >> + ret = iio_read_channel_raw(priv->channel, &val); >> + if (ret < 0) >> + return ret; >> + >> + ts_code_ave += val; >> + /* >> + * According to the HW manual (section 40.4.4 Procedure for Measuring the >> + * Temperature) we need to wait here at leat 3us. >> + */ >> + usleep_range(5, 10); >> + } >> + >> + ret = 0; >> + ts_code_ave = DIV_ROUND_CLOSEST(MCELSIUS(ts_code_ave), TSU_READ_STEPS); >> + >> + /* >> + * According to the HW manual (section 40.4.4 Procedure for Measuring the Temperature) >> + * the computation formula is as follows: >> + * >> + * Tj = (ts_code_ave - priv->calib1) * 165 / (priv->calib0 - priv->calib1) - 40 >> + * >> + * Convert everything to mili Celsius before applying the formula to avoid >> + * losing precision. >> + */ >> + >> + *temp = DIV_ROUND_CLOSEST((s64)(ts_code_ave - MCELSIUS(priv->calib1)) * MCELSIUS(165), >> + MCELSIUS(priv->calib0 - priv->calib1)) - MCELSIUS(40); > > The issue Geert points out, can that not be solved by holding off > converting to MCELSIUS() to after you have done the calculation? This method works as well, but at the cost of some precision. As of my experiments, with it there will be no temperatures with .5 Celsius resolution (e.g., 50.5, 51.5, 52.5, etc) reported. Thank you, Claudiu