Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp159656ybl; Fri, 16 Aug 2019 21:17:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqxcomSmvXYixyKj309Q/NsXCbnlw3RnAj1BSUZ/4VsUpl06LQuTet6iPCtyNMjr9T/BVukZ X-Received: by 2002:aa7:925a:: with SMTP id 26mr14116969pfp.198.1566015446785; Fri, 16 Aug 2019 21:17:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566015446; cv=none; d=google.com; s=arc-20160816; b=gLey778ZMj0t6g1qREc2TAa2nf8ZO+kPT5GEY/jvSo8OJrL0+2x3x3Y7lsBg1oGggv cI05YDAZUHNZx9tMIksQrJx/9Mwy4eujfaIBTwghx01HW3z5THHUwehOZ6siu/a/nwKN xTgYtyaprak7qYRKBUrrtg7rZB39D0H3ozRcUgkV5IG3aTZySBD4B9H4wXGMwyTFX4N5 WDk/ZzyJhFXXISU9KjNDLoy7KG7Ibpq9IQTWqjTbVzgdpqh3Ia4ClJG65o7PhAIOaglb +FpV3OHLJVvzn2THoQomOM/UIAMxXBiKUvb1Ee8bCWcZHkmmC2xWAyVGg0XXsLKTxLvo lCQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:user-agent:to:cc:from:subject :references:in-reply-to:content-transfer-encoding:mime-version :message-id:dkim-signature; bh=TPUXoZ1NzImxZaqU1kQTGHfT7R1dYMoLUZJDIh8RY3c=; b=g6FgxADk94IdtOrcsuxQYtGTAPWykbLszdDodGh1Y+q5fY0xOSOW+ZVKKjYNoDwy9/ r7K9/ygK76kjZ9zIX7puyg4Ok7e1V0t0cCbAbl9oHBNDwMxlgTl14tb6lbwdosqIQPDk 6mCQznOpIgG1NBSxLgJeHxFbaqRsUuuoacT31r/88pKJeGLL5j9+XeY35yTWB3P0Q8lJ /tAlIQgYJqf5hX6pIlfQtbOyTgqP2BerGuW1swzUR5y7gXFMMedU5uaw4A+7feC2RlV+ lLCrxWWxUB3M2qT6X5Ig5hnh3FwuVojr6hygmSC+LYE+sVrYTJduBJQpXN2xVsjKYyBk pS8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FtMdo8GD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d35si5332609pla.179.2019.08.16.21.17.11; Fri, 16 Aug 2019 21:17:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FtMdo8GD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725864AbfHQEQW (ORCPT + 99 others); Sat, 17 Aug 2019 00:16:22 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:35789 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725832AbfHQEQW (ORCPT ); Sat, 17 Aug 2019 00:16:22 -0400 Received: by mail-pf1-f195.google.com with SMTP id d85so4139598pfd.2 for ; Fri, 16 Aug 2019 21:16:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=message-id:mime-version:content-transfer-encoding:in-reply-to :references:subject:from:cc:to:user-agent:date; bh=TPUXoZ1NzImxZaqU1kQTGHfT7R1dYMoLUZJDIh8RY3c=; b=FtMdo8GDJ3dX+F1qXTJgR5de4PkLTpWKO0veMkJvhBhTEynsDmbMKc2OGMGNewk3ms M5R2TgpawHavE1X/wdEjHzvtliHNenPpjDNolCVvBlkzntIu+G02//O20UGXImYWYxX5 Vs7FfUy58cQTQ/NrRG0+IhG2kEMpImgi9xLjc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:mime-version :content-transfer-encoding:in-reply-to:references:subject:from:cc:to :user-agent:date; bh=TPUXoZ1NzImxZaqU1kQTGHfT7R1dYMoLUZJDIh8RY3c=; b=VQZEQ8orIIS3gJjthj/zHFJ/aLQjKJN0GH9eaiDEwDh+f5HgwvhaaN14a0vIYxueZn nrRtx17RDDFwLPtwBu/+gBjFNiwhgg1ugTzHRcota91IzxqbxO3mTssHBOj50lixln2u NiKSsfXZyGRiG8jvDehnvD3AeGtgLEDN5qhcK3WchcRjkFJ0FKNeTE3u1/Sb1wt8i5z3 rQzpQ/boWzI0ngzPMlkzUe+bQALsDTfVXDHp79GU4WESQVEGfbuGvQ6M0laQclxlpp/G AhTz/S8dkVsskmAzbYN59AvOPWYzio7cgAs6ulD6QWKUk14uYDF6Ap+pzIaiPMGeifj+ Fkcw== X-Gm-Message-State: APjAAAWdftGkSduv/5TNw3QNESEulqDXBuSv1eUGJzJSQyYOopKPivf/ TkVTC/inXY1em2EKAzygnC8m7g== X-Received: by 2002:a62:1808:: with SMTP id 8mr14129781pfy.177.1566015381746; Fri, 16 Aug 2019 21:16:21 -0700 (PDT) Received: from chromium.org ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id t9sm7168070pgj.89.2019.08.16.21.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2019 21:16:21 -0700 (PDT) Message-ID: <5d577f95.1c69fb81.6c07e.44da@mx.google.com> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <07de61a57cf2362169d3b128405d7305eb20785f.1564091601.git.amit.kucheria@linaro.org> References: <07de61a57cf2362169d3b128405d7305eb20785f.1564091601.git.amit.kucheria@linaro.org> Subject: Re: [PATCH 14/15] drivers: thermal: tsens: Create function to return sign-extended temperature From: Stephen Boyd Cc: linux-pm@vger.kernel.org To: Amit Kucheria , Andy Gross , Daniel Lezcano , Mark Rutland , Rob Herring , Zhang Rui , andy.gross@linaro.org, bjorn.andersson@linaro.org, edubezval@gmail.com, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org User-Agent: alot/0.8.1 Date: Fri, 16 Aug 2019 21:16:20 -0700 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Amit Kucheria (2019-07-25 15:18:49) > diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/t= sens-common.c > index 7ab2e740a1da..13a875b99094 100644 > --- a/drivers/thermal/qcom/tsens-common.c > +++ b/drivers/thermal/qcom/tsens-common.c > @@ -84,13 +84,35 @@ static inline int code_to_degc(u32 adc_code, const st= ruct tsens_sensor *s) > return degc; > } > =20 > +/** > + * tsens_hw_to_mC - Return properly sign extended temperature in mCelsiu= s, Can you make this proper kernel-doc? Describe the arguments and have a "Return:" section. > + * whether in ADC code or deciCelsius depending on IP version. > + * This function handles the different widths of the signed integer acro= ss IPs. > + */ > +static int tsens_hw_to_mC(char *str, struct tsens_sensor *s, int field, = int temp) > +{ > + struct tsens_priv *priv =3D s->priv; > + u32 mask; > + > + if (priv->feat->adc) { > + /* Convert temperature from ADC code to milliCelsius */ > + return code_to_degc(temp, s) * 1000; > + } else { Please deindent and drop the else because there's a return above. > + mask =3D GENMASK(priv->fields[field].msb, > + priv->fields[field].lsb) >> priv->fields[f= ield].lsb; Why is the mask generated, shifted right, sent into fls(), and then passed to sign_extend32? Shoudln't it be something like=20 sign_extend32(temp, priv->fields[field].msg - priv->fiels[field].lsb - 1) > + dev_dbg(priv->dev, "%s: mask: %d\n", str, fls(mask)); > + /* Convert temperature from deciCelsius to milliCelsius */ > + return sign_extend32(temp, fls(mask) - 1) * 100; > + } > +} > + > @@ -112,15 +134,7 @@ int get_temp_tsens_valid(struct tsens_sensor *s, int= *temp) > if (ret) > return ret; > =20 > - if (priv->feat->adc) { > - /* Convert temperature from ADC code to milliCelsius */ > - *temp =3D code_to_degc(last_temp, s) * 1000; > - } else { > - mask =3D GENMASK(priv->fields[LAST_TEMP_0].msb, > - priv->fields[LAST_TEMP_0].lsb); > - /* Convert temperature from deciCelsius to milliCelsius */ > - *temp =3D sign_extend32(last_temp, fls(mask) - 1) * 100; Oh the code is copied. Seems really complicated still. > - } > + *temp =3D tsens_hw_to_mC("get_temp", s, LAST_TEMP_0, last_temp);