summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2015-12-09 08:25:58 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2016-01-08 08:30:55 +0100
commit3cff8948ff5d2d4dc834bdc955684b73571713bd (patch)
treea9e3c19705fcc423fd8ead5587a7faa690749af3 /common
parent9d15b9298807283813e0495ccf04c1175d12719f (diff)
downloadbarebox-3cff8948ff5d2d4dc834bdc955684b73571713bd.tar.gz
barebox-3cff8948ff5d2d4dc834bdc955684b73571713bd.tar.xz
state: implement signed int support
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/state.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/common/state.c b/common/state.c
index ec72dbd9a0..d1fa47ffa3 100644
--- a/common/state.c
+++ b/common/state.c
@@ -66,6 +66,7 @@ enum state_variable_type {
STATE_TYPE_ENUM,
STATE_TYPE_U8,
STATE_TYPE_U32,
+ STATE_TYPE_S32,
STATE_TYPE_MAC,
STATE_TYPE_STRING,
};
@@ -209,8 +210,8 @@ static struct state_variable *state_uint8_create(struct state *state,
return &su32->var;
}
-static struct state_variable *state_uint32_create(struct state *state,
- const char *name, struct device_node *node)
+static struct state_variable *state_int32_create(struct state *state,
+ const char *name, struct device_node *node, const char *format)
{
struct state_uint32 *su32;
struct param_d *param;
@@ -218,7 +219,7 @@ static struct state_variable *state_uint32_create(struct state *state,
su32 = xzalloc(sizeof(*su32));
param = dev_add_param_int(&state->dev, name, state_set_dirty,
- NULL, &su32->value, "%u", state);
+ NULL, &su32->value, format, state);
if (IS_ERR(param)) {
free(su32);
return ERR_CAST(param);
@@ -231,6 +232,18 @@ static struct state_variable *state_uint32_create(struct state *state,
return &su32->var;
}
+static struct state_variable *state_uint32_create(struct state *state,
+ const char *name, struct device_node *node)
+{
+ return state_int32_create(state, name, node, "%u");
+}
+
+static struct state_variable *state_sint32_create(struct state *state,
+ const char *name, struct device_node *node)
+{
+ return state_int32_create(state, name, node, "%d");
+}
+
/*
* enum32
*/
@@ -605,6 +618,12 @@ static struct variable_type types[] = {
.export = state_string_export,
.import = state_string_import,
.create = state_string_create,
+ }, {
+ .type = STATE_TYPE_S32,
+ .type_name = "int32",
+ .export = state_uint32_export,
+ .import = state_uint32_import,
+ .create = state_sint32_create,
},
};