mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Daniel Schultz <d.schultz@phytec.de>
To: barebox@lists.infradead.org
Subject: [PATCH v3 4/7] common: state: Add variable_type to state_variable
Date: Fri, 3 Nov 2017 11:48:26 +0100	[thread overview]
Message-ID: <1509706109-41478-4-git-send-email-d.schultz@phytec.de> (raw)
In-Reply-To: <1509706109-41478-1-git-send-email-d.schultz@phytec.de>

Add a pointer in state_variable to the corresponding variable_type array
element.

Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
---
Changes:
	v2: New patch
	v3: struct variable_type is passed as parameter in the create callbacks.

 common/state/state.c           |  2 +-
 common/state/state.h           |  8 +++++---
 common/state/state_variables.c | 20 +++++++++++++++-----
 3 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/common/state/state.c b/common/state/state.c
index 266d211..98a7db3 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -246,7 +246,7 @@ static int state_convert_node_variable(struct state *state,
 	}
 
 	if (conv == STATE_CONVERT_FROM_NODE_CREATE) {
-		sv = vtype->create(state, name, node);
+		sv = vtype->create(state, name, node, vtype);
 		if (IS_ERR(sv)) {
 			ret = PTR_ERR(sv);
 			dev_err(&state->dev, "failed to create %s: %s\n", name,
diff --git a/common/state/state.h b/common/state/state.h
index 81aaec2..7dd163c 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -123,15 +123,17 @@ struct variable_type {
 	int (*export) (struct state_variable *, struct device_node *,
 		       enum state_convert);
 	int (*import) (struct state_variable *, struct device_node *);
-	struct state_variable *(*create) (struct state * state,
-					  const char *name,
-					  struct device_node *);
+	struct state_variable *(*create) (struct state *,
+					  const char *,
+					  struct device_node *,
+					  const struct variable_type *);
 };
 
 /* instance of a single variable */
 struct state_variable {
 	struct state *state;
 	struct list_head list;
+	const struct variable_type *type;
 	const char *name;
 	unsigned int start;
 	unsigned int size;
diff --git a/common/state/state_variables.c b/common/state/state_variables.c
index 56bcd95..688467d 100644
--- a/common/state/state_variables.c
+++ b/common/state/state_variables.c
@@ -101,7 +101,8 @@ static int state_uint8_set(struct param_d *p, void *priv)
 
 static struct state_variable *state_uint8_create(struct state *state,
 						 const char *name,
-						 struct device_node *node)
+						 struct device_node *node,
+					      const struct variable_type *vtype)
 {
 	struct state_uint32 *su32;
 	struct param_d *param;
@@ -116,6 +117,7 @@ static struct state_variable *state_uint8_create(struct state *state,
 	}
 
 	su32->param = param;
+	su32->var.type = vtype;
 	su32->var.size = sizeof(uint8_t);
 #ifdef __LITTLE_ENDIAN
 	su32->var.raw = &su32->value;
@@ -129,7 +131,8 @@ static struct state_variable *state_uint8_create(struct state *state,
 
 static struct state_variable *state_uint32_create(struct state *state,
 						  const char *name,
-						  struct device_node *node)
+						  struct device_node *node,
+					      const struct variable_type *vtype)
 {
 	struct state_uint32 *su32;
 	struct param_d *param;
@@ -144,6 +147,7 @@ static struct state_variable *state_uint32_create(struct state *state,
 	}
 
 	su32->param = param;
+	su32->var.type = vtype;
 	su32->var.size = sizeof(uint32_t);
 	su32->var.raw = &su32->value;
 	su32->var.state = state;
@@ -218,7 +222,8 @@ static int state_enum32_import(struct state_variable *sv,
 
 static struct state_variable *state_enum32_create(struct state *state,
 						  const char *name,
-						  struct device_node *node)
+						  struct device_node *node,
+					      const struct variable_type *vtype)
 {
 	struct state_enum32 *enum32;
 	int ret, i, num_names;
@@ -234,6 +239,7 @@ static struct state_variable *state_enum32_create(struct state *state,
 
 	enum32->names = xzalloc(sizeof(char *) * num_names);
 	enum32->num_names = num_names;
+	enum32->var.type = vtype;
 	enum32->var.size = sizeof(uint32_t);
 	enum32->var.raw = &enum32->value;
 	enum32->var.state = state;
@@ -300,13 +306,15 @@ static int state_mac_import(struct state_variable *sv, struct device_node *node)
 
 static struct state_variable *state_mac_create(struct state *state,
 					       const char *name,
-					       struct device_node *node)
+					       struct device_node *node,
+					      const struct variable_type *vtype)
 {
 	struct state_mac *mac;
 	int ret;
 
 	mac = xzalloc(sizeof(*mac));
 
+	mac->var.type = vtype;
 	mac->var.size = ARRAY_SIZE(mac->value);
 	mac->var.raw = mac->value;
 	mac->var.state = state;
@@ -402,7 +410,8 @@ static int state_string_get(struct param_d *p, void *priv)
 
 static struct state_variable *state_string_create(struct state *state,
 						  const char *name,
-						  struct device_node *node)
+						  struct device_node *node,
+					      const struct variable_type *vtype)
 {
 	struct state_string *string;
 	uint32_t start_size[2];
@@ -420,6 +429,7 @@ static struct state_variable *state_string_create(struct state *state,
 		return ERR_PTR(-EILSEQ);
 
 	string = xzalloc(sizeof(*string) + start_size[1]);
+	string->var.type = vtype;
 	string->var.size = start_size[1];
 	string->var.raw = &string->raw;
 	string->var.state = state;
-- 
2.7.4


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

  parent reply	other threads:[~2017-11-03 10:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-03 10:48 [PATCH v3 1/7] ARM: boards: phytec-som-am335x: Add unified MLO Daniel Schultz
2017-11-03 10:48 ` [PATCH v3 2/7] ARM: dts: AM335x: Add state framework Daniel Schultz
2017-11-03 10:48 ` [PATCH v3 3/7] ARM: configs: am335x_defconfig: Add state config Daniel Schultz
2017-11-03 10:48 ` Daniel Schultz [this message]
2017-11-03 10:48 ` [PATCH v3 5/7] common: state: Add variable type as enum Daniel Schultz
2017-11-03 10:48 ` [PATCH v3 6/7] common: state: Add function to read state MAC Daniel Schultz
2017-11-03 10:48 ` [PATCH v3 7/7] ARM: phytec-som-am335x: Set MAC addresses from state Daniel Schultz
2017-11-07  6:47 ` [PATCH v3 1/7] ARM: boards: phytec-som-am335x: Add unified MLO Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1509706109-41478-4-git-send-email-d.schultz@phytec.de \
    --to=d.schultz@phytec.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox