From: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
To: Daniel Lezcano <daniel.lezcano@linaro.org>,
bchihi@baylibre.com, rafael@kernel.org, amitk@kernel.org,
rui.zhang@intel.com
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
khilman@baylibre.com, linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, james.lo@mediatek.com,
rex-bc.chen@mediatek.com
Subject: Re: [PATCH v10 4/6] thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver
Date: Mon, 16 Jan 2023 12:52:16 +0100 [thread overview]
Message-ID: <d640f848-3f28-3089-7703-ee6cb9db32ed@collabora.com> (raw)
In-Reply-To: <1ee1152b-b83b-ed7b-6368-26601ece37e8@linaro.org>
Il 16/01/23 12:08, Daniel Lezcano ha scritto:
> On 16/01/2023 11:50, AngeloGioacchino Del Regno wrote:
>> Il 12/01/23 16:28, bchihi@baylibre.com ha scritto:
>>> From: Balsam CHIHI <bchihi@baylibre.com>
>>>
>>> The Low Voltage Thermal Sensor (LVTS) is a multiple sensors, multi
>>> controllers contained in a thermal domain.
>>>
>>> A thermal domains can be the MCU or the AP.
>>>
>>> Each thermal domains contain up to seven controllers, each thermal
>>> controller handle up to four thermal sensors.
>>>
>>> The LVTS has two Finite State Machines (FSM), one to handle the
>>> functionin temperatures range like hot or cold temperature and another
>>> one to handle monitoring trip point. The FSM notifies via interrupts
>>> when a trip point is crossed.
>>>
>>> The interrupt is managed at the thermal controller level, so when an
>>> interrupt occurs, the driver has to find out which sensor triggered
>>> such an interrupt.
>>>
>>> The sampling of the thermal can be filtered or immediate. For the
>>> former, the LVTS measures several points and applies a low pass
>>> filter.
>>>
>>> Signed-off-by: Balsam CHIHI <bchihi@baylibre.com>
>>> ---
>>> drivers/thermal/mediatek/Kconfig | 15 +
>>> drivers/thermal/mediatek/Makefile | 1 +
>>> drivers/thermal/mediatek/lvts_thermal.c | 1244 +++++++++++++++++++
>>> include/dt-bindings/thermal/mediatek-lvts.h | 19 +
>>> 4 files changed, 1279 insertions(+)
>>> create mode 100644 drivers/thermal/mediatek/lvts_thermal.c
>>> create mode 100644 include/dt-bindings/thermal/mediatek-lvts.h
>>>
>>
>> ..snip..
>>
>>> +
>>> +static int lvts_set_trips(struct thermal_zone_device *tz, int low, int high)
>>> +{
>>> + struct lvts_sensor *lvts_sensor = tz->devdata;
>>> + void __iomem *base = lvts_sensor->base;
>>> + u32 raw_low = lvts_temp_to_raw(low);
>>> + u32 raw_high = lvts_temp_to_raw(high);
>>> +
>>> + /*
>>> + * Hot to normal temperature threshold
>>> + *
>>> + * LVTS_H2NTHRE
>>> + *
>>> + * Bits:
>>> + *
>>> + * 14-0 : Raw temperature for threshold
>>> + */
>>> + if (low != -INT_MAX) {
>>> + dev_dbg(&tz->device, "Setting low limit temperature interrupt: %d\n",
>>> low);
>>> + writel(raw_low, LVTS_H2NTHRE(base));
>>> + }
>>> +
>>> + /*
>>> + * Hot temperature threshold
>>> + *
>>> + * LVTS_HTHRE
>>> + *
>>> + * Bits:
>>> + *
>>> + * 14-0 : Raw temperature for threshold
>>> + */
>>> + dev_dbg(&tz->device, "Setting high limit temperature interrupt: %d\n", high);
>>> + writel(raw_high, LVTS_HTHRE(base));
>>> +
>>> + return 0;
>>> +}
>>> +
>>> +static irqreturn_t lvts_ctrl_irq_handler(struct lvts_ctrl *lvts_ctrl)
>>> +{
>>> + irqreturn_t iret = IRQ_NONE;
>>> + u32 value, masks[] = { 0x0009001F, 0X000881F0, 0x00247C00, 0x1FC00000 };
>>
>> Please, no magic numbers around.
>>
>>> + int i;
>>> +
>>> + /*
>>> + * Interrupt monitoring status
>>> + *
>>> + * LVTS_MONINTST
>>> + *
>>> + * Bits:
>>
>> You're describing the register with nice words, but there's another way to do
>> the same that will be even more effective.
>>
>> /*
>> * LVTS MONINT: Interrupt Monitoring register
>> * Each bit describes the enable status of per-sensor interrupts.
>> */
>> #define LVTS_MONINT_THRES_COLD BIT(0) /* Cold threshold */
>> #define LVTS_MONINT_THRES_HOT BIT(1) /* Hot threshold */
>> #define LVTS_MONINT_OFFST_LOW BIT(2) /* Low offset */
>> #define LVTS_MONINT_OFFST_HIGH BIT(3) /* High offset */
>> #define LVTS_MONINT_OFFST_NTH BIT(4) /* Normal To Hot */
>> #define EVERYTHING_ELSE ........................
>
> I don't see how this is more effective than describing the register layout. If
> someone wants to hack the driver, it is much better to have the layout than this
> long list of defines for every bits of every registers.
>
This also describes the register layout, with the difference that we can use those
definitions with bitfield macros to avoid writing magic numbers around.
Anyway, I'm not against the long comment that is describing the layout with nice
words - my suggestion was just only about one of the ways to replace the magic
numbers with actual definitions.
Regards,
Angelo
next prev parent reply other threads:[~2023-01-16 11:52 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-12 15:28 [PATCH v10 0/6] Add LVTS thermal architecture bchihi
2023-01-12 15:28 ` [PATCH v10 1/6] thermal/drivers/mediatek: Relocate driver to mediatek folder bchihi
2023-01-12 20:08 ` kernel test robot
2023-01-13 10:47 ` Daniel Lezcano
2023-01-12 15:28 ` [PATCH v10 2/6] dt-bindings/thermal/mediatek: Add dt-binding document for LVTS thermal controllers bchihi
2023-01-13 8:11 ` Krzysztof Kozlowski
2023-01-13 11:54 ` Matthias Brugger
2023-01-13 14:30 ` Balsam CHIHI
2023-01-16 10:38 ` AngeloGioacchino Del Regno
2023-01-16 11:05 ` Balsam CHIHI
2023-01-12 15:28 ` [PATCH v10 3/6] arm64/dts/mt8195: Add efuse node to mt8195 bchihi
2023-01-13 11:45 ` Matthias Brugger
2023-01-16 10:38 ` AngeloGioacchino Del Regno
2023-01-12 15:28 ` [PATCH v10 4/6] thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver bchihi
2023-01-16 10:50 ` AngeloGioacchino Del Regno
2023-01-16 11:08 ` Daniel Lezcano
2023-01-16 11:52 ` AngeloGioacchino Del Regno [this message]
2023-01-18 13:58 ` Balsam CHIHI
2023-01-18 14:30 ` Daniel Lezcano
2023-01-18 14:52 ` Balsam CHIHI
2023-01-18 14:37 ` Balsam CHIHI
2023-01-12 15:28 ` [PATCH v10 5/6] arm64/dts/mt8195: Add thermal zones and thermal nodes bchihi
2023-01-12 15:28 ` [PATCH v10 6/6] arm64/dts/mt8195: Add temperature mitigation threshold bchihi
2023-01-13 11:49 ` Matthias Brugger
2023-01-13 14:24 ` Balsam CHIHI
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=d640f848-3f28-3089-7703-ee6cb9db32ed@collabora.com \
--to=angelogioacchino.delregno@collabora.com \
--cc=amitk@kernel.org \
--cc=bchihi@baylibre.com \
--cc=daniel.lezcano@linaro.org \
--cc=james.lo@mediatek.com \
--cc=khilman@baylibre.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=rafael@kernel.org \
--cc=rex-bc.chen@mediatek.com \
--cc=rui.zhang@intel.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