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: 2588 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 5C0FF23F58 for ; Fri, 8 Jul 2011 08:17:25 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id 1FED1A184AE for ; Fri, 8 Jul 2011 08:17:25 +0000 (UTC) Received: by mail-qw0-f52.google.com with SMTP id 8so1183928qwb.11 for ; Fri, 08 Jul 2011 01:17:24 -0700 (PDT) Received: by 10.229.62.194 with SMTP id y2mr1378575qch.4.1310113044801; Fri, 08 Jul 2011 01:17:24 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.48.135 with SMTP id r7cs130508qcf; Fri, 8 Jul 2011 01:17:24 -0700 (PDT) Received: by 10.43.47.133 with SMTP id us5mr1544236icb.409.1310113044142; Fri, 08 Jul 2011 01:17:24 -0700 (PDT) Received: from mail-iw0-f178.google.com (mail-iw0-f178.google.com [209.85.214.178]) by mx.google.com with ESMTPS id ft7si13665195ibb.21.2011.07.08.01.17.23 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 08 Jul 2011 01:17:24 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.214.178 is neither permitted nor denied by best guess record for domain of shawn.guo@linaro.org) client-ip=209.85.214.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.214.178 is neither permitted nor denied by best guess record for domain of shawn.guo@linaro.org) smtp.mail=shawn.guo@linaro.org Received: by mail-iw0-f178.google.com with SMTP id 10so1874824iwc.37 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 Cc: devicetree-discuss@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, patches@linaro.org, Rob Herring , Thomas Abraham , Grant Likely 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> 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,