From patchwork Fri Jul 8 08:27:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 956282 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p688HQKW029253 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 8 Jul 2011 08:17:47 GMT Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Qf6FZ-0005OW-QH; Fri, 08 Jul 2011 08:17:25 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Qf6FY-0005OP-Nc for spi-devel-general@lists.sourceforge.net; Fri, 08 Jul 2011 08:17:24 +0000 X-ACL-Warn: Received: from mail-iw0-f175.google.com ([209.85.214.175]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1Qf6FX-0005jz-RQ for spi-devel-general@lists.sourceforge.net; Fri, 08 Jul 2011 08:17:24 +0000 Received: by mail-iw0-f175.google.com with SMTP id 4so2191562iwn.34 for ; Fri, 08 Jul 2011 01:17:23 -0700 (PDT) Received: by 10.42.213.137 with SMTP id gw9mr1800249icb.158.1310113043562; Fri, 08 Jul 2011 01:17:23 -0700 (PDT) Received: from localhost.localdomain ([114.218.200.65]) by mx.google.com with ESMTPS id s2sm10692207icw.17.2011.07.08.01.17.13 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 08 Jul 2011 01:17:23 -0700 (PDT) From: Shawn Guo To: spi-devel-general@lists.sourceforge.net Subject: [PATCH 4/6] dt: add helper function to read u32 arrays Date: Fri, 8 Jul 2011 16:27:32 +0800 Message-Id: <1310113654-25887-5-git-send-email-shawn.guo@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1310113654-25887-1-git-send-email-shawn.guo@linaro.org> References: <1310113654-25887-1-git-send-email-shawn.guo@linaro.org> X-Spam-Score: -0.0 (/) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 AWL AWL: From: address is in the auto white-list X-Headers-End: 1Qf6FX-0005jz-RQ Cc: patches@linaro.org, devicetree-discuss@lists.ozlabs.org, Rob Herring , Thomas Abraham , linux-arm-kernel@lists.infradead.org X-BeenThere: spi-devel-general@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux SPI core/device drivers discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: spi-devel-general-bounces@lists.sourceforge.net X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Fri, 08 Jul 2011 08:17:47 +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 --- 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 9f5293f..736cf5f 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -620,32 +620,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 69afeec..4761046 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -196,8 +196,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, const char **out_string); extern int of_device_is_compatible(const struct device_node *device,