mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] state: add deep probe aware helpers to get state
@ 2022-02-02 11:19 Ahmad Fatoum
  2022-02-07  9:00 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2022-02-02 11:19 UTC (permalink / raw)
  To: barebox; +Cc: mtr, Ahmad Fatoum

state_by_name itself can't be made deep probe aware as it doesn't have
enough information on what to probe. Board code calling it must instead
itself ensure that the state has been proved (either via initcall
ordering or by calling e.g. of_ensure_probed_by_alias). For
state_by_node we can do it better: We can ensure probe of the supplied
device node. For most purposes, users just want to probe the default
state. This can now be done with state_by_alias("state").

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/state/state.c | 20 +++++++++++++++++++-
 include/state.h      | 12 +++++++++---
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/common/state/state.c b/common/state/state.c
index 469ee62d4012..8594c219eee8 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -704,10 +704,12 @@ struct state *state_by_name(const char *name)
  *
  * @node	The of node of the state instance
  */
-struct state *state_by_node(const struct device_node *node)
+struct state *state_by_node(struct device_node *node)
 {
 	struct state *state;
 
+	of_device_ensure_probed(node);
+
 	list_for_each_entry(state, &state_list, list) {
 		if (!strcmp(state->of_path, node->full_name))
 			return state;
@@ -716,6 +718,22 @@ struct state *state_by_node(const struct device_node *node)
 	return NULL;
 }
 
+/*
+ * state_by_alias - find a state instance by alias
+ *
+ * @name	The DT alias of the state instance
+ */
+struct state *state_by_alias(const char *alias)
+{
+	struct device_node *node;
+
+	node = of_find_node_by_alias(NULL, alias);
+	if (!node)
+		return NULL;
+
+	return state_by_node(node);
+}
+
 int state_read_mac(struct state *state, const char *name, u8 *buf)
 {
 	struct state_variable *svar;
diff --git a/include/state.h b/include/state.h
index be1b592576c1..bffcd5a9007f 100644
--- a/include/state.h
+++ b/include/state.h
@@ -12,7 +12,8 @@ struct state *state_new_from_node(struct device_node *node, bool readonly);
 void state_release(struct state *state);
 
 struct state *state_by_name(const char *name);
-struct state *state_by_node(const struct device_node *node);
+struct state *state_by_node(struct device_node *node);
+struct state *state_by_alias(const char *alias);
 
 int state_load_no_auth(struct state *state);
 int state_load(struct state *state);
@@ -34,10 +35,15 @@ static inline struct state *state_by_name(const char *name)
 	return NULL;
 }
 
-static inline struct state *state_by_node(const struct device_node *node)
+static inline struct state *state_by_node(struct device_node *node)
 {
 	return NULL;
-};
+}
+
+static inline struct state *state_by_alias(const char *alias)
+{
+	return NULL;
+}
 
 static inline int state_load(struct state *state)
 {
-- 
2.30.2


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


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

end of thread, other threads:[~2022-02-07  9:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-02 11:19 [PATCH] state: add deep probe aware helpers to get state Ahmad Fatoum
2022-02-07  9:00 ` Sascha Hauer

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