linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amit Kucheria <amit.kucheria@linaro.org>
To: Stephen Boyd <swboyd@chromium.org>
Cc: Andy Gross <agross@kernel.org>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Eduardo Valentin <edubezval@gmail.com>,
	linux-arm-msm <linux-arm-msm@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	sivaa@codeaurora.org, Daniel Lezcano <daniel.lezcano@linaro.org>,
	Linux PM list <linux-pm@vger.kernel.org>
Subject: Re: [PATCH 1/3] drivers: thermal: tsens: Add critical interrupt support
Date: Tue, 3 Dec 2019 10:27:09 +0530	[thread overview]
Message-ID: <CAHLCerNw_FuFeqDfckjmsSE+=ZGCn5EkvquUtDn7EEVjrw9aVQ@mail.gmail.com> (raw)
In-Reply-To: <5dcdda2a.1c69fb81.27852.ac35@mx.google.com>

On Fri, Nov 15, 2019 at 4:20 AM Stephen Boyd <swboyd@chromium.org> wrote:
>
> Quoting Amit Kucheria (2019-11-11 11:21:27)
> > diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c
> > index 4359a4247ac3..2989cb952cdb 100644
> > --- a/drivers/thermal/qcom/tsens-common.c
> > +++ b/drivers/thermal/qcom/tsens-common.c
> > @@ -321,6 +357,65 @@ static inline u32 masked_irq(u32 hw_id, u32 mask, enum tsens_ver ver)
> >         return 0;
> >  }
> >
> > +/**
> > + * tsens_critical_irq_thread - Threaded interrupt handler for critical interrupts
> > + * @irq: irq number
> > + * @data: tsens controller private data
> > + *
> > + * Check all sensors to find ones that violated their critical threshold limits.
> > + * Clear and then re-enable the interrupt.
> > + *
> > + * The level-triggered interrupt might deassert if the temperature returned to
> > + * within the threshold limits by the time the handler got scheduled. We
> > + * consider the irq to have been handled in that case.
> > + *
> > + * Return: IRQ_HANDLED
> > + */
> > +irqreturn_t tsens_critical_irq_thread(int irq, void *data)
> > +{
> > +       struct tsens_priv *priv = data;
> > +       struct tsens_irq_data d;
> > +       bool enable = true, disable = false;
>
> Why not just use true and false in the one place these variables are
> used?

Will fix.

> > +       unsigned long flags;
> > +       int temp, ret, i;
> > +
> > +       for (i = 0; i < priv->num_sensors; i++) {
> > +               struct tsens_sensor *s = &priv->sensor[i];
>
> Maybe make this const?

OK.

>
> > +               u32 hw_id = s->hw_id;
> > +
> > +               if (IS_ERR(priv->sensor[i].tzd))
>
> IS_ERR(s->tzd)?

Yup.

>
> > +                       continue;
> > +               if (!tsens_threshold_violated(priv, hw_id, &d))
> > +                       continue;
> > +               ret = get_temp_tsens_valid(s, &temp);
>
> Can this accept a const 's'?

Yes.

> > +               if (ret) {
> > +                       dev_err(priv->dev, "[%u] %s: error reading sensor\n", hw_id, __func__);
> > +                       continue;
> > +               }
> > +
> > +               spin_lock_irqsave(&priv->ul_lock, flags);
> > +
> > +               tsens_read_irq_state(priv, hw_id, s, &d);
> > +
> > +               if (d.crit_viol &&
> > +                   !masked_irq(hw_id, d.crit_irq_mask, tsens_version(priv))) {
> > +                       tsens_set_interrupt(priv, hw_id, CRITICAL, disable);
> > +                       if (d.crit_thresh > temp) {
> > +                               dev_dbg(priv->dev, "[%u] %s: re-arm upper\n",
> > +                                       priv->sensor[i].hw_id, __func__);
>
> hw_id instead of priv->sensor...?

Done. Will fixup for older code in a separate patch.

> > +                       } else {
> > +                               dev_dbg(priv->dev, "[%u] %s: TZ update trigger (%d mC)\n",
> > +                                       hw_id, __func__, temp);
> > +                       }
> > +                       tsens_set_interrupt(priv, hw_id, CRITICAL, enable);
> > +               }
> > +
> > +               spin_unlock_irqrestore(&priv->crit_lock, flags);
> > +       }
> > +
> > +       return IRQ_HANDLED;
> > +}
> > +
> >  /**
> >   * tsens_irq_thread - Threaded interrupt handler for uplow interrupts
> >   * @irq: irq number
> > diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
> > index 7d317660211e..784c4976c4f9 100644
> > --- a/drivers/thermal/qcom/tsens.c
> > +++ b/drivers/thermal/qcom/tsens.c
> > @@ -121,6 +121,27 @@ static int tsens_register(struct tsens_priv *priv)
> >
> >         enable_irq_wake(irq);
> >
> > +       if (tsens_version(priv) > VER_1_X) {
> > +               irq = platform_get_irq_byname(pdev, "critical");
> > +               if (irq < 0) {
> > +                       ret = irq;
> > +                       goto err_put_device;
> > +               }
> > +
> > +               ret = devm_request_threaded_irq(&pdev->dev, irq,
> > +                                               NULL, tsens_critical_irq_thread,
> > +                                               IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
> > +                                               dev_name(&pdev->dev), priv);
> > +               if (ret) {
> > +                       dev_err(&pdev->dev, "%s: failed to get critical irq\n", __func__);
> > +                       goto err_put_device;
>
> Do we need to disable_irq_wake() for the previous irq here?

Or we could just move the earlier enable_irq_wake() to after
successful registration of the critical interrupt to avoid the error
branch. See v2 posting.



> > +               }
> > +
> > +               enable_irq_wake(irq);
> > +       }
> > +
> > +       return 0;
> > +
> >  err_put_device:
> >         put_device(&pdev->dev);
> >         return ret;

  reply	other threads:[~2019-12-03  4:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-11 19:21 [PATCH 0/3] thermal: tsens: Handle critical interrupts Amit Kucheria
2019-11-11 19:21 ` [PATCH 1/3] drivers: thermal: tsens: Add critical interrupt support Amit Kucheria
2019-11-12 19:38   ` Bjorn Andersson
2019-11-28 18:46     ` Amit Kucheria
2019-11-28 21:43       ` Bjorn Andersson
2019-12-03  5:02         ` Amit Kucheria
2019-11-14 22:50   ` Stephen Boyd
2019-12-03  4:57     ` Amit Kucheria [this message]
2019-11-11 19:21 ` [PATCH 2/3] drivers: thermal: tsens: Add watchdog support Amit Kucheria
2019-11-12 19:22   ` Bjorn Andersson
2019-11-28 19:18     ` Amit Kucheria
2019-11-14 22:38   ` Stephen Boyd
2019-11-28 19:16     ` Amit Kucheria

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='CAHLCerNw_FuFeqDfckjmsSE+=ZGCn5EkvquUtDn7EEVjrw9aVQ@mail.gmail.com' \
    --to=amit.kucheria@linaro.org \
    --cc=agross@kernel.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=edubezval@gmail.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sivaa@codeaurora.org \
    --cc=swboyd@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;
as well as URLs for NNTP newsgroup(s).