public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
To: "Nícolas F. R. A. Prado" <nfraprado@collabora.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Daniel Lezcano" <daniel.lezcano@linaro.org>,
	"Zhang Rui" <rui.zhang@intel.com>,
	"Lukasz Luba" <lukasz.luba@arm.com>,
	"Matthias Brugger" <matthias.bgg@gmail.com>,
	"Alexandre Mergnat" <amergnat@baylibre.com>,
	"Balsam CHIHI" <bchihi@baylibre.com>
Cc: kernel@collabora.com, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org,
	"Hsin-Te Yuan" <yuanhsinte@chromium.org>,
	"Chen-Yu Tsai" <wenst@chromium.org>,
	"Bernhard Rosenkränzer" <bero@baylibre.com>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH 3/5] thermal/drivers/mediatek/lvts: Disable low offset IRQ for minimum threshold
Date: Tue, 26 Nov 2024 10:43:47 +0100	[thread overview]
Message-ID: <78f440ff-1247-4d97-a170-fe2412e75d4a@collabora.com> (raw)
In-Reply-To: <20241125-mt8192-lvts-filtered-suspend-fix-v1-3-42e3c0528c6c@collabora.com>

Il 25/11/24 22:20, Nícolas F. R. A. Prado ha scritto:
> In order to get working interrupts, a low offset value needs to be
> configured. The minimum value for it is 20 Celsius, which is what is
> configured when there's no lower thermal trip (ie the thermal core
> passes -INT_MAX as low trip temperature). However, when the temperature
> gets that low and fluctuates around that value it causes an interrupt
> storm.
> 
> Prevent that interrupt storm by not enabling the low offset interrupt if
> the low threshold is the minimum one.
> 
> Cc: stable@vger.kernel.org
> Fixes: 77354eaef821 ("thermal/drivers/mediatek/lvts_thermal: Don't leave threshold zeroed")
> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
> ---
>   drivers/thermal/mediatek/lvts_thermal.c | 48 ++++++++++++++++++++++++---------
>   1 file changed, 35 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
> index 6ac33030f015c7239e36d81018d1a6893cb69ef8..2271023f090df82fbdd0b5755bb34879e58b0533 100644
> --- a/drivers/thermal/mediatek/lvts_thermal.c
> +++ b/drivers/thermal/mediatek/lvts_thermal.c
> @@ -67,10 +67,14 @@
>   #define LVTS_CALSCALE_CONF			0x300
>   #define LVTS_MONINT_CONF			0x0300318C
>   
> -#define LVTS_MONINT_OFFSET_SENSOR0		0xC
> -#define LVTS_MONINT_OFFSET_SENSOR1		0x180
> -#define LVTS_MONINT_OFFSET_SENSOR2		0x3000
> -#define LVTS_MONINT_OFFSET_SENSOR3		0x3000000
> +#define LVTS_MONINT_OFFSET_HIGH_SENSOR0		BIT(3)

Yeah it's longer, but that's more readable:

#define LVTS_MONINT_OFFSET_HIGH_INTEN_SENSOR0

...because what this BIT does is enabling the high offset interrupt for the
sensing point 0 (which in this driver we call sensor 0).

That name would make it (imo) way less likely to need any datasheet to understand
what is actually going on with that setting :-)

> +#define LVTS_MONINT_OFFSET_HIGH_SENSOR1		BIT(8)
> +#define LVTS_MONINT_OFFSET_HIGH_SENSOR2		BIT(13)
> +#define LVTS_MONINT_OFFSET_HIGH_SENSOR3		BIT(25)
> +#define LVTS_MONINT_OFFSET_LOW_SENSOR0		BIT(2)

Of course, the comment is valid for the LOW ones as well!

Everything else is good for me, and since it is just about simple renaming, I can
already give you my

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>

> +#define LVTS_MONINT_OFFSET_LOW_SENSOR1		BIT(7)
> +#define LVTS_MONINT_OFFSET_LOW_SENSOR2		BIT(12)
> +#define LVTS_MONINT_OFFSET_LOW_SENSOR3		BIT(24)
>   
>   #define LVTS_INT_SENSOR0			0x0009001F
>   #define LVTS_INT_SENSOR1			0x001203E0
> @@ -326,11 +330,17 @@ static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
>   
>   static void lvts_update_irq_mask(struct lvts_ctrl *lvts_ctrl)
>   {
> -	u32 masks[] = {
> -		LVTS_MONINT_OFFSET_SENSOR0,
> -		LVTS_MONINT_OFFSET_SENSOR1,
> -		LVTS_MONINT_OFFSET_SENSOR2,
> -		LVTS_MONINT_OFFSET_SENSOR3,
> +	u32 high_offset_masks[] = {
> +		LVTS_MONINT_OFFSET_HIGH_SENSOR0,
> +		LVTS_MONINT_OFFSET_HIGH_SENSOR1,
> +		LVTS_MONINT_OFFSET_HIGH_SENSOR2,
> +		LVTS_MONINT_OFFSET_HIGH_SENSOR3,
> +	};
> +	u32 low_offset_masks[] = {
> +		LVTS_MONINT_OFFSET_LOW_SENSOR0,
> +		LVTS_MONINT_OFFSET_LOW_SENSOR1,
> +		LVTS_MONINT_OFFSET_LOW_SENSOR2,
> +		LVTS_MONINT_OFFSET_LOW_SENSOR3,
>   	};
>   	u32 value = 0;
>   	int i;
> @@ -339,10 +349,22 @@ static void lvts_update_irq_mask(struct lvts_ctrl *lvts_ctrl)
>   
>   	for (i = 0; i < ARRAY_SIZE(masks); i++) {
>   		if (lvts_ctrl->sensors[i].high_thresh == lvts_ctrl->high_thresh
> -		    && lvts_ctrl->sensors[i].low_thresh == lvts_ctrl->low_thresh)
> -			value |= masks[i];
> -		else
> -			value &= ~masks[i];
> +		    && lvts_ctrl->sensors[i].low_thresh == lvts_ctrl->low_thresh) {
> +			/*
> +			 * The minimum threshold needs to be configured in the
> +			 * OFFSETL register to get working interrupts, but we
> +			 * don't actually want to generate interrupts when
> +			 * crossing it.
> +			 */
> +			if (lvts_ctrl->low_thresh == -INT_MAX) {
> +				value &= ~low_offset_masks[i];
> +				value |= high_offset_masks[i];
> +			} else {
> +				value |= low_offset_masks[i] | high_offset_masks[i];
> +			}
> +		} else {
> +			value &= ~(low_offset_masks[i] | high_offset_masks[i]);
> +		}
>   	}
>   
>   	writel(value, LVTS_MONINT(lvts_ctrl->base));
> 


  reply	other threads:[~2024-11-26  9:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-25 21:20 [PATCH 0/5] thermal/drivers/mediatek/lvts: Fixes for suspend and IRQ storm, and cleanups Nícolas F. R. A. Prado
2024-11-25 21:20 ` [PATCH 1/5] thermal/drivers/mediatek/lvts: Disable monitor mode during suspend Nícolas F. R. A. Prado
2024-11-26  8:00   ` Hsin-Te Yuan
2024-11-26 13:37     ` Nícolas F. R. A. Prado
2024-11-27  7:27       ` Hsin-Te Yuan
2024-11-26  9:43   ` AngeloGioacchino Del Regno
2024-11-26 13:19     ` Nícolas F. R. A. Prado
2024-11-26 14:38       ` AngeloGioacchino Del Regno
2024-11-25 21:20 ` [PATCH 2/5] thermal/drivers/mediatek/lvts: Disable Stage 3 thermal threshold Nícolas F. R. A. Prado
2024-11-26  9:43   ` AngeloGioacchino Del Regno
2024-11-25 21:20 ` [PATCH 3/5] thermal/drivers/mediatek/lvts: Disable low offset IRQ for minimum threshold Nícolas F. R. A. Prado
2024-11-26  9:43   ` AngeloGioacchino Del Regno [this message]
2024-11-25 21:20 ` [PATCH 4/5] thermal/drivers/mediatek/lvts: Start sensor interrupts disabled Nícolas F. R. A. Prado
2024-11-26  9:43   ` AngeloGioacchino Del Regno
2024-11-25 21:20 ` [PATCH 5/5] thermal/drivers/mediatek/lvts: Only update IRQ enable for valid sensors Nícolas F. R. A. Prado
2024-11-26  9:43   ` AngeloGioacchino Del Regno

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=78f440ff-1247-4d97-a170-fe2412e75d4a@collabora.com \
    --to=angelogioacchino.delregno@collabora.com \
    --cc=amergnat@baylibre.com \
    --cc=bchihi@baylibre.com \
    --cc=bero@baylibre.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=kernel@collabora.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=matthias.bgg@gmail.com \
    --cc=nfraprado@collabora.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=stable@vger.kernel.org \
    --cc=wenst@chromium.org \
    --cc=yuanhsinte@chromium.org \
    /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