mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] state: implement signed int support
Date: Mon, 14 Dec 2015 12:47:48 +0100	[thread overview]
Message-ID: <1450093668-17961-1-git-send-email-s.hauer@pengutronix.de> (raw)

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 .../devicetree/bindings/barebox/barebox,state.rst  |  5 +++--
 common/state.c                                     | 25 +++++++++++++++++++---
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/Documentation/devicetree/bindings/barebox/barebox,state.rst b/Documentation/devicetree/bindings/barebox/barebox,state.rst
index ef66029..d1b0627 100644
--- a/Documentation/devicetree/bindings/barebox/barebox,state.rst
+++ b/Documentation/devicetree/bindings/barebox/barebox,state.rst
@@ -55,8 +55,8 @@ Required properties:
   ``#size-cells = <1>``. Defines the ``offset`` and ``size`` of the
   variable in the ``raw`` backend. ``size`` must fit the node
   ``type``. Variables are not allowed to overlap.
-* ``type``: Should be ``uint8``, ``uint32``, ``enum32``, ``mac`` or
-  ``string`` for the type of the variable
+* ``type``: Should be ``uint8``, ``uint32``, ``int32``. ``enum32``, ``mac``
+  or ``string`` for the type of the variable
 * ``names``: For ``enum32`` values only, this specifies the values
   possible for ``enum32``.
 
@@ -93,6 +93,7 @@ Variable Types
 
 * ``uint8``:
 * ``uint32``:
+* ``int32``:
 * ``enum32``: The ``default`` value is an integer representing an
   offset into the names array.
 * ``mac``:
diff --git a/common/state.c b/common/state.c
index ec72dbd..d1fa47f 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,
 	},
 };
 
-- 
2.6.2


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

                 reply	other threads:[~2015-12-14 11:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1450093668-17961-1-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.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