Re: [PATCH v8 4/5] watchdog: qcom: add support to get the bootstatus from IMEM
From: Konrad Dybcio
Date: Fri Feb 27 2026 - 06:01:10 EST
On 2/27/26 8:42 AM, Guenter Roeck wrote:
> On 2/26/26 08:59, 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_bootstatus() to read the restart reason from
>> IMEM.
>>
>> Reviewed-by: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx>
>> Signed-off-by: Kathiravan Thirumoorthy <kathiravan.thirumoorthy@xxxxxxxxxxxxxxxx>
>> ---
>> Changes in v8:
>> - Picked up the R-b tag
>> - Updated the comment as suggested by Konrad
>> Changes in v7:
>> - no changes
>> Changes in v6:
>> - Reworked to get the restart reason code from SRAM region
>>
>> Changes in v5:
>> - Use dev_err_probe instead of dev_err
>>
>> Changes in v4:
>> - Kept only WDIOF_CARDRESET and dropped other codes
>> - Renamed qcom_wdt_get_reason_reason() to
>> qcom_wdt_get_bootstatus()
>> - Moved the existing check inside qcom_wdt_get_bootstatus()
>> - Dropped the device data and put all the details in the DT node
>>
>> 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 | 42 ++++++++++++++++++++++++++++++++++++++++--
>> 1 file changed, 40 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/watchdog/qcom-wdt.c b/drivers/watchdog/qcom-wdt.c
>> index dfaac5995c84c1f377023e6e62770c5548528a4c..bbf229a7b5840714b9429f4b092ec3f7a6a26961 100644
>> --- a/drivers/watchdog/qcom-wdt.c
>> +++ b/drivers/watchdog/qcom-wdt.c
>> @@ -9,6 +9,7 @@
>> #include <linux/kernel.h>
>> #include <linux/module.h>
>> #include <linux/of.h>
>> +#include <linux/of_address.h>
>> #include <linux/platform_device.h>
>> #include <linux/watchdog.h>
>> @@ -42,6 +43,7 @@ struct qcom_wdt_match_data {
>> const u32 *offset;
>> bool pretimeout;
>> u32 max_tick_count;
>> + u32 wdt_reason_val;
>> };
>> struct qcom_wdt {
>> @@ -185,6 +187,7 @@ static const struct qcom_wdt_match_data match_data_ipq5424 = {
>> .offset = reg_offset_data_kpss,
>> .pretimeout = true,
>> .max_tick_count = 0xFFFFFU,
>> + .wdt_reason_val = 5,
>> };
>> static const struct qcom_wdt_match_data match_data_kpss = {
>> @@ -193,6 +196,40 @@ static const struct qcom_wdt_match_data match_data_kpss = {
>> .max_tick_count = 0xFFFFFU,
>> };
>> +static int qcom_wdt_get_bootstatus(struct device *dev, struct qcom_wdt *wdt,
>> + u32 val)
>> +{
>> + struct device_node *imem;
>> + struct resource res;
>> + void __iomem *addr;
>> + int ret;
>> +
>> + imem = of_parse_phandle(dev->of_node, "sram", 0);
>> + if (!imem) {
>> + /* Read the EXPIRED_STATUS bit as a fallback */
>> + if (readl(wdt_addr(wdt, WDT_STS)) & 1)
>> + wdt->wdd.bootstatus = WDIOF_CARDRESET;
>> +
>> + return 0;
>> + }
>> +
>> + ret = of_address_to_resource(imem, 0, &res);
>> + of_node_put(imem);
>> + if (ret)
>> + return ret;
>> +
>> + addr = ioremap(res.start, resource_size(&res));
>> + if (!addr)
>> + return -ENOMEM;
>> +
>> + if (readl(addr) == val)
>> + wdt->wdd.bootstatus = WDIOF_CARDRESET;
>> +
>> + iounmap(addr);
>> +
>> + return 0;
>> +}
>> +
>> static int qcom_wdt_probe(struct platform_device *pdev)
>> {
>> struct device *dev = &pdev->dev;
>> @@ -273,8 +310,9 @@ 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_bootstatus(dev, wdt, data->wdt_reason_val);
>> + if (ret)
>> + return ret;
>>
>
> Why is reporting the boot status so important that the failure to read it
> results in refusing to instantiate the driver ? That warrants a detailed
> explanation, even more so since it is not backward compatible.
This only fails if the reference passed in the new 'sram' property is present,
but invalid
Konrad