From patchwork Wed Jul 6 20:42:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 951062 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p66KhTOc032529 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 6 Jul 2011 20:43:51 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QeYwH-0005Wt-67; Wed, 06 Jul 2011 20:43:17 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QeYwG-00089g-Qr; Wed, 06 Jul 2011 20:43:16 +0000 Received: from mail-iw0-f177.google.com ([209.85.214.177]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QeYwD-00089L-Gt for linux-arm-kernel@lists.infradead.org; Wed, 06 Jul 2011 20:43:14 +0000 Received: by iwn35 with SMTP id 35so305040iwn.36 for ; Wed, 06 Jul 2011 13:43:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; bh=cVJfyuePESsQF5rflrbkpzaXeHhhS8sXBnc/mei3BzI=; b=cdsAqhHdIuDSfyGJL2LilYpylZ3rg9Z1eMX13gJqtY9TPD/of894XkErcXSpm4K3GI 1gVx/I2Etdxx4gEDbRD4kAbSJeVC/fYD2G/4SyxGUXt42LVuIQVVILIYbMxxxR00ltPe feKJ+12jdu/nWCBBQFfcLBT7E+LXH4xElu2MU= Received: by 10.42.1.84 with SMTP id 20mr23677icf.160.1309984987002; Wed, 06 Jul 2011 13:43:07 -0700 (PDT) Received: from rob-laptop.i.smooth-stone.com ([173.226.190.126]) by mx.google.com with ESMTPS id x4sm4274148ibm.8.2011.07.06.13.43.05 (version=SSLv3 cipher=OTHER); Wed, 06 Jul 2011 13:43:06 -0700 (PDT) From: Rob Herring To: linux-arm-kernel@lists.infradead.org, devicetree-discuss@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] dt: add helper function to read u32 arrays Date: Wed, 6 Jul 2011 15:42:58 -0500 Message-Id: <1309984979-8847-1-git-send-email-robherring2@gmail.com> X-Mailer: git-send-email 1.7.4.1 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110706_164313_876812_906D0829 X-CRM114-Status: GOOD ( 15.81 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.214.177 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (robherring2[at]gmail.com) 0.1 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (robherring2[at]gmail.com) -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 T_TO_NO_BRKTS_FREEMAIL To: misformatted and free email service Cc: Grant Likely , Thomas Abraham , Rob Herring X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 06 Jul 2011 20:43:55 +0000 (UTC) From: Rob Herring Rework of_property_read_u32 to read an array of values. Then of_property_read_u32 becomes an inline with array size of 1. Also make struct device_node ptr const. Signed-off-by: Rob Herring Cc: Thomas Abraham Cc: Grant Likely --- Grant, Perhaps you want to roll this into the original patch? It would also be nice if there were empty versions of the helpers as well. Rob drivers/of/base.c | 19 +++++++++++++------ include/linux/of.h | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index b8b65fd..745537d 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -596,32 +596,39 @@ struct device_node *of_find_node_by_phandle(phandle handle) EXPORT_SYMBOL(of_find_node_by_phandle); /** - * of_property_read_u32 - Find and read a 32 bit integer from a property + * of_property_read_u32_array - Find and read an array of 32 bit integers + * from a property. + * * @np: device node from which the property value is to be read. * @propname: name of the property to be searched. * @out_value: pointer to return value, modified only if return value is 0. * - * Search for a property in a device node and read a 32-bit value from + * Search for a property in a device node and read 32-bit value(s) from * it. Returns 0 on success, -EINVAL if the property does not exist, * -ENODATA if property does not have a value, and -EOVERFLOW if the * property data isn't large enough. * * The out_value is modified only if a valid u32 value can be decoded. */ -int of_property_read_u32(struct device_node *np, char *propname, u32 *out_value) +int of_property_read_u32_array(const struct device_node *np, char *propname, + u32 *out_values, size_t sz) { struct property *prop = of_find_property(np, propname, NULL); + const __be32 *val; if (!prop) return -EINVAL; if (!prop->value) return -ENODATA; - if (sizeof(*out_value) > prop->length) + if ((sz * sizeof(*out_values)) > prop->length) return -EOVERFLOW; - *out_value = be32_to_cpup(prop->value); + + val = prop->value; + while (sz--) + *out_values++ = be32_to_cpup(val++); return 0; } -EXPORT_SYMBOL_GPL(of_property_read_u32); +EXPORT_SYMBOL_GPL(of_property_read_u32_array); /** * of_property_read_string - Find and read a string from a property diff --git a/include/linux/of.h b/include/linux/of.h index 4fc4c1b..41f10e2 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -195,8 +195,18 @@ extern struct device_node *of_find_node_with_property( extern struct property *of_find_property(const struct device_node *np, const char *name, int *lenp); -extern int of_property_read_u32(struct device_node *np, char *propname, - u32 *out_value); +extern int of_property_read_u32_array(const struct device_node *np, + char *propname, + u32 *out_values, + size_t sz); + +static inline int of_property_read_u32(const struct device_node *np, + char *propname, + u32 *out_value) +{ + return of_property_read_u32_array(np, propname, out_value, 1); +} + extern int of_property_read_string(struct device_node *np, char *propname, char **out_string); extern int of_device_is_compatible(const struct device_node *device,