summaryrefslogtreecommitdiffstats
path: root/arch/sandbox
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-06-19 05:45:08 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-06-21 08:04:36 +0200
commit84477a5d5a770133e96a44a9e2dd109ec4228d62 (patch)
tree14e0bec9a6815d493ec9641151aeb0cffb2cbb88 /arch/sandbox
parentd61d31fc4d4beaf261ff9f7f9d24907f52576d7e (diff)
downloadbarebox-84477a5d5a770133e96a44a9e2dd109ec4228d62.tar.gz
barebox-84477a5d5a770133e96a44a9e2dd109ec4228d62.tar.xz
sandbox: use nvmem on top of stickypage for reset reason
Watchdog and system reset driver use a byte in the sticky page to persist reset reason over reexec. So far, this was a byte outside partitioned space. With the new nvmem-cells binding, a partition can be dedicated to holding nvmem cells. Use that instead. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210619034516.6737-6-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/sandbox')
-rw-r--r--arch/sandbox/board/power.c35
-rw-r--r--arch/sandbox/board/watchdog.c20
-rw-r--r--arch/sandbox/dts/sandbox.dts18
3 files changed, 45 insertions, 28 deletions
diff --git a/arch/sandbox/board/power.c b/arch/sandbox/board/power.c
index 3cc9447958..57801c8c3d 100644
--- a/arch/sandbox/board/power.c
+++ b/arch/sandbox/board/power.c
@@ -4,11 +4,11 @@
#include <restart.h>
#include <mach/linux.h>
#include <reset_source.h>
-#include <mfd/syscon.h>
+#include <linux/nvmem-consumer.h>
struct sandbox_power {
struct restart_handler rst_hang, rst_reexec;
- struct regmap *src;
+ struct nvmem_cell *reset_source_cell;
u32 src_offset;
};
@@ -24,16 +24,20 @@ static void sandbox_rst_hang(struct restart_handler *rst)
static void sandbox_rst_reexec(struct restart_handler *rst)
{
+ u8 reason = RESET_RST;
struct sandbox_power *power = container_of(rst, struct sandbox_power, rst_reexec);
- regmap_update_bits(power->src, power->src_offset, 0xff, RESET_RST);
+
+ if (!IS_ERR(power->reset_source_cell))
+ WARN_ON(nvmem_cell_write(power->reset_source_cell, &reason, 1) <= 0);
+
linux_reexec();
}
static int sandbox_power_probe(struct device_d *dev)
{
struct sandbox_power *power = xzalloc(sizeof(*power));
- unsigned int rst;
- int ret;
+ size_t len = 1;
+ u8 *rst;
poweroff_handler_register_fn(sandbox_poweroff);
@@ -52,20 +56,21 @@ static int sandbox_power_probe(struct device_d *dev)
if (IS_ENABLED(CONFIG_SANDBOX_REEXEC))
restart_handler_register(&power->rst_reexec);
- power->src = syscon_regmap_lookup_by_phandle(dev->device_node, "barebox,reset-source");
- if (IS_ERR(power->src))
+ power->reset_source_cell = of_nvmem_cell_get(dev->device_node, "reset-source");
+ if (IS_ERR(power->reset_source_cell)) {
+ dev_warn(dev, "No reset source info available: %pe\n", power->reset_source_cell);
return 0;
+ }
- ret = of_property_read_u32_index(dev->device_node, "barebox,reset-source", 1,
- &power->src_offset);
- if (ret)
- return 0;
+ rst = nvmem_cell_read(power->reset_source_cell, &len);
+ if (!IS_ERR(rst)) {
+ if (*rst == 0)
+ *rst = RESET_POR;
+ reset_source_set_prinst(*rst, RESET_SOURCE_DEFAULT_PRIORITY, 0);
- ret = regmap_read(power->src, power->src_offset, &rst);
- if (ret == 0 && rst == 0)
- rst = RESET_POR;
+ free(rst);
+ }
- reset_source_set_prinst(rst, RESET_SOURCE_DEFAULT_PRIORITY, 0);
return 0;
}
diff --git a/arch/sandbox/board/watchdog.c b/arch/sandbox/board/watchdog.c
index e1cff7a0bf..ff26a2019f 100644
--- a/arch/sandbox/board/watchdog.c
+++ b/arch/sandbox/board/watchdog.c
@@ -6,7 +6,7 @@
#include <mach/linux.h>
#include <of.h>
#include <watchdog.h>
-#include <mfd/syscon.h>
+#include <linux/nvmem-consumer.h>
#include <reset_source.h>
struct sandbox_watchdog {
@@ -36,10 +36,9 @@ static int sandbox_watchdog_set_timeout(struct watchdog *wdd, unsigned int timeo
static int sandbox_watchdog_probe(struct device_d *dev)
{
struct device_node *np = dev->device_node;
+ struct nvmem_cell *reset_source_cell;
struct sandbox_watchdog *wd;
struct watchdog *wdd;
- struct regmap *src;
- u32 src_offset;
int ret;
wd = xzalloc(sizeof(*wd));
@@ -57,16 +56,17 @@ static int sandbox_watchdog_probe(struct device_d *dev)
return ret;
}
- src = syscon_regmap_lookup_by_phandle(np, "barebox,reset-source");
- if (IS_ERR(src))
- return 0;
+ reset_source_cell = of_nvmem_cell_get(dev->device_node, "reset-source");
+ if (IS_ERR(reset_source_cell)) {
+ dev_warn(dev, "No reset source info available: %pe\n", reset_source_cell);
+ goto out;
+ }
- ret = of_property_read_u32_index(np, "barebox,reset-source", 1, &src_offset);
- if (ret)
- return 0;
+ nvmem_cell_write(reset_source_cell, &(u8) { RESET_WDG }, 1);
- regmap_update_bits(src, src_offset, 0xff, RESET_WDG);
+ nvmem_cell_put(reset_source_cell);
+out:
dev_info(dev, "probed\n");
return 0;
}
diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index e99986bb90..7f8f1964e4 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -71,7 +71,17 @@
#address-cells = <1>;
#size-cells = <1>;
- /* 0x00+4 reserved for syscon use */
+ part_nvmem: nvmem@300 {
+ compatible = "nvmem-cells";
+ reg = <0x300 0x100>;
+ label = "nvmem";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ reset_source: reset-source@0 {
+ reg = <0x0 0x1>;
+ };
+ };
part_env: env@400 {
reg = <0x400 0x800>;
@@ -87,12 +97,14 @@
power {
compatible = "barebox,sandbox-power";
- barebox,reset-source = <&stickypage 0>;
+ nvmem-cell-names = "reset-source";
+ nvmem-cells = <&reset_source>;
};
watchdog {
compatible = "barebox,sandbox-watchdog";
- barebox,reset-source = <&stickypage 0>;
+ nvmem-cell-names = "reset-source";
+ nvmem-cells = <&reset_source>;
};
sound {