summaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2015-03-10 15:54:26 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2015-03-12 08:28:31 +0100
commit1487e6b9ad2ec0fafb0a2a35c921a33fb6c37fec (patch)
tree22ae6baae5a65993b9ad46b39bdbc1e7f210b79e /drivers/misc
parentdcc4a70a3c279669d21a90764cda29854244c237 (diff)
downloadbarebox-1487e6b9ad2ec0fafb0a2a35c921a33fb6c37fec.tar.gz
barebox-1487e6b9ad2ec0fafb0a2a35c921a33fb6c37fec.tar.xz
state: add framework for persistent state handling
This patch adds a framework to describe, access, store and restore a set of variables. A state variable set can be fully described in a devicetree node. This node could be part of the regular devicetree blob or it could be an extra devicetree solely for the state. The state variable set contains variables of different types and a place to store the variable set. For more information see: Documentation/devicetree/bindings/barebox/barebox,state.rst Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Jan Luebbe <jlu@pengutronix.de> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/Kconfig4
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/state.c81
3 files changed, 86 insertions, 0 deletions
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index c34a4af512..7a5b14697e 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -15,4 +15,8 @@ config SRAM
help
This driver adds support for memory mapped SRAM.
+config STATE_DRV
+ tristate "state driver"
+ depends on STATE
+
endmenu
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 908c8cb708..487e4b8ba2 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -4,3 +4,4 @@
obj-$(CONFIG_JTAG) += jtag.o
obj-$(CONFIG_SRAM) += sram.o
+obj-$(CONFIG_STATE_DRV) += state.o
diff --git a/drivers/misc/state.c b/drivers/misc/state.c
new file mode 100644
index 0000000000..f066a836cb
--- /dev/null
+++ b/drivers/misc/state.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2013 Sascha Hauer <s.hauer@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <common.h>
+#include <driver.h>
+#include <init.h>
+#include <malloc.h>
+#include <of.h>
+#include <state.h>
+
+#include <linux/err.h>
+
+static int state_probe(struct device_d *dev)
+{
+ struct device_node *np = dev->device_node;
+ struct state *state;
+ const char *alias;
+ const char *backend_type = NULL;
+ int ret;
+ char *path;
+
+ if (!np)
+ return -EINVAL;
+
+ alias = of_alias_get(np);
+ if (!alias)
+ alias = "state";
+
+ state = state_new_from_node(alias, np);
+ if (IS_ERR(state))
+ return PTR_ERR(state);
+
+ ret = of_find_path(np, "backend", &path);
+ if (ret)
+ return ret;
+
+ dev_info(dev, "outpath: %s\n", path);
+
+ ret = of_property_read_string(np, "backend-type", &backend_type);
+ if (ret)
+ return ret;
+ else if (!strcmp(backend_type, "raw"))
+ ret = state_backend_raw_file(state, path, 0, 0);
+ else if (!strcmp(backend_type, "dtb"))
+ ret = state_backend_dtb_file(state, path);
+ else
+ dev_warn(dev, "invalid backend type: %s\n", backend_type);
+
+ if (ret)
+ return ret;
+
+ state_load(state);
+
+ return 0;
+}
+
+static __maybe_unused struct of_device_id state_ids[] = {
+ {
+ .compatible = "barebox,state",
+ }, {
+ /* sentinel */
+ }
+};
+
+static struct driver_d state_driver = {
+ .name = "state",
+ .probe = state_probe,
+ .of_compatible = DRV_OF_COMPAT(state_ids),
+};
+device_platform_driver(state_driver);