From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 1853A2D0C7B for ; Wed, 15 Oct 2025 14:40:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760539226; cv=none; b=ASD6LznYU3zVphkttC70a6SHWrR0CPxyEk5Y9eFbVVDwqbrMUWGqwAESHvH+39wGWuZlqMKxyprBmZuN3G4BNMX7GB/tDpTk8JIpJjR2vRiJ2Q2tlFY9KC58jncFsfp2F6q8tAv81W2rmxw1s5bJG0FwdsgQJYFnbhXaTq+rm2k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760539226; c=relaxed/simple; bh=Kq6pVdZOg7a1WPr8AiMpWEij5BoHEYQsn4tjHgq5LT0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=j/1obw0esTF1kucjelu3kWkR2m6dVXFGaftgK+dc6+j/DFeUS3bKQOE1EsQ6tClPPEH7hQngzPnUmDtuCrvgZDUYdiDW11Ml+euGsdAvg8MbeK6tneID6UFzTGD4rIz6bhR+/T8uzcdHZTo10Ro6dr75bA4YyWS+PwqkuhXYsQ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DW4Y56Bc; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DW4Y56Bc" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-3f0134ccc0cso5049008f8f.1 for ; Wed, 15 Oct 2025 07:40:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1760539222; x=1761144022; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=GoqtzN0lWlzu79SStRn0iIZHV2VRS7p0ymwJV3EZvNM=; b=DW4Y56Bc8Qr4m82j8gJSZj7eQGWJQoAOjjYQC1BGB4SpIwQk6/yyJXYL4Ob9diL1Bo xWFVgcLsw5gEOK3fZNxQSiMnkV97Rzr0RHjsnP5VpaFtli+OUp3C1pP3qTvI8mJ62uzW o1OynKGvg6IotejZjy4SviMim5AOxK5bIqlT706K01M6YhjaCCOaSSvXYnF5bOk87ZJ7 r3C+k1+xzTUmI0XIyBPnRttFdh7fBa5pR+DYYNV8hnp/JheyrvYKRXIq4rHzNVcWSTgn HNOcg4zNBIDOCK6Z6TidY/SAHp9FpWc8JVXg4bHXLVyugJxJeWqJ270b7EzXgA16JBpQ heHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760539222; x=1761144022; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GoqtzN0lWlzu79SStRn0iIZHV2VRS7p0ymwJV3EZvNM=; b=puMOQ9ZxeQUEmq/B1iri8pCobuAPrxwIHWLUP5bpPYhXAYsLumrwcBt0YHBmmAZAmn qwNFcJS53ejWJb4b4uInk0HeQ6mN3CVPGtvMzy4vl20L/ckAOmfuGq45qTMmG3TJpfwA wXK/dOIkq3AS/GAz+3lG7uSgYsTPgP3492E+zrV06xkJJylF8Lq777vSfDO+fRJ+Oyzr PVdOACWyNmp7VD5ivee1U3GBFM2cF/nuP8cSTTXCPHsJRVDeeRrKiuR8V3pddM/d//aD mxltqBkGunYTxtoesAq4nR4cEhmGegRvEjY8yMbuwVvO8rWu3raFfua4ygs92cPIfnnS tYkg== X-Forwarded-Encrypted: i=1; AJvYcCUqV72IT3/RRaTDMYWrb0xGVY1vHXbXStQWcBEUiqIXpi/Js52F8ICzLhRmWz8ZRT59gKno3YAWJhBQoJs=@vger.kernel.org X-Gm-Message-State: AOJu0YxQ6JQW9zLHunk6VsGJxC0F43tW/np/oS4AV4ib1gF38li+Stnh SgJUIZWo6IJui4TfYUJAraipubdPLUfafECyN3z/WLJjUWUPtkdaRDJz X-Gm-Gg: ASbGncvsT8VP7WbA7VycwCtoaDLBq3lKomNNkmfS0rdwUQUyL9uEjpdNNZGUJQaKHxj 83K1aP1ovDfpYb5DZDNb7Bf7gwJzQjsw73rei+HA9s7KuXPFawyuiTXdTZOva/DmOAwMiZro/Se hZ92OitcSerIlyc/4Fls/86rkPHl/tlqfWNlhmo3tZ+a1jk6FyTWl9jy5SRIgkh8Mmkg8azwurK 5rJQsSOUuL+zvlRSIXUH/pH+oV2/Rr40bwKh9JSIBw/hR46iFoo1hftNiUB43RvO+ciSvCiy+1Z JKlRvi9I0xBdbdnNmlf5bM3Nq66ywuy3sa82B2+hdrJzvUXMuyRUajvFpbR7TtTDjGTLnzT88vk kUHknfkcDYs+ZMsZDHMuXRh/I+Uz7S7Tmt+iz4ZMzHbhF0ogYhw== X-Google-Smtp-Source: AGHT+IFsLDcwGEHyBOoWPYn6JJApXkwvV7WDKIKm6EalFLQUwdrQ6onT+X8Kqzu8TCKG+6Oj9L642Q== X-Received: by 2002:a05:6000:4313:b0:3e0:c28a:abbb with SMTP id ffacd0b85a97d-42666ac39a2mr18353598f8f.13.1760539221995; Wed, 15 Oct 2025 07:40:21 -0700 (PDT) Received: from legfed1 ([2a00:79c0:605:6300:22ea:3d6a:5919:85f8]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-470fe96d064sm20404785e9.2.2025.10.15.07.40.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Oct 2025 07:40:21 -0700 (PDT) Date: Wed, 15 Oct 2025 16:40:19 +0200 From: Dimitri Fedrau To: Andy Shevchenko Cc: dimitri.fedrau@liebherr.com, Javier Carrasco , Li peiyu <579lpy@gmail.com>, Jonathan Cameron , David Lechner , Nuno =?utf-8?B?U8Oh?= , Andy Shevchenko , Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Chris Lesiak Subject: Re: [PATCH v3 2/2] iio: humditiy: hdc3020: fix units for thresholds and hysteresis Message-ID: <20251015144019.GA2207492@legfed1> References: <20251013-hdc3020-units-fix-v3-0-b21fab32b882@liebherr.com> <20251013-hdc3020-units-fix-v3-2-b21fab32b882@liebherr.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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Am Wed, Oct 15, 2025 at 12:45:31PM +0300 schrieb Andy Shevchenko: > On Mon, Oct 13, 2025 at 11:12 AM Dimitri Fedrau via B4 Relay > wrote: > > > > According to the ABI the units after application of scale and offset are > > milli degree celsius for temperature thresholds and milli percent for > > relative humidity thresholds. Currently the resulting units are degree > > celsius for temperature thresholds and hysteresis and percent for relative > > humidity thresholds and hysteresis. Change scale factor to fix this issue. > > ... > > > > - return -2949075 + (175 * temp); > > + return -589815 + (35 * temp); > > I was under the impression that we agreed on the explicit division by 5. > > return -2949075 / 5 + (175 / 5 * temp); > I wanted to scale the formula as it has been done before, but didn't make it really clear. After thinking about it again, I think you are right, will add the explicit division by 5. > ... > > > - return hum * 100; > > + return hum * 20; > > And in a similar way here. > Ok. > > > s_clr = max(s_clr, HDC3020_MIN_TEMP_MICRO); > > s_clr = min(s_clr, HDC3020_MAX_TEMP_MICRO); > > @@ -565,7 +574,8 @@ static int hdc3020_write_thresh(struct iio_dev *indio_dev, > > /* Calculate old hysteresis */ > > s_thresh = (s64)hdc3020_thresh_get_hum(thresh) * 1000000; > > s_clr = (s64)hdc3020_thresh_get_hum(clr) * 1000000; > > - s_hyst = div_s64(abs(s_thresh - s_clr), 65535); > > + s_hyst = div_s64(abs(s_thresh - s_clr), > > + HDC3020_THRESH_FRACTION); > > /* Set new threshold */ > > thresh = reg_val; > > /* Try to set old hysteresis */ > > @@ -574,15 +584,16 @@ static int hdc3020_write_thresh(struct iio_dev *indio_dev, > > case IIO_EV_INFO_HYSTERESIS: > > /* > > * Function hdc3020_thresh_get_hum returns relative > > - * humidity in percent scaled by 65535. Scale by 1000000 > > - * to be able to subtract scaled hysteresis value. > > + * humidity in percent scaled by HDC3020_THRESH_FRACTION. > > + * Scale by 1000000 to be able to subtract scaled > > + * hysteresis value. > > */ > > s_thresh = (s64)hdc3020_thresh_get_hum(thresh) * 1000000; > > /* > > - * Units of s_val are in micro percent, scale by 65535 > > - * to get same units as s_thresh. > > + * Units of s_val are in micro percent, scale by > > + * HDC3020_THRESH_FRACTION to get same units as s_thresh. > > */ > > - s_hyst = (s64)s_val * 65535; > > + s_hyst = (s64)s_val * HDC3020_THRESH_FRACTION; > > s_clr = hdc3020_thresh_clr(s_thresh, s_hyst, dir); > > s_clr = max(s_clr, 0); > > s_clr = min(s_clr, HDC3020_MAX_HUM_MICRO); > > @@ -630,7 +641,7 @@ static int hdc3020_read_thresh(struct iio_dev *indio_dev, > > thresh = hdc3020_thresh_get_temp(ret); > > switch (info) { > > case IIO_EV_INFO_VALUE: > > - *val = thresh; > > + *val = thresh * MILLI; > > break; > > case IIO_EV_INFO_HYSTERESIS: > > ret = hdc3020_read_be16(data, reg_clr); > > @@ -638,18 +649,18 @@ static int hdc3020_read_thresh(struct iio_dev *indio_dev, > > return ret; > > > > clr = hdc3020_thresh_get_temp(ret); > > - *val = abs(thresh - clr); > > + *val = abs(thresh - clr) * MILLI; > > break; > > default: > > return -EOPNOTSUPP; > > } > > - *val2 = 65535; > > + *val2 = HDC3020_THRESH_FRACTION; > > return IIO_VAL_FRACTIONAL; > > case IIO_HUMIDITYRELATIVE: > > thresh = hdc3020_thresh_get_hum(ret); > > switch (info) { > > case IIO_EV_INFO_VALUE: > > - *val = thresh; > > + *val = thresh * MILLI; > > break; > > case IIO_EV_INFO_HYSTERESIS: > > ret = hdc3020_read_be16(data, reg_clr); > > @@ -657,12 +668,12 @@ static int hdc3020_read_thresh(struct iio_dev *indio_dev, > > return ret; > > > > clr = hdc3020_thresh_get_hum(ret); > > - *val = abs(thresh - clr); > > + *val = abs(thresh - clr) * MILLI; > > break; > > default: > > return -EOPNOTSUPP; > > } > > - *val2 = 65535; > > + *val2 = HDC3020_THRESH_FRACTION; > > return IIO_VAL_FRACTIONAL; > > default: > > return -EOPNOTSUPP; > > > > -- > > 2.39.5 > > > > > > Best regards, Dimitri Fedrau