Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3191869ybl; Mon, 19 Aug 2019 13:54:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzU3kbuhkz+cINTle/ryMH/rOerzf8tf6rp0PiHDhKYYq9+aYgeWLbeDmdT0um0wM+CkVMG X-Received: by 2002:a17:902:788b:: with SMTP id q11mr24600319pll.308.1566248042002; Mon, 19 Aug 2019 13:54:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566248041; cv=none; d=google.com; s=arc-20160816; b=md0GWOD8CprcmJ56kq1BQwMt0VZfvUd7b/0EC2RPOcKhAd3Y812EjNy74AriDw52Op JTwvL4CC/WdlTpuPCbjzy4UKx8m/3y0ciRsrc1J/XxxFiuateBWF8k2SGRCG79EVGuKT bcqcGtPaAvakyhcZtE5DVL+zKRUz0BTgcXvW20RE9JwjwiaHrbFrnaa6MIfG/qNulZSt 0uVwPtWMRITgGo8L6zQneh/VDb3bKTzN5liWoiorDME3Pn4kMsUTa8BT9Hmfoyo2fLYb 5/v/KAQa9XzEY7o+SxP77bx+ILljxL+HhzaOavpAfiz5UvH2ao1W3BOVBtBIf/G0OIww fDyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=+KzCPfliyJhvJ1c0iMQplTZBNeAA1mxUAJd/xcjNV38=; b=GeHH4QBIpVEyLJUbHDR9SjnZYLAyxJUL6fsKBvddPE64TZvWpQAp1N7kNrO48Cik3m qxSluFf8N7WIV/6F7xjvkp+5HE+BFHl+BJ1Ax4WAFZvQttHrrXasEfJ5Vi7823VSy6MO SamCpOyY0fgsLsOCdttxLCDaUfJ+atTRt/1IUjx/evMGXeBI4nyHmMu1eFTadNF8bp82 HliomJokodL0thgzqagBaNqvQ5smJdJZ6zGsZddTbn8AA4kAejRMQ0M6fOWXnkAuuJTK 90KZIpBJcf8n+ARbckRauIM4ACmjwd5Pa+LUlUBl3acpJVKJqi5QXXee9Htx6O4yQ+yA 0jhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZihfdZck; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y63si10502710pgd.403.2019.08.19.13.53.46; Mon, 19 Aug 2019 13:54:01 -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=@linaro.org header.s=google header.b=ZihfdZck; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728352AbfHSUvl (ORCPT + 99 others); Mon, 19 Aug 2019 16:51:41 -0400 Received: from mail-vs1-f65.google.com ([209.85.217.65]:36242 "EHLO mail-vs1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727971AbfHSUvl (ORCPT ); Mon, 19 Aug 2019 16:51:41 -0400 Received: by mail-vs1-f65.google.com with SMTP id y16so2094005vsc.3 for ; Mon, 19 Aug 2019 13:51:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+KzCPfliyJhvJ1c0iMQplTZBNeAA1mxUAJd/xcjNV38=; b=ZihfdZckUcDLIFJ3PBKZNuHrFkrg+kl8Q6esH4q1/HG09NGkQVfscJhS9miTcnmWs9 hceJ+fMwhxQGzS0Dy9BDD+njDCPCL+AijCDXvK7SmVsHl+YoMxmceVUYrKOcgGznl2yS OZjTRZi60IVwsHNDqxCqC/BCb48qPqWzB6cOmQCpoS+nSoynsxYXKC1v67kB7oEOMjUx d4qS6L6FJPzQsjexyx1rl4fX21XNUBdvlwjtv2AFsPKyatA11Da4oAkHVQD+iG7UVRBp s7RFnzAncWiSWDYWZEWm/VOXRHf3po8HA7y0L2/spCPNggZ+yUTZKNoz3vCGQ9w0mM53 VYCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+KzCPfliyJhvJ1c0iMQplTZBNeAA1mxUAJd/xcjNV38=; b=mbKjj4y565An4AOZ4TI5wPgtT+O1OxC5NqjJgfOoB7AwrvQU0yzI9EccbW0sIXZJyd zFGzhk4GmkNAWUbkmX1Y5yxB0EYlvPhE79dkQtv4/pILbUM0U+40qhcCuXEOtxjFQKcu 5a8VZDOUXu1MZ9aD3bvNeOP1wMP9w/zMHEoDyf66MUDjIzJVE8y+cLc2o1Gvh541Cu1f /kmAp6rr/0Cw+38zJr8gsFCqQtOqtSPP4WR/N2UV879a5a2tD+jaCNbXdQuLuGqDGPCd KE08wxUlp4SLHQPoHt1yk+JQZFy9hhj4cS/OMWuu3nvEgSapjfjMeV+D0w4b6N3ISbTL aIRQ== X-Gm-Message-State: APjAAAXPox+LTjzahHEltFSBmovjU8x0g5bxkyfHjWh0LuQ99yaHX4Ik Gk1jV+4rB325Zfn8KAv5NVDVrDm7nnGE8jzvdX78/w== X-Received: by 2002:a67:df07:: with SMTP id s7mr11007757vsk.27.1566247899971; Mon, 19 Aug 2019 13:51:39 -0700 (PDT) MIME-Version: 1.0 References: <07de61a57cf2362169d3b128405d7305eb20785f.1564091601.git.amit.kucheria@linaro.org> <5d577f95.1c69fb81.6c07e.44da@mx.google.com> In-Reply-To: <5d577f95.1c69fb81.6c07e.44da@mx.google.com> From: Amit Kucheria Date: Tue, 20 Aug 2019 02:21:28 +0530 Message-ID: Subject: Re: [PATCH 14/15] drivers: thermal: tsens: Create function to return sign-extended temperature To: Stephen Boyd Cc: Andy Gross , Daniel Lezcano , Mark Rutland , Rob Herring , Zhang Rui , Andy Gross , Bjorn Andersson , Eduardo Valentin , linux-arm-msm , LKML , Linux PM list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 17, 2019 at 9:46 AM Stephen Boyd wrote: > > Quoting Amit Kucheria (2019-07-25 15:18:49) > > diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-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 struct tsens_sensor *s) > > return degc; > > } > > > > +/** > > + * tsens_hw_to_mC - Return properly sign extended temperature in mCelsius, > > Can you make this proper kernel-doc? Describe the arguments and have a > "Return:" section. Will fix. > > + * whether in ADC code or deciCelsius depending on IP version. > > + * This function handles the different widths of the signed integer across IPs. > > + */ > > +static int tsens_hw_to_mC(char *str, struct tsens_sensor *s, int field, int temp) > > +{ > > + struct tsens_priv *priv = 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. Will fix. > > + mask = GENMASK(priv->fields[field].msb, > > + priv->fields[field].lsb) >> priv->fields[field].lsb; > > Why is the mask generated, shifted right, sent into fls(), and then > passed to sign_extend32? Shoudln't it be something like > > sign_extend32(temp, priv->fields[field].msg - priv->fiels[field].lsb - 1) Yes, that should work and greatly simply the function. Will fix. > > + 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; > > > > - if (priv->feat->adc) { > > - /* Convert temperature from ADC code to milliCelsius */ > > - *temp = code_to_degc(last_temp, s) * 1000; > > - } else { > > - mask = GENMASK(priv->fields[LAST_TEMP_0].msb, > > - priv->fields[LAST_TEMP_0].lsb); > > - /* Convert temperature from deciCelsius to milliCelsius */ > > - *temp = sign_extend32(last_temp, fls(mask) - 1) * 100; > > Oh the code is copied. Seems really complicated still. > > > - } > > + *temp = tsens_hw_to_mC("get_temp", s, LAST_TEMP_0, last_temp);