From: Priyansh Jain <quic_priyjain@quicinc.com>
To: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Cc: Amit Kucheria <amitk@kernel.org>,
Thara Gopinath <thara.gopinath@gmail.com>,
Bjorn Andersson <andersson@kernel.org>,
"Konrad Dybcio" <konrad.dybcio@linaro.org>,
"Rafael J . Wysocki" <rafael@kernel.org>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Zhang Rui <rui.zhang@intel.com>,
Lukasz Luba <lukasz.luba@arm.com>, <linux-pm@vger.kernel.org>,
<linux-arm-msm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<quic_manafm@quicinc.com>
Subject: Re: [PATCH] thermal/drivers/tsens: Add suspend to RAM support for tsens
Date: Wed, 24 Jan 2024 16:07:12 +0530 [thread overview]
Message-ID: <836632f2-6384-1585-abf2-e4fd368318d4@quicinc.com> (raw)
In-Reply-To: <CAA8EJprUmw-Q1aXUrP-T1dtJE-UUmqgb3RY7_+J4fetJKk11+Q@mail.gmail.com>
On 1/22/2024 7:24 PM, Dmitry Baryshkov wrote:
> On Mon, 22 Jan 2024 at 12:11, Priyansh Jain <quic_priyjain@quicinc.com> wrote:
>>
>> Add suspend callback support for tsens which disables tsens interrupts
>> in suspend to RAM callback.
>> Add resume callback support for tsens which reinitializes tsens hardware
>> and enables back tsens interrupts in resume callback.
>
> This describes what the patch does. This is more or less obvious from
> the patch itself. Instead it should describe why this is necessary.
>
sure will update in next version.
Regards,
Priyansh
>>
>> Signed-off-by: Priyansh Jain <quic_priyjain@quicinc.com>
>> ---
>> drivers/thermal/qcom/tsens-v2.c | 2 +
>> drivers/thermal/qcom/tsens.c | 93 +++++++++++++++++++++++++++++++--
>> drivers/thermal/qcom/tsens.h | 7 +++
>> 3 files changed, 98 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/thermal/qcom/tsens-v2.c b/drivers/thermal/qcom/tsens-v2.c
>> index 29a61d2d6ca3..1b74db6299c4 100644
>> --- a/drivers/thermal/qcom/tsens-v2.c
>> +++ b/drivers/thermal/qcom/tsens-v2.c
>> @@ -107,6 +107,8 @@ static const struct reg_field tsens_v2_regfields[MAX_REGFIELDS] = {
>> static const struct tsens_ops ops_generic_v2 = {
>> .init = init_common,
>> .get_temp = get_temp_tsens_valid,
>> + .suspend = tsens_suspend_common,
>> + .resume = tsens_resume_common,
>> };
>>
>> struct tsens_plat_data data_tsens_v2 = {
>> diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
>> index 6d7c16ccb44d..603ccb91009d 100644
>> --- a/drivers/thermal/qcom/tsens.c
>> +++ b/drivers/thermal/qcom/tsens.c
>> @@ -17,6 +17,7 @@
>> #include <linux/pm.h>
>> #include <linux/regmap.h>
>> #include <linux/slab.h>
>> +#include <linux/suspend.h>
>> #include <linux/thermal.h>
>> #include "../thermal_hwmon.h"
>> #include "tsens.h"
>> @@ -1153,7 +1154,7 @@ static const struct thermal_zone_device_ops tsens_of_ops = {
>> };
>>
>> static int tsens_register_irq(struct tsens_priv *priv, char *irqname,
>> - irq_handler_t thread_fn)
>> + irq_handler_t thread_fn, int *irq_num)
>> {
>> struct platform_device *pdev;
>> int ret, irq;
>> @@ -1169,6 +1170,7 @@ static int tsens_register_irq(struct tsens_priv *priv, char *irqname,
>> if (irq == -ENXIO)
>> ret = 0;
>> } else {
>> + *irq_num = irq;
>> /* VER_0 interrupt is TRIGGER_RISING, VER_0_1 and up is ONESHOT */
>> if (tsens_version(priv) == VER_0)
>> ret = devm_request_threaded_irq(&pdev->dev, irq,
>> @@ -1193,6 +1195,85 @@ static int tsens_register_irq(struct tsens_priv *priv, char *irqname,
>> return ret;
>> }
>>
>> +static int tsens_reinit(struct tsens_priv *priv)
>> +{
>> + unsigned long flags;
>> +
>> + spin_lock_irqsave(&priv->ul_lock, flags);
>> +
>> + /* in VER_0 TSENS need to be explicitly enabled */
>> + if (tsens_version(priv) == VER_0)
>> + regmap_field_write(priv->rf[TSENS_EN], 1);
>> +
>> + /*
>> + * Re-enable the watchdog, unmask the bark.
>> + * Disable cycle completion monitoring
>> + */
>> + if (priv->feat->has_watchdog) {
>> + regmap_field_write(priv->rf[WDOG_BARK_MASK], 0);
>> + regmap_field_write(priv->rf[CC_MON_MASK], 1);
>> + }
>> +
>> + /* Re-enable interrupts */
>> + if (tsens_version(priv) >= VER_0_1)
>> + tsens_enable_irq(priv);
>> +
>> + spin_unlock_irqrestore(&priv->ul_lock, flags);
>> +
>> + return 0;
>> +}
>> +
>> +int tsens_suspend_common(struct tsens_priv *priv)
>> +{
>> + switch (pm_suspend_target_state) {
>> + case PM_SUSPEND_MEM:
>> + if (priv->combo_irq > 0) {
>> + disable_irq_nosync(priv->combo_irq);
>> + disable_irq_wake(priv->combo_irq);
>> + }
>> +
>> + if (priv->uplow_irq > 0) {
>> + disable_irq_nosync(priv->uplow_irq);
>> + disable_irq_wake(priv->uplow_irq);
>> + }
>> +
>> + if (priv->crit_irq > 0) {
>> + disable_irq_nosync(priv->crit_irq);
>> + disable_irq_wake(priv->crit_irq);
>> + }
>> + break;
>> + default:
>> + break;
>> + }
>> + return 0;
>> +}
>> +
>> +int tsens_resume_common(struct tsens_priv *priv)
>> +{
>> + switch (pm_suspend_target_state) {
>> + case PM_SUSPEND_MEM:
>> + tsens_reinit(priv);
>> + if (priv->combo_irq > 0) {
>> + enable_irq(priv->combo_irq);
>> + enable_irq_wake(priv->combo_irq);
>> + }
>> +
>> + if (priv->uplow_irq > 0) {
>> + enable_irq(priv->uplow_irq);
>> + enable_irq_wake(priv->uplow_irq);
>> + }
>> +
>> + if (priv->crit_irq > 0) {
>> + enable_irq(priv->crit_irq);
>> + enable_irq_wake(priv->crit_irq);
>> + }
>> + break;
>> + default:
>> + break;
>> + }
>> + return 0;
>> +}
>> +
>> static int tsens_register(struct tsens_priv *priv)
>> {
>> int i, ret;
>> @@ -1227,15 +1308,19 @@ static int tsens_register(struct tsens_priv *priv)
>>
>> if (priv->feat->combo_int) {
>> ret = tsens_register_irq(priv, "combined",
>> - tsens_combined_irq_thread);
>> + tsens_combined_irq_thread,
>> + &priv->combo_irq);
>> } else {
>> - ret = tsens_register_irq(priv, "uplow", tsens_irq_thread);
>> + ret = tsens_register_irq(priv, "uplow",
>> + tsens_irq_thread,
>> + &priv->uplow_irq);
>> if (ret < 0)
>> return ret;
>>
>> if (priv->feat->crit_int)
>> ret = tsens_register_irq(priv, "critical",
>> - tsens_critical_irq_thread);
>> + tsens_critical_irq_thread,
>> + &priv->crit_irq);
>> }
>>
>> return ret;
>> diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
>> index cb637fa289ca..268bf56105be 100644
>> --- a/drivers/thermal/qcom/tsens.h
>> +++ b/drivers/thermal/qcom/tsens.h
>> @@ -582,6 +582,11 @@ struct tsens_priv {
>> const struct reg_field *fields;
>> const struct tsens_ops *ops;
>>
>> + /* For saving irq number to re-use later */
>> + int uplow_irq;
>> + int crit_irq;
>> + int combo_irq;
>> +
>> struct dentry *debug_root;
>> struct dentry *debug;
>>
>> @@ -634,6 +639,8 @@ void compute_intercept_slope(struct tsens_priv *priv, u32 *pt1, u32 *pt2, u32 mo
>> int init_common(struct tsens_priv *priv);
>> int get_temp_tsens_valid(const struct tsens_sensor *s, int *temp);
>> int get_temp_common(const struct tsens_sensor *s, int *temp);
>> +int tsens_suspend_common(struct tsens_priv *priv);
>> +int tsens_resume_common(struct tsens_priv *priv);
>>
>> /* TSENS target */
>> extern struct tsens_plat_data data_8960;
>> --
>> 2.17.1
>>
>>
>
>
next prev parent reply other threads:[~2024-01-24 10:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-22 10:07 Priyansh Jain
2024-01-22 13:54 ` Dmitry Baryshkov
2024-01-24 10:37 ` Priyansh Jain [this message]
2024-01-22 14:32 ` Konrad Dybcio
2024-01-24 10:42 ` Priyansh Jain
2024-01-24 12:34 ` Konrad Dybcio
2024-01-24 15:25 ` Priyansh Jain
2024-01-25 11:08 ` Konrad Dybcio
2024-01-27 15:37 ` Manaf Meethalavalappu Pallikunhi
2024-02-23 5:20 ` Priyansh Jain
2024-01-27 20:11 ` Amit Kucheria
2024-02-27 16:06 ` Priyansh Jain
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=836632f2-6384-1585-abf2-e4fd368318d4@quicinc.com \
--to=quic_priyjain@quicinc.com \
--cc=amitk@kernel.org \
--cc=andersson@kernel.org \
--cc=daniel.lezcano@linaro.org \
--cc=dmitry.baryshkov@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=lukasz.luba@arm.com \
--cc=quic_manafm@quicinc.com \
--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®