mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] param: add dev_add_param_tristate(_ro) helpers
@ 2019-11-21  8:40 Ahmad Fatoum
  2019-11-21  8:40 ` [PATCH 2/3] watchdog: core: use new dev_add_param_tristate helper for .running param Ahmad Fatoum
  2019-11-21  8:40 ` [PATCH 3/3] remoteproc: add .stop device parameter for stopping remote processor Ahmad Fatoum
  0 siblings, 2 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2019-11-21  8:40 UTC (permalink / raw)
  To: barebox

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>
---
 include/param.h | 24 ++++++++++++++++++++++++
 lib/parameter.c | 22 ++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/include/param.h b/include/param.h
index 4ac502e726c0..d75f50ea3e60 100644
--- a/include/param.h
+++ b/include/param.h
@@ -63,6 +63,16 @@ struct param_d *dev_add_param_enum(struct device_d *dev, const char *name,
 		int (*get)(struct param_d *p, void *priv),
 		int *value, const char * const *names, int max, void *priv);
 
+enum param_tristate { PARAM_TRISTATE_UNKNOWN, PARAM_TRISTATE_TRUE, PARAM_TRISTATE_FALSE };
+
+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);
+
+struct param_d *dev_add_param_tristate_ro(struct device_d *dev, const char *name,
+		int *value);
+
 struct param_d *dev_add_param_bitmask(struct device_d *dev, const char *name,
 		int (*set)(struct param_d *p, void *priv),
 		int (*get)(struct param_d *p, void *priv),
@@ -144,6 +154,20 @@ static inline struct param_d *dev_add_param_bitmask(struct device_d *dev, const
 	return ERR_PTR(-ENOSYS);
 }
 
+static inline 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 ERR_PTR(-ENOSYS);
+}
+
+static inline struct param_d *dev_add_param_tristate_ro(struct device_d *dev, const char *name,
+		int *value)
+{
+	return ERR_PTR(-ENOSYS);
+}
+
 static inline struct param_d *dev_add_param_ip(struct device_d *dev, const char *name,
 		int (*set)(struct param_d *p, void *priv),
 		int (*get)(struct param_d *p, void *priv),
diff --git a/lib/parameter.c b/lib/parameter.c
index fdbb2e71d15d..22695634e5f1 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;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-12-05  8:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-21  8:40 [PATCH 1/3] param: add dev_add_param_tristate(_ro) helpers Ahmad Fatoum
2019-11-21  8:40 ` [PATCH 2/3] watchdog: core: use new dev_add_param_tristate helper for .running param Ahmad Fatoum
2019-11-21  8:40 ` [PATCH 3/3] remoteproc: add .stop device parameter for stopping remote processor Ahmad Fatoum
2019-11-25  8:28   ` Sascha Hauer
2019-11-25  9:45     ` Ahmad Fatoum
2019-12-04 13:07     ` Ahmad Fatoum
2019-12-05  8:10       ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox