devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Collins <collinsd@codeaurora.org>
To: devicetree-discuss@lists.ozlabs.org
Cc: linux-arm-msm@vger.kernel.org
Subject: How to represent negative values for device tree property
Date: Fri, 29 Mar 2013 13:13:29 -0700	[thread overview]
Message-ID: <5155F5E9.4080106@codeaurora.org> (raw)

Hi,

I am working on a thermal driver which needs to be able to read a
temperature threshold from a device tree property.  The hardware supports
thresholds in the range -204.8 to +204.7 C in 0.1 C steps.  I have found,
as I am sure others have as well, that dtc treats a '-' before an integer
in a dtsi file as a syntax error.  Therefore, I need some artificial way
to represent negative numbers in device tree.  Here are the possibilities
that I have thought of so far:

1. Use a second integer to specify the sign of the threshold:
     20000 mC --> <0 20000>
    -20000 mC --> <1 20000>
2. Use a string instead of an integer to specify the threshold and
   then convert it to an integer in the driver software:
     20000 mC --> "20000"
    -20000 mC --> "-20000"
3. Use units of millikelvin instead of millicelcius.  0 mC == 273150 mK
     20000 mC --> <293150>
    -20000 mC --> <253150>
4. Use an arbitrary offset e.g. 0 mC == 1000000
     20000 mC --> <1020000>
    -20000 mC --> <980000>
5. Use the unsigned 32-bit representation for 2’s-compliment
   signed 32-bit integer
     20000 mC --> <20000>
    -20000 mC --> <0xffffb1e0> or <4294947296>

Which of these options would you recommend using?  Is there any better way
to handle negative values that I haven’t listed?  What is the best general
case solution for specifying negative numbers in device tree?

Thanks,
David

-- 
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

             reply	other threads:[~2013-03-29 20:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-29 20:13 David Collins [this message]
  -- strict thread matches above, loose matches on Subject: below --
2013-04-01 21:08 How to represent negative values for device tree property David Collins
2013-04-01 22:00 ` Stephen Warren
2013-04-02  0:24   ` David Collins
2013-04-02  6:29     ` David Gibson
2013-04-02 15:36       ` Stephen Warren
2013-04-02  6:17 ` David Gibson

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=5155F5E9.4080106@codeaurora.org \
    --to=collinsd@codeaurora.org \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=linux-arm-msm@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).