summaryrefslogtreecommitdiffstats
path: root/lib/parameter.c
diff options
context:
space:
mode:
authorAhmad Fatoum <ahmad@a3f.at>2019-11-21 09:40:03 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2019-12-05 09:10:25 +0100
commit713a601bde07bb498f99bc6288d0c10ddcbe2e0a (patch)
treece744fd0bd48e2471a8367450d1d1995fc801c7a /lib/parameter.c
parent1d86578493aaddf04672731275e5e2df0f2dda94 (diff)
downloadbarebox-713a601bde07bb498f99bc6288d0c10ddcbe2e0a.tar.gz
barebox-713a601bde07bb498f99bc6288d0c10ddcbe2e0a.tar.xz
param: add dev_add_param_tristate(_ro) helpers
This is can be considered an extension to the dev_add_param_bool interfaces with a third value that's "unknown". This can be used for cases, where barebox can flip a bit somewhere, but it has no way of knowing what the initial state of the bit was, e.g. turn on/off the watchdog, but no watchdog status. Turn on/off a co-processor, but no co-processor online status. And so on. Not providing a way to customize the "unknown" string is a deliberate choice, so future device parameters follow the same naming scheme. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib/parameter.c')
-rw-r--r--lib/parameter.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/parameter.c b/lib/parameter.c
index fdbb2e71d1..22695634e5 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -588,6 +588,28 @@ struct param_d *dev_add_param_enum(struct device_d *dev, const char *name,
return &pe->param;
}
+static const char *const tristate_names[] = {
+ [PARAM_TRISTATE_UNKNOWN] = "unknown",
+ [PARAM_TRISTATE_TRUE] = "1",
+ [PARAM_TRISTATE_FALSE] = "0",
+};
+
+struct param_d *dev_add_param_tristate(struct device_d *dev, const char *name,
+ int (*set)(struct param_d *p, void *priv),
+ int (*get)(struct param_d *p, void *priv),
+ int *value, void *priv)
+{
+ return dev_add_param_enum(dev, name, set, get, value, tristate_names,
+ ARRAY_SIZE(tristate_names), priv);
+}
+
+struct param_d *dev_add_param_tristate_ro(struct device_d *dev, const char *name,
+ int *value)
+{
+ return dev_add_param_enum_ro(dev, name, value, tristate_names,
+ ARRAY_SIZE(tristate_names));
+}
+
struct param_bitmask {
struct param_d param;
unsigned long *value;