[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <52AAAA0B.7010307@nvidia.com>
Date: Fri, 13 Dec 2013 12:02:43 +0530
From: Laxman Dewangan <ldewangan@...dia.com>
To: Stephen Warren <swarren@...dotorg.org>
CC: "robh+dt@...nel.org" <robh+dt@...nel.org>,
"pawel.moll@....com" <pawel.moll@....com>,
"mark.rutland@....com" <mark.rutland@....com>,
"grant.likely@...aro.org" <grant.likely@...aro.org>,
"ijc+devicetree@...lion.org.uk" <ijc+devicetree@...lion.org.uk>,
"galak@...eaurora.org" <galak@...eaurora.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"devicetree@...r.kernel.org" <devicetree@...r.kernel.org>,
Stephen Warren <swarren@...dia.com>,
Kerwin Wan <kerwinw@...dia.com>,
"david@...son.dropbear.id.au" <david@...son.dropbear.id.au>
Subject: Re: [PATCH 1/2] of: add support for reading s32 property value
On Thursday 12 December 2013 11:31 PM, Stephen Warren wrote:
> On 12/12/2013 06:24 AM, Laxman Dewangan wrote:
>> 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.
>> diff --git a/include/linux/of.h b/include/linux/of.h
>> +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;
> I may not be thinking straight today since I have a cold, but doesn't
> patch 2/2 encode negative values as 2's complement, and an s32 variable
> in the kernel is also encoded as 2's complement, so all you need here is
> a cast:
>
> *out_value = (s32)val;
>
> ... since the cast doesn't change the binary representation?
This is correct if all architecture follows the 2's complement for -Ve
number representation.
If this is true then the patch will become more easy.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists