public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Huan He" <hehuan1@eswincomputing.com>
To: "Guenter Roeck" <linux@roeck-us.net>
Cc: "Krzysztof Kozlowski" <krzk@kernel.org>,
	robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
	p.zabel@pengutronix.de, linux-hwmon@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	ningyu@eswincomputing.com, linmin@eswincomputing.com,
	pinkesh.vaghela@einfochips.com, luyulin@eswincomputing.com
Subject: Re: Re: Re: Re: [PATCH v2 0/2] Add driver support for ESWIN EIC7700 PVT controller
Date: Thu, 5 Mar 2026 19:12:37 +0800 (GMT+08:00)	[thread overview]
Message-ID: <6803a67f.3e27.19cbdb318ff.Coremail.hehuan1@eswincomputing.com> (raw)
In-Reply-To: <46752141.375d.19c5ae8161e.Coremail.hehuan1@eswincomputing.com>

Hi Guenter,

Thank you very much for your detailed review and valuable feedback. I
apologize for the delayed response.

> > 
> > # Commit 6f4d5698f334 ("hwmon: Add Eswin EIC7700 PVT sensor driver")
> > 1.  eic7700-pvt.c:487: ERROR: Unbalanced clock refcount with Runtime PM
> >     > +	pvt->clk = devm_clk_get_enabled(&pdev->dev, NULL);
> > 
> >     Using `devm_clk_get_enabled()` enables the clock and registers a devm action
> >     to disable it on removal. However, the driver also uses Runtime PM to manage
> >     the same clock:
> > 
> >     > +static int __maybe_unused eic7700_pvt_runtime_suspend(struct device *dev)
> >     > +{
> >     > +	struct pvt_hwmon *pvt = dev_get_drvdata(dev);
> >     > +
> >     > +	clk_disable_unprepare(pvt->clk);
> > 
> >     If the device is runtime suspended when `remove()` is called:
> >     1. `probe()`: `clk_prepare_enable()` (Ref: 1)
> >     2. `runtime_suspend()`: `clk_disable_unprepare()` (Ref: 0)
> >     3. `remove()` (via devm): `clk_disable_unprepare()` (Ref: -1)
> > 
> >     This leads to a refcount underflow and warning.
> > 
> >     Fix: Use `devm_clk_get()` and manually call `clk_prepare_enable()` in probe.
> >     Ensure that the manual enable is balanced correctly, or rely on Runtime PM
> >     (and `pm_runtime_get_sync` in probe) to handle the clock, ensuring
> >     `pm_runtime_put` balances it. Since `check_pwr` needs the clock before
> >     Runtime PM is enabled, you should enable it manually and then possibly
> >     disable it before enabling Runtime PM, or keep it enabled and let Runtime PM
> >     take over (but ensure `remove` doesn't double disable).
> > 
> >     A common pattern:
> >     ```c
> >     pvt->clk = devm_clk_get(dev, NULL);
> >     ...
> >     clk_prepare_enable(pvt->clk);
> >     ...
> >     pm_runtime_enable(dev);
> >     pm_runtime_get_noresume(dev);
> >     ...
> >     pm_runtime_put(dev);
> >     ```
> >     And ensure `remove` (or devm action) disables it ONLY if not suspended?
> >     Actually, simpler is:
> >     Don't use `devm_clk_get_enabled` if you use `runtime_suspend` to disable it.
> >     Use `devm_clk_get`.
> >     In probe: `clk_prepare_enable`.
> >     Register a `devm_add_action` that calls `clk_disable_unprepare` *only if* the
> >     driver is not using Runtime PM to control it? No, that's messy.
> > 
> >     Better fix:
> >     Use `devm_clk_get`.
> >     In probe: `clk_prepare_enable`.
> >     In remove (devm action?): `clk_disable_unprepare` (but this still has the issue).
> > 
> >     Correct Fix:
> >     Do not use `clk_disable_unprepare` in `runtime_suspend` if you used
> >     `devm_clk_get_enabled`.
> >     OR
> >     Don't use `devm_clk_get_enabled`. Use `devm_clk_get`.
> >     Manage the clock entirely via Runtime PM.
> >     In probe:
> >     `clk_prepare_enable(pvt->clk);` (Temporary for check_pwr)
> >     `check_pwr...`
> >     `clk_disable_unprepare(pvt->clk);`
> >     `pm_runtime_enable(dev);`
> >     ...
> 
> We will reproduce and further analyze the clock refcount imbalance
> scenario.

Regarding the Runtime PM issue potentially causing clock refcount
imbalance, we have investigated it and will address this in the v3 patch.

> 
> > 
> > 3.  eic7700-pvt.c:368: WARN: Spurious interrupts on shared IRQ line
> >     > +	eic7700_pvt_update(pvt->regs + PVT_ENA, PVT_ENA_EN, PVT_ENA_EN);
> > 
> >     `check_pwr` enables the device (and thus potential interrupts) before
> >     `request_irq` is called. If the IRQ line is shared and the device asserts
> >     an interrupt immediately, the interrupt will be unhandled (spurious) because
> >     no handler is registered yet.
> > 
> >     Fix: Request the IRQ before enabling the device, or ensure interrupts are masked
> >     at the controller level (if possible) before enabling the block. Since `check_pwr`
> >     relies on polling and ISR clears the status, moving `request_irq` is tricky.
> >     Verify if `PVT_ENA` has a separate interrupt enable bit or if `PVT_INT` has a mask.
> >     If not, this is a hardware/driver design risk.
> > 
> 
> Confirmed with the hardware team, the PVT_ENA register has no independent
> interrupt enable, and PVT_INT does not support masking.
> Enabling the device before request_irq may generate interrupts, but the
> driver disables the PVT module (PVT_ENA_EN = 0) and clears interrupts by
> writing PVT_INT_CLR. In practice, no issues have been observed.
> 

For the spurious interrupt concern: after confirming with the hardware
team, the PVT_ENA register has no independent interrupt enable, and
PVT_INT does not support masking. In the current implementation, enabling
the device during check_pwr may generate an interrupt, but the driver
subsequently disables the PVT module (PVT_ENA_EN = 0) and clears the
interrupt status by writing PVT_INT_CLR. In practice, no issues have been
observed.

Could you please confirm whether it is acceptable to keep the current
implementation under these conditions?
 
Best regards,
Huan He

  reply	other threads:[~2026-03-05 11:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-28 10:14 [PATCH v2 0/2] Add driver support for ESWIN EIC7700 PVT controller hehuan1
2026-01-28 10:16 ` [PATCH v2 1/2] dt-bindings: hwmon: Add Eswin EIC7700 PVT sensor hehuan1
2026-01-28 17:51   ` Conor Dooley
2026-01-29  3:06     ` Huan He
2026-01-29 16:42       ` Conor Dooley
2026-01-30  2:00         ` Huan He
2026-01-30 17:04           ` Conor Dooley
2026-01-28 10:17 ` [PATCH v2 2/2] hwmon: Add Eswin EIC7700 PVT sensor driver hehuan1
2026-02-11  9:55 ` [PATCH v2 0/2] Add driver support for ESWIN EIC7700 PVT controller Huan He
2026-02-11 11:05   ` Krzysztof Kozlowski
2026-02-12  4:24     ` Huan He
2026-02-12  6:05       ` Guenter Roeck
2026-02-14  6:48         ` Huan He
2026-03-05 11:12           ` Huan He [this message]
2026-03-05 14:47             ` Guenter Roeck

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=6803a67f.3e27.19cbdb318ff.Coremail.hehuan1@eswincomputing.com \
    --to=hehuan1@eswincomputing.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=krzk@kernel.org \
    --cc=linmin@eswincomputing.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=luyulin@eswincomputing.com \
    --cc=ningyu@eswincomputing.com \
    --cc=p.zabel@pengutronix.de \
    --cc=pinkesh.vaghela@einfochips.com \
    --cc=robh@kernel.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