All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 42/45] sysreset: Add a way to find the last reset
Date: Mon,  1 Oct 2018 12:22:46 -0600	[thread overview]
Message-ID: <20181001182249.129565-43-sjg@chromium.org> (raw)
In-Reply-To: <20181001182249.129565-1-sjg@chromium.org>

We have a method to return the last reset as a string for humans, but not
a method that allows it to be used programmatically. Add a new method that
returns the last reset as an enum.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/sysreset/sysreset-uclass.c  | 30 +++++++++++++++++++++++++++++
 drivers/sysreset/sysreset_sandbox.c | 12 ++++++++++++
 include/sysreset.h                  | 30 +++++++++++++++++++++++++++++
 test/dm/sysreset.c                  | 19 ++++++++++++++++++
 4 files changed, 91 insertions(+)

diff --git a/drivers/sysreset/sysreset-uclass.c b/drivers/sysreset/sysreset-uclass.c
index e38814b3ed1..ad831c703a9 100644
--- a/drivers/sysreset/sysreset-uclass.c
+++ b/drivers/sysreset/sysreset-uclass.c
@@ -36,6 +36,16 @@ int sysreset_get_status(struct udevice *dev, char *buf, int size)
 	return ops->get_status(dev, buf, size);
 }
 
+int sysreset_get_last(struct udevice *dev)
+{
+	struct sysreset_ops *ops = sysreset_get_ops(dev);
+
+	if (!ops->get_last)
+		return -ENOSYS;
+
+	return ops->get_last(dev);
+}
+
 int sysreset_walk(enum sysreset_t type)
 {
 	struct udevice *dev;
@@ -55,6 +65,26 @@ int sysreset_walk(enum sysreset_t type)
 	return ret;
 }
 
+int sysreset_get_last_walk(void)
+{
+	struct udevice *dev;
+	int value = -ENOENT;
+
+	for (uclass_first_device(UCLASS_SYSRESET, &dev);
+	     dev;
+	     uclass_next_device(&dev)) {
+		int ret;
+
+		ret = sysreset_get_last(dev);
+		if (ret >= 0) {
+			value = ret;
+			break;
+		}
+	}
+
+	return value;
+}
+
 void sysreset_walk_halt(enum sysreset_t type)
 {
 	int ret;
diff --git a/drivers/sysreset/sysreset_sandbox.c b/drivers/sysreset/sysreset_sandbox.c
index 75004d9f774..51252f7f71b 100644
--- a/drivers/sysreset/sysreset_sandbox.c
+++ b/drivers/sysreset/sysreset_sandbox.c
@@ -36,6 +36,11 @@ int sandbox_warm_sysreset_get_status(struct udevice *dev, char *buf, int size)
 	return 0;
 }
 
+int sandbox_warm_sysreset_get_last(struct udevice *dev)
+{
+	return SYSRESET_WARM;
+}
+
 static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type)
 {
 	struct sandbox_state *state = state_get_current();
@@ -74,9 +79,15 @@ int sandbox_sysreset_get_status(struct udevice *dev, char *buf, int size)
 	return 0;
 }
 
+int sandbox_sysreset_get_last(struct udevice *dev)
+{
+	return SYSRESET_COLD;
+}
+
 static struct sysreset_ops sandbox_sysreset_ops = {
 	.request	= sandbox_sysreset_request,
 	.get_status	= sandbox_sysreset_get_status,
+	.get_last	= sandbox_sysreset_get_last,
 };
 
 static const struct udevice_id sandbox_sysreset_ids[] = {
@@ -94,6 +105,7 @@ U_BOOT_DRIVER(sysreset_sandbox) = {
 static struct sysreset_ops sandbox_warm_sysreset_ops = {
 	.request	= sandbox_warm_sysreset_request,
 	.get_status	= sandbox_warm_sysreset_get_status,
+	.get_last	= sandbox_warm_sysreset_get_last,
 };
 
 static const struct udevice_id sandbox_warm_sysreset_ids[] = {
diff --git a/include/sysreset.h b/include/sysreset.h
index 343e46f1aa5..61295e3fcbb 100644
--- a/include/sysreset.h
+++ b/include/sysreset.h
@@ -11,6 +11,7 @@ enum sysreset_t {
 	SYSRESET_WARM,	/* Reset CPU, keep GPIOs active */
 	SYSRESET_COLD,	/* Reset CPU and GPIOs */
 	SYSRESET_POWER,	/* Reset PMIC (remove and restore power) */
+	SYSRESET_POWER_OFF,	/* Turn off power */
 
 	SYSRESET_COUNT,
 };
@@ -37,6 +38,14 @@ struct sysreset_ops {
 	 * @return 0 if OK, -ve on error
 	 */
 	int (*get_status)(struct udevice *dev, char *buf, int size);
+
+	/**
+	 * get_last() - get information on the last reset
+	 *
+	 * @dev:	Device to check
+	 * @return last reset state (enum sysreset_t) or -ve error
+	 */
+	int (*get_last)(struct udevice *dev);
 };
 
 #define sysreset_get_ops(dev)        ((struct sysreset_ops *)(dev)->driver->ops)
@@ -59,6 +68,14 @@ int sysreset_request(struct udevice *dev, enum sysreset_t type);
  */
 int sysreset_get_status(struct udevice *dev, char *buf, int size);
 
+/**
+ * sysreset_get_last() - get information on the last reset
+ *
+ * @dev:	Device to check
+ * @return last reset state (enum sysreset_t) or -ve error
+ */
+int sysreset_get_last(struct udevice *dev);
+
 /**
  * sysreset_walk() - cause a system reset
  *
@@ -73,6 +90,19 @@ int sysreset_get_status(struct udevice *dev, char *buf, int size);
  */
 int sysreset_walk(enum sysreset_t type);
 
+/**
+ * sysreset_get_last_walk() - get information on the last reset
+ *
+ * This works through the available sysreset devices until it finds one that can
+ * perform a reset. If the provided sysreset type is not available, the next one
+ * will be tried.
+ *
+ * If no device prives the information, this function returns -ENOENT
+ *
+ * @return last reset state (enum sysreset_t) or -ve error
+ */
+int sysreset_get_last_walk(void);
+
 /**
  * sysreset_walk_halt() - try to reset, otherwise halt
  *
diff --git a/test/dm/sysreset.c b/test/dm/sysreset.c
index 218cc239cc6..a4607fa857e 100644
--- a/test/dm/sysreset.c
+++ b/test/dm/sysreset.c
@@ -90,3 +90,22 @@ static int dm_test_sysreset_walk(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_sysreset_walk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+static int dm_test_sysreset_get_last(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+
+	/* Device 1 is the warm sysreset device */
+	ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev));
+	ut_asserteq(SYSRESET_WARM, sysreset_get_last(dev));
+
+	/* Device 2 is the cold sysreset device */
+	ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev));
+	ut_asserteq(SYSRESET_COLD, sysreset_get_last(dev));
+
+	/* This is device 0, the non-DT one */
+	ut_asserteq(SYSRESET_COLD, sysreset_get_last_walk());
+
+	return 0;
+}
+DM_TEST(dm_test_sysreset_get_last, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.19.0.605.g01d371f741-goog

  parent reply	other threads:[~2018-10-01 18:22 UTC|newest]

Thread overview: 106+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-01 18:22 [U-Boot] [PATCH 00/45] Various fixes and improvements Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 01/45] dm: core: Alloc uclass-private data to be cache-aligned Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 02/45] dm: core: Update some functions to use const Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 03/45] dm: core: Add a function to find the first inactive child Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 04/45] dm: core: Update ofnode to read binman-style flash entry Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 05/45] sf: Avoid allocating memory on every read operation Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 06/45] spl: input: Allow input in SPL and TPL Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 07/45] Makefile: Add a warning if SPL/TPL cannot be built Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 08/45] spl: misc: Allow misc drivers in SPL and TPL Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 09/45] blk: Support block drivers in TPL Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 10/45] Kconfig: Convert CONFIG_RTC_MC146818 to Kconfig Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 11/45] rtc: Allow use of RTC in SPL and TPL Simon Glass
2018-10-11 19:21   ` [U-Boot] [U-Boot,11/45] " Heinrich Schuchardt
2018-10-11 19:56     ` Heinrich Schuchardt
2018-10-13  2:46       ` Bin Meng
2018-10-19  3:25         ` Simon Glass
2018-10-19  4:20           ` Bin Meng
2018-10-01 18:22 ` [U-Boot] [PATCH 12/45] fdt: Document the fact that dtc is now built Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 13/45] doc: Update docs for device tree in SPL, TPL Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 14/45] fdt: Allow indicating a node is for U-Boot proper only Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 15/45] tpm: Add support for SPL and TPL Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 16/45] serial: Allow serial to be absent in TPL Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 17/45] fdt: Allow libfdt " Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 18/45] cros: Update cros_ec code to use struct udevice Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 19/45] cros: Adjust board_get_cros_ec_dev() to return a udevice Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 20/45] dm: spi: Add logging of some return values Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 21/45] fdt: Remove fdtdec_decode_region() function Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 22/45] video: Adjust video_clear() to return an error Simon Glass
2018-10-01 19:23   ` Anatolij Gustschin
2018-10-09 23:55   ` sjg at google.com
2018-10-01 18:22 ` [U-Boot] [PATCH 23/45] tpm: Use livetree and allow children Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 24/45] tpm: Tidy up logging in tpm-common.c Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 25/45] tpm: Add a few new commands for v1 Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 26/45] binman: Move to three-digit test-file numbers Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 27/45] binman: Add a test for Intel reference code Simon Glass
2018-10-22 20:54   ` [U-Boot] [U-Boot, " Tom Rini
2018-10-01 18:22 ` [U-Boot] [PATCH 28/45] log: Add comments to the rest of the log categories Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 29/45] malloc_simple: Add logging of allocations Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 30/45] Add a header file for strings Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 31/45] Rename GPT_HEADER_SIGNATURE to avoid conflict Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 32/45] cros: Update ec_commands to latest version Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 33/45] x86: Update mtrr functions to allow leaving cache alone Simon Glass
2018-10-02 13:41   ` Bin Meng
2018-10-09 23:54   ` sjg at google.com
2018-10-01 18:22 ` [U-Boot] [PATCH 34/45] cros_ec: Update cros_ec_read_hash() to specify the image Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 35/45] cros_ec: Add support for v3 messages on LPC Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 36/45] test: panel: Add a test for the panel uclass Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 37/45] panel: Expand the backlight support Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 38/45] ctags: Minor changes to fix ctags output Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 39/45] fdt: Allow C++ comments in link scripts and DT files Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 40/45] pci: Add a little more debugging to pci_rom Simon Glass
2018-10-02 13:37   ` Bin Meng
2018-10-09 23:54   ` sjg at google.com
2018-10-01 18:22 ` [U-Boot] [PATCH 41/45] sysreset: Tidy up a few comments and logging Simon Glass
2018-10-01 18:22 ` Simon Glass [this message]
2018-10-01 18:22 ` [U-Boot] [PATCH 43/45] video: at91: Adjust vidconsole_position_cursor() to use char pos Simon Glass
2018-10-01 20:22   ` Anatolij Gustschin
2018-10-02  7:37     ` Eugen Hristev
2018-10-09  3:40       ` Simon Glass
2018-10-09 10:44         ` Eugen.Hristev at microchip.com
2018-10-09 23:54         ` sjg at google.com
2018-10-09  3:41     ` Simon Glass
2018-10-01 18:22 ` [U-Boot] [PATCH 44/45] video: Tidy up a few comments in video.o Simon Glass
2018-10-01 19:25   ` Anatolij Gustschin
2018-10-09 23:54   ` sjg at google.com
2018-10-01 18:22 ` [U-Boot] [PATCH 45/45] dtoc: Fix the value of SetInt() Simon Glass
2018-10-09 23:54 ` sjg at google.com
2018-10-09 23:54 ` [U-Boot] [PATCH 42/45] sysreset: Add a way to find the last reset sjg at google.com
2018-10-09 23:54 ` [U-Boot] [PATCH 41/45] sysreset: Tidy up a few comments and logging sjg at google.com
2018-10-09 23:54 ` [U-Boot] [PATCH 38/45] ctags: Minor changes to fix ctags output sjg at google.com
2018-10-09 23:54 ` [U-Boot] [PATCH 39/45] fdt: Allow C++ comments in link scripts and DT files sjg at google.com
2018-10-09 23:54 ` [U-Boot] [PATCH 37/45] panel: Expand the backlight support sjg at google.com
2018-10-09 23:54 ` [U-Boot] [PATCH 36/45] test: panel: Add a test for the panel uclass sjg at google.com
2018-10-09 23:54 ` [U-Boot] [PATCH 35/45] cros_ec: Add support for v3 messages on LPC sjg at google.com
2018-10-09 23:54 ` [U-Boot] [PATCH 34/45] cros_ec: Update cros_ec_read_hash() to specify the image sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 32/45] cros: Update ec_commands to latest version sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 31/45] Rename GPT_HEADER_SIGNATURE to avoid conflict sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 30/45] Add a header file for strings sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 29/45] malloc_simple: Add logging of allocations sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 28/45] log: Add comments to the rest of the log categories sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 27/45] binman: Add a test for Intel reference code sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 26/45] binman: Move to three-digit test-file numbers sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 25/45] tpm: Add a few new commands for v1 sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 24/45] tpm: Tidy up logging in tpm-common.c sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 23/45] tpm: Use livetree and allow children sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 21/45] fdt: Remove fdtdec_decode_region() function sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 20/45] dm: spi: Add logging of some return values sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 19/45] cros: Adjust board_get_cros_ec_dev() to return a udevice sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 18/45] cros: Update cros_ec code to use struct udevice sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 17/45] fdt: Allow libfdt in TPL sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 16/45] serial: Allow serial to be absent " sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 15/45] tpm: Add support for SPL and TPL sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 14/45] fdt: Allow indicating a node is for U-Boot proper only sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 13/45] doc: Update docs for device tree in SPL, TPL sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 12/45] fdt: Document the fact that dtc is now built sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 11/45] rtc: Allow use of RTC in SPL and TPL sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 10/45] Kconfig: Convert CONFIG_RTC_MC146818 to Kconfig sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 09/45] blk: Support block drivers in TPL sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 08/45] spl: misc: Allow misc drivers in SPL and TPL sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 07/45] Makefile: Add a warning if SPL/TPL cannot be built sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 06/45] spl: input: Allow input in SPL and TPL sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 05/45] sf: Avoid allocating memory on every read operation sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 04/45] dm: core: Update ofnode to read binman-style flash entry sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 03/45] dm: core: Add a function to find the first inactive child sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 02/45] dm: core: Update some functions to use const sjg at google.com
2018-10-09 23:55 ` [U-Boot] [PATCH 01/45] dm: core: Alloc uclass-private data to be cache-aligned sjg at google.com

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=20181001182249.129565-43-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.