From: Guenter Roeck <linux@roeck-us.net>
To: Kathiravan Thirumoorthy
<kathiravan.thirumoorthy@oss.qualcomm.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
Wim Van Sebroeck <wim@linux-watchdog.org>,
bod.linux@nxsw.ie
Cc: linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-watchdog@vger.kernel.org
Subject: Re: [PATCH v3 4/4] watchdog: qcom: add support to read the restart reason from IMEM
Date: Fri, 2 May 2025 06:33:55 -0700 [thread overview]
Message-ID: <f8b57c99-2f6a-496b-a6fe-3e2aa6b0b989@roeck-us.net> (raw)
In-Reply-To: <20250502-wdt_reset_reason-v3-4-b2dc7ace38ca@oss.qualcomm.com>
On 5/2/25 06:17, Kathiravan Thirumoorthy wrote:
> When the system boots up after a watchdog reset, the EXPIRED_STATUS bit
> in the WDT_STS register is cleared. To identify if the system was
> restarted due to WDT expiry, XBL update the information in the IMEM region.
> Update the driver to read the restart reason from IMEM and populate the
> bootstatus accordingly.
>
> With the CONFIG_WATCHDOG_SYSFS enabled, user can extract the information
> as below:
>
> cat /sys/devices/platform/soc@0/f410000.watchdog/watchdog/watchdog0/bootstatus
> 32
>
> For backward compatibility, keep the EXPIRED_STATUS bit check. Add a new
> function qcom_wdt_get_restart_reason() to read the restart reason from
> IMEM.
>
> Signed-off-by: Kathiravan Thirumoorthy <kathiravan.thirumoorthy@oss.qualcomm.com>
> ---
> Changes in v3:
> - Split the introduction of device data into separate patch
> - s/bootloaders/XBL - for clarity of which bootloader is
> involved
> - Mention the sysfs path on to extract this information
> - s/compatible/imem_compatible in the device data structure to
> avoid the confusion / better naming
> Changes in v2:
> - Use the syscon API to access the IMEM region
> - Handle the error cases returned by qcom_wdt_get_restart_reason
> - Define device specific data to retrieve the IMEM compatible,
> offset and the value for non secure WDT, which allows to
> extend the support for other SoCs
> ---
> drivers/watchdog/qcom-wdt.c | 40 ++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 38 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/watchdog/qcom-wdt.c b/drivers/watchdog/qcom-wdt.c
> index dfaac5995c84c1f377023e6e62770c5548528a4c..f2cb8bfdf53a5090bcfff6ea3a23005b629ef948 100644
> --- a/drivers/watchdog/qcom-wdt.c
> +++ b/drivers/watchdog/qcom-wdt.c
> @@ -7,9 +7,11 @@
> #include <linux/interrupt.h>
> #include <linux/io.h>
> #include <linux/kernel.h>
> +#include <linux/mfd/syscon.h>
> #include <linux/module.h>
> #include <linux/of.h>
> #include <linux/platform_device.h>
> +#include <linux/regmap.h>
> #include <linux/watchdog.h>
>
> enum wdt_reg {
> @@ -42,6 +44,9 @@ struct qcom_wdt_match_data {
> const u32 *offset;
> bool pretimeout;
> u32 max_tick_count;
> + const char *imem_compatible;
> + unsigned int restart_reason_offset;
> + unsigned int non_secure_wdt_val;
> };
>
> struct qcom_wdt {
> @@ -185,6 +190,9 @@ static const struct qcom_wdt_match_data match_data_ipq5424 = {
> .offset = reg_offset_data_kpss,
> .pretimeout = true,
> .max_tick_count = 0xFFFFFU,
> + .imem_compatible = "qcom,ipq5424-imem",
> + .restart_reason_offset = 0x7b0,
> + .non_secure_wdt_val = 0x5,
> };
>
> static const struct qcom_wdt_match_data match_data_kpss = {
> @@ -193,6 +201,29 @@ static const struct qcom_wdt_match_data match_data_kpss = {
> .max_tick_count = 0xFFFFFU,
> };
>
> +static int qcom_wdt_get_restart_reason(struct qcom_wdt *wdt,
> + const struct qcom_wdt_match_data *data)
> +{
> + struct regmap *imem;
> + unsigned int val;
> + int ret;
> +
> + imem = syscon_regmap_lookup_by_compatible(data->imem_compatible);
> + if (IS_ERR(imem))
> + return PTR_ERR(imem);
> +
> + ret = regmap_read(imem, data->restart_reason_offset, &val);
> + if (ret) {
> + dev_err(wdt->wdd.parent, "failed to read the restart reason info\n");
> + return ret;
> + }
> +
> + if (val == data->non_secure_wdt_val)
> + wdt->wdd.bootstatus = WDIOF_CARDRESET;
> +
> + return 0;
> +}
> +
> static int qcom_wdt_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> @@ -273,8 +304,13 @@ static int qcom_wdt_probe(struct platform_device *pdev)
> wdt->wdd.parent = dev;
> wdt->layout = data->offset;
>
> - if (readl(wdt_addr(wdt, WDT_STS)) & 1)
> - wdt->wdd.bootstatus = WDIOF_CARDRESET;
> + ret = qcom_wdt_get_restart_reason(wdt, data);
> + if (ret == -ENODEV) {
> + if (readl(wdt_addr(wdt, WDT_STS)) & 1)
> + wdt->wdd.bootstatus = WDIOF_CARDRESET;
> + } else if (ret) {
> + return ret;
> + }
Seems odd to me that there is now a function qcom_wdt_get_restart_reason()
but it doesn't handle all means to get the restart reason. Maybe I missed it,
but what is the reason for that ? Why not move reading WDT_STS into
qcom_wdt_get_restart_reason() as well ?
Guenter
>
> /*
> * If 'timeout-sec' unspecified in devicetree, assume a 30 second
>
next prev parent reply other threads:[~2025-05-02 13:33 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-02 13:17 [PATCH v3 0/4] Add " Kathiravan Thirumoorthy
2025-05-02 13:17 ` [PATCH v3 1/4] dt-bindings: sram: qcom,imem: Document IPQ5424 compatible Kathiravan Thirumoorthy
2025-05-02 13:17 ` [PATCH v3 2/4] arm64: dts: qcom: ipq5424: Add the IMEM node Kathiravan Thirumoorthy
2025-05-02 13:17 ` [PATCH v3 3/4] watchdog: qcom: introduce the device data for IPQ5424 watchdog device Kathiravan Thirumoorthy
2025-05-02 13:36 ` Guenter Roeck
2025-05-02 14:53 ` Dmitry Baryshkov
2025-05-02 16:01 ` Kathiravan Thirumoorthy
2025-05-02 13:17 ` [PATCH v3 4/4] watchdog: qcom: add support to read the restart reason from IMEM Kathiravan Thirumoorthy
2025-05-02 13:33 ` Krzysztof Kozlowski
2025-05-02 16:02 ` Kathiravan Thirumoorthy
2025-05-02 13:33 ` Guenter Roeck [this message]
2025-05-02 16:08 ` Kathiravan Thirumoorthy
2025-05-02 22:13 ` Konrad Dybcio
2025-05-02 14:03 ` Konrad Dybcio
2025-05-02 16:28 ` Kathiravan Thirumoorthy
2025-05-02 22:23 ` Konrad Dybcio
2025-05-06 11:01 ` Kathiravan Thirumoorthy
2025-05-14 13:15 ` Kathiravan Thirumoorthy
2025-05-14 18:05 ` Guenter Roeck
2025-05-16 11:18 ` Konrad Dybcio
2025-05-16 12:52 ` Kathiravan Thirumoorthy
2025-05-16 16:35 ` Konrad Dybcio
2025-05-17 10:41 ` Kathiravan Thirumoorthy
2025-05-02 14:54 ` Dmitry Baryshkov
2025-05-02 16:31 ` Kathiravan Thirumoorthy
2025-08-11 18:40 ` (subset) [PATCH v3 0/4] Add " Bjorn Andersson
2025-08-25 12:11 ` Kathiravan Thirumoorthy
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=f8b57c99-2f6a-496b-a6fe-3e2aa6b0b989@roeck-us.net \
--to=linux@roeck-us.net \
--cc=andersson@kernel.org \
--cc=bod.linux@nxsw.ie \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=kathiravan.thirumoorthy@oss.qualcomm.com \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=robh@kernel.org \
--cc=wim@linux-watchdog.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
all inboxes | Powered by JetHome®