All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laxman Dewangan <ldewangan@nvidia.com>
To: <robh+dt@kernel.org>, <pawel.moll@arm.com>,
	<mark.rutland@arm.com>, <grant.likely@linaro.org>
Cc: <ijc+devicetree@hellion.org.uk>, <galak@codeaurora.org>,
	<linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<swarren@nvidia.com>, <kerwinw@nvidia.com>,
	Laxman Dewangan <ldewangan@nvidia.com>,
	<david@gibson.dropbear.id.au>
Subject: [PATCH 1/2] of: add support for reading s32 property value
Date: Thu, 12 Dec 2013 18:54:52 +0530	[thread overview]
Message-ID: <1386854693-10871-1-git-send-email-ldewangan@nvidia.com> (raw)

Add of_property_read_s32() to read the signed 32bit number
from dt property value. This supports to pass the -ve numbers
from dt. Use 2's complement method for represnting negative number
and passed as u32 from dts. When reading back the value, again
converted to 2's complement if msb shows as 1.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
CC: david@gibson.dropbear.id.au
CC: swarren@nvidia.com
---
We required to pass the -ve value from DT and after looking the discussion
http://www.mail-archive.com/linux-arm-msm@vger.kernel.org/msg05108.html
I created this patch.
I CCed to David and Stephen on this.


 include/linux/of.h |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/include/linux/of.h b/include/linux/of.h
index 276c546..17c0327 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -601,6 +601,22 @@ static inline int of_property_read_u32(const struct device_node *np,
 	return of_property_read_u32_array(np, propname, out_value, 1);
 }
 
+static inline int of_property_read_s32(const struct device_node *np,
+				       const char *propname,
+				       s32 *out_value)
+{
+	u32 val;
+	int ret;
+
+	ret = of_property_read_u32(np, propname, &val);
+	if (ret < 0)
+		return ret;
+
+	/* 2's complement if MSB is 1 */
+	*out_value = (val & 0x80000000U) ? -((val ^ 0xFFFFFFFFU) + 1) : val;
+	return ret;
+}
+
 #define of_property_for_each_u32(np, propname, prop, p, u)	\
 	for (prop = of_find_property(np, propname, NULL),	\
 		p = of_prop_next_u32(prop, NULL, &u);		\
-- 
1.7.0.4


WARNING: multiple messages have this Message-ID (diff)
From: Laxman Dewangan <ldewangan@nvidia.com>
To: robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com,
	grant.likely@linaro.org
Cc: ijc+devicetree@hellion.org.uk, galak@codeaurora.org,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	swarren@nvidia.com, kerwinw@nvidia.com,
	Laxman Dewangan <ldewangan@nvidia.com>,
	david@gibson.dropbear.id.au
Subject: [PATCH 1/2] of: add support for reading s32 property value
Date: Thu, 12 Dec 2013 18:54:52 +0530	[thread overview]
Message-ID: <1386854693-10871-1-git-send-email-ldewangan@nvidia.com> (raw)

Add of_property_read_s32() to read the signed 32bit number
from dt property value. This supports to pass the -ve numbers
from dt. Use 2's complement method for represnting negative number
and passed as u32 from dts. When reading back the value, again
converted to 2's complement if msb shows as 1.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
CC: david@gibson.dropbear.id.au
CC: swarren@nvidia.com
---
We required to pass the -ve value from DT and after looking the discussion
http://www.mail-archive.com/linux-arm-msm@vger.kernel.org/msg05108.html
I created this patch.
I CCed to David and Stephen on this.


 include/linux/of.h |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/include/linux/of.h b/include/linux/of.h
index 276c546..17c0327 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -601,6 +601,22 @@ static inline int of_property_read_u32(const struct device_node *np,
 	return of_property_read_u32_array(np, propname, out_value, 1);
 }
 
+static inline int of_property_read_s32(const struct device_node *np,
+				       const char *propname,
+				       s32 *out_value)
+{
+	u32 val;
+	int ret;
+
+	ret = of_property_read_u32(np, propname, &val);
+	if (ret < 0)
+		return ret;
+
+	/* 2's complement if MSB is 1 */
+	*out_value = (val & 0x80000000U) ? -((val ^ 0xFFFFFFFFU) + 1) : val;
+	return ret;
+}
+
 #define of_property_for_each_u32(np, propname, prop, p, u)	\
 	for (prop = of_find_property(np, propname, NULL),	\
 		p = of_prop_next_u32(prop, NULL, &u);		\
-- 
1.7.0.4

             reply	other threads:[~2013-12-12 13:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-12 13:24 Laxman Dewangan [this message]
2013-12-12 13:24 ` [PATCH 1/2] of: add support for reading s32 property value Laxman Dewangan
2013-12-12 13:24 ` [PATCH 2/2] dt-binding: add header to define types and conversion Laxman Dewangan
2013-12-12 13:24   ` Laxman Dewangan
2013-12-12 18:01 ` [PATCH 1/2] of: add support for reading s32 property value Stephen Warren
2013-12-13  6:32   ` Laxman Dewangan
2013-12-13  6:32     ` Laxman Dewangan

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=1386854693-10871-1-git-send-email-ldewangan@nvidia.com \
    --to=ldewangan@nvidia.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=grant.likely@linaro.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=kerwinw@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pawel.moll@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=swarren@nvidia.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.