From: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
To: Bryan O'Donoghue <bryan.odonoghue@linaro.org>,
amitk@kernel.org, thara.gopinath@gmail.com, agross@kernel.org,
andersson@kernel.org, konrad.dybcio@linaro.org,
rafael@kernel.org, daniel.lezcano@linaro.org,
rui.zhang@intel.com
Cc: linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] thermal/drivers/tsens: Extract and shift-in optional MSB
Date: Thu, 6 Apr 2023 20:47:11 +0300 [thread overview]
Message-ID: <ecf48eaf-b4b9-3749-894d-0f06d0b954e3@linaro.org> (raw)
In-Reply-To: <20230406145850.357296-4-bryan.odonoghue@linaro.org>
On 06/04/2023 17:58, Bryan O'Donoghue wrote:
> In msm8939 some of the sensor calibration data traverses byte boundaries.
> Two examples of this are thermal sensor 2 point 1 and sensor 9 point 2.
>
> For sensor 2 point 1 we can get away with a simple read traversing byte
> boundaries as the calibration most significant bits are adjacent to the
> least significant across the byte boundary.
>
> In this case a read starting at the end of the first byte for nine bits
> will deliver up the data we want.
>
> In the case of sensor 9 point 2 however, the most significant bits are not
> adjacent and so therefore we need to perform two reads and or the bits
> together.
>
> If reg.p1_shift or reg.p2_shift is set then automatically search for
> pX_sY_msb in the dts applying pX_shift as a right shift or into the pX_sY
> value.
I think that having this in the common code is a bit of an overkill. No
other platform has this 'peculiarity' up to now. So, it might be better
to add 8939-specific calibration function that calls
tsens_read_calibration(), mixes in the s10_p2_msb and then calls
compute_intercept_slope().
>
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> ---
> drivers/thermal/qcom/tsens.c | 33 +++++++++++++++++++++++++++++++++
> 1 file changed, 33 insertions(+)
>
> diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
> index a260f563b4889..eff2c8671c343 100644
> --- a/drivers/thermal/qcom/tsens.c
> +++ b/drivers/thermal/qcom/tsens.c
> @@ -74,6 +74,7 @@ int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2,
> {
> u32 mode;
> u32 base1, base2;
> + u32 msb;
> char name[] = "sXX_pY_backup"; /* s10_p1_backup */
> int i, ret;
>
> @@ -122,6 +123,22 @@ int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2,
>
> dev_dbg(priv->dev, "%s 0x%x\n", name, p1[i]);
>
> + if (priv->reg && priv->reg[i].p1_shift) {
> + ret = snprintf(name, sizeof(name), "s%d_p1_msb",
> + priv->sensor[i].hw_id);
> + if (ret < 0)
> + return ret;
> +
> + ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &msb);
> + if (ret) {
> + dev_err(priv->dev, "Failed to read %s\n", name);
> + return ret;
> + }
> +
> + dev_dbg(priv->dev, "%s 0x%x\n", name, msb);
> + p1[i] |= msb >> priv->reg[i].p1_shift;
> + }
> +
> ret = snprintf(name, sizeof(name), "s%d_p2%s", priv->sensor[i].hw_id,
> backup ? "_backup" : "");
> if (ret < 0)
> @@ -134,6 +151,22 @@ int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2,
> }
>
> dev_dbg(priv->dev, "%s 0x%x\n", name, p2[i]);
> +
> + if (priv->reg && priv->reg[i].p2_shift) {
> + ret = snprintf(name, sizeof(name), "s%d_p2_msb",
> + priv->sensor[i].hw_id);
> + if (ret < 0)
> + return ret;
> +
> + ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &msb);
> + if (ret) {
> + dev_err(priv->dev, "Failed to read %s\n", name);
> + return ret;
> + }
> +
> + dev_dbg(priv->dev, "%s 0x%x\n", name, msb);
> + p2[i] |= msb >> priv->reg[i].p2_shift;
> + }
> }
>
> switch (mode) {
--
With best wishes
Dmitry
next prev parent reply other threads:[~2023-04-06 17:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-06 14:58 [PATCH 0/3] drivers/thermal/qcom/tsens: Add ability to read and shift-in non-contiguous calibration data Bryan O'Donoghue
2023-04-06 14:58 ` [PATCH 1/3] thermal/drivers/tsens: Add error/debug prints to calibration read Bryan O'Donoghue
2023-04-06 17:36 ` Dmitry Baryshkov
2023-04-06 14:58 ` [PATCH 2/3] thermal/drivers/tsens: Describe sensor registers via a structure Bryan O'Donoghue
2023-04-06 17:43 ` Dmitry Baryshkov
2023-04-06 14:58 ` [PATCH 3/3] thermal/drivers/tsens: Extract and shift-in optional MSB Bryan O'Donoghue
2023-04-06 17:47 ` Dmitry Baryshkov [this message]
2023-04-06 16:20 ` [PATCH 0/3] drivers/thermal/qcom/tsens: Add ability to read and shift-in non-contiguous calibration data Stephan Gerhold
2023-04-06 22:36 ` Bryan O'Donoghue
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ecf48eaf-b4b9-3749-894d-0f06d0b954e3@linaro.org \
--to=dmitry.baryshkov@linaro.org \
--cc=agross@kernel.org \
--cc=amitk@kernel.org \
--cc=andersson@kernel.org \
--cc=bryan.odonoghue@linaro.org \
--cc=daniel.lezcano@linaro.org \
--cc=konrad.dybcio@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=rui.zhang@intel.com \
--cc=thara.gopinath@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®