devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gilad Avidov <gavidov@codeaurora.org>
To: robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com,
	ijc+devicetree@hellion.org.uk, galak@codeaurora.org,
	grant.likely@linaro.org
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	sdharia@codeaurora.org, linux-arm-msm@vger.kernel.org,
	Gilad Avidov <gavidov@codeaurora.org>
Subject: [PATCH 0/1] Compact interface for Device-Tree
Date: Thu, 30 Oct 2014 16:59:23 -0600	[thread overview]
Message-ID: <1414709964-27284-1-git-send-email-gavidov@codeaurora.org> (raw)


Device-Tree compact API
------------------------

Common code seen in driver’s probe reads device tree values and handling
erroneous return codes from all those of_property_read_xxx()  APIs. This
common code is factored out by the of_property_map module which allows
driver’s probe to replace that (often lengthy) code with a concise table:

struct of_prop_map map[] = {
    {"i2c",            &dev->id,        OF_REQ,  OF_ID,  -1},
    {"qcom,clk-freq-out",    &dev->clk_freq_out,    OF_REQ,  OF_U32,  0},
    {"qcom,clk-freq-in",    &dev->clk_freq_in,    OF_REQ,  OF_U32,  0},
    {"qcom,disable-dma",    &dev->disable_dma,    OF_OPT,  OF_BOOL, 0},
    {"qcom,master-id",    &dev->mstr_id,        OF_SGST, OF_U32,  0},
    {NULL,            NULL,            0,       0,       0},
};

Then call populate to read the values into the device’s variables:

ret = of_prop_populate(dev, dev->of_node, map);


An equivalent code snippet using the traditional of_property_read_XXXX()
API. Note that the equivalent is longer and more difficult to follow and
debug:

/* optional property */
dev->disable_dma = of_property_read_bool(node, "qcom,disable-dma");

ret = of_property_read_u32(dev->node, "qcom,clk-freq-out", &dev->clk_freq_out);
if (ret) {
    dev_err(dev, "error: missing 'qcom,clk-freq-out' DT property\n");
    if (!err)
        err = ret;
}

ret = of_property_read_u32(dev->node, "qcom,clk-freq-in", &dev->clk_freq_in);
if (ret) {
    dev_err(dev, "error: missing 'qcom,clk-freq-in' DT property\n");
    if (!err)
        err = ret;
}

/* suggested property */
ret = of_property_read_u32(dev->node, "qcom,master-id", &dev->mstr_id);
if (ret && !err)
    err = ret;


ret = of_alias_get_id(dev->node, "i2c");
if (ret < 0) {
    dev_err(dev, "error: missing '"i2c"' DT property\n");
    if (!err)
        err = ret;
} else {
    dev->id = ret;
}


The Device-Tree node and alias which are read by the above code snippets:

aliases {
    i2c0 = &i2c_0; /* I2C0 controller device */
};

i2c_0: i2c@78b6000 { /* BLSP1 QUP2 */
    compatible = "qcom,i2c-msm-v2";
    reg-names = "qup_phys_addr", "bam_phys_addr";
    reg = <0x78b6000 0x600>,
          <0x7884000 0x23000>;
    qcom,clk-freq-out = <100000>;
    qcom,clk-freq-in  = <19200000>;
    qcom,disable-dma;
    qcom,master-id = <86>;
}; 


Gilad Avidov (1):
  of_propery_map: compact interface for Device-Tree

 Documentation/devicetree/of_property_map.txt |   76 ++++++++++++++++++++++
 drivers/of/Makefile                          |    2 +-
 drivers/of/of_property_map.c                 |   88 ++++++++++++++++++++++++++
 include/linux/of_property_map.h              |   74 ++++++++++++++++++++++
 4 files changed, 239 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/of_property_map.txt
 create mode 100644 drivers/of/of_property_map.c
 create mode 100644 include/linux/of_property_map.h

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

             reply	other threads:[~2014-10-30 22:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-30 22:59 Gilad Avidov [this message]
2014-10-30 22:59 ` [PATCH 1/1] of_propery_map: compact interface for Device-Tree Gilad Avidov
2014-10-31 21:13 ` [PATCH 0/1] Compact " Rob Herring
2014-10-31 22:53   ` Rafael J. Wysocki
2014-11-03 15:06     ` Arnd Bergmann
2014-11-04  9:59       ` Sascha Hauer
2014-11-04 15:53       ` Grant Likely
2014-11-04 16:25         ` Arnd Bergmann

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=1414709964-27284-1-git-send-email-gavidov@codeaurora.org \
    --to=gavidov@codeaurora.org \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=grant.likely@linaro.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pawel.moll@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=sdharia@codeaurora.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).