diff mbox series

[3/3] firmware: xilinx: Add sysfs to get last reset reason

Message ID 1599697204-32103-4-git-send-email-amit.sunil.dhamne@xilinx.com (mailing list archive)
State New, archived
Headers show
Series firmware: xilinx: Add support to get last reset reason | expand

Commit Message

Amit Sunil Dhamne Sept. 10, 2020, 12:20 a.m. UTC
From: Tejas Patel <tejas.patel@xilinx.com>

Add sysfs to get last reset reason.

Signed-off-by: Tejas Patel <tejas.patel@xilinx.com>
Signed-off-by: Amit Sunil Dhamne <amit.sunil.dhamne@xilinx.com>
---
 .../ABI/stable/sysfs-driver-firmware-zynqmp        | 13 ++++++++
 drivers/firmware/xilinx/zynqmp.c                   | 37 ++++++++++++++++++++++
 include/linux/firmware/xlnx-zynqmp.h               | 11 +++++++
 3 files changed, 61 insertions(+)

--
2.7.4

This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.
diff mbox series

Patch

diff --git a/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp b/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp
index 00fa04c..96a5760 100644
--- a/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp
+++ b/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp
@@ -101,3 +101,16 @@  Description:
                # echo 0 > /sys/devices/platform/firmware\:zynqmp-firmware/health_status

 Users:         Xilinx
+
+What:          /sys/devices/platform/firmware\:zynqmp-firmware/last_reset_reason
+Date:          June 2020
+KernelVersion: 5.9.0
+Contact:       "Tejas Patel" <tejasp@xilinx.com>
+Description:
+               This sysfs interface allows to get last reset reason.
+
+               Usage:
+               Get last reset reason
+               # cat /sys/devices/platform/firmware\:zynqmp-firmware/last_reset_reason
+
+Users:         Xilinx
diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c
index c5db34f..f590856 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp.c
@@ -1266,6 +1266,42 @@  static DEVICE_ATTR_RW(pggs1);
 static DEVICE_ATTR_RW(pggs2);
 static DEVICE_ATTR_RW(pggs3);

+static ssize_t last_reset_reason_show(struct device *device,
+                                     struct device_attribute *attr, char *buf)
+{
+       int ret;
+       u32 ret_payload[PAYLOAD_ARG_CNT];
+
+       ret = zynqmp_pm_get_last_reset_reason(ret_payload);
+       if (-EINVAL == ret)
+               return sprintf(buf, "Feature not supported\n");
+       else if (ret)
+               return ret;
+
+       switch (ret_payload[1]) {
+       case PM_RESET_REASON_EXT_POR:
+               return sprintf(buf, "ext_por\n");
+       case PM_RESET_REASON_SW_POR:
+               return sprintf(buf, "sw_por\n");
+       case PM_RESET_REASON_SLR_POR:
+               return sprintf(buf, "sl_por\n");
+       case PM_RESET_REASON_ERR_POR:
+               return sprintf(buf, "err_por\n");
+       case PM_RESET_REASON_DAP_SRST:
+               return sprintf(buf, "dap_srst\n");
+       case PM_RESET_REASON_ERR_SRST:
+               return sprintf(buf, "err_srst\n");
+       case PM_RESET_REASON_SW_SRST:
+               return sprintf(buf, "sw_srst\n");
+       case PM_RESET_REASON_SLR_SRST:
+               return sprintf(buf, "slr_srst\n");
+       default:
+               return sprintf(buf, "unknown reset\n");
+       }
+}
+
+static DEVICE_ATTR_RO(last_reset_reason);
+
 static struct attribute *zynqmp_firmware_attrs[] = {
        &dev_attr_ggs0.attr,
        &dev_attr_ggs1.attr,
@@ -1277,6 +1313,7 @@  static struct attribute *zynqmp_firmware_attrs[] = {
        &dev_attr_pggs3.attr,
        &dev_attr_shutdown_scope.attr,
        &dev_attr_health_status.attr,
+       &dev_attr_last_reset_reason.attr,
        NULL,
 };

diff --git a/include/linux/firmware/xlnx-zynqmp.h b/include/linux/firmware/xlnx-zynqmp.h
index 90c8664..f7cb0a9 100644
--- a/include/linux/firmware/xlnx-zynqmp.h
+++ b/include/linux/firmware/xlnx-zynqmp.h
@@ -302,6 +302,17 @@  enum zynqmp_pm_shutdown_subtype {
        ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM,
 };

+enum pm_reset_reason {
+       PM_RESET_REASON_EXT_POR = 0,
+       PM_RESET_REASON_SW_POR = 1,
+       PM_RESET_REASON_SLR_POR = 2,
+       PM_RESET_REASON_ERR_POR = 3,
+       PM_RESET_REASON_DAP_SRST = 7,
+       PM_RESET_REASON_ERR_SRST = 8,
+       PM_RESET_REASON_SW_SRST = 9,
+       PM_RESET_REASON_SLR_SRST = 10,
+};
+
 /**
  * struct zynqmp_pm_query_data - PM query data
  * @qid:       query ID