From patchwork Wed Nov 7 04:22:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 12705 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 A1E2B23E05 for ; Wed, 7 Nov 2012 04:22:08 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id B0097A19139 for ; Wed, 7 Nov 2012 04:22:07 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so1716242iej.11 for ; Tue, 06 Nov 2012 20:22:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :dkim-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding:x-gm-message-state; bh=wwUqDSmXgFh/tpvpZjMIM8ov7RiXtlONODR9/05ZZSk=; b=E+o3jofgErJYGUvsgn/qQ0EDTY3sLuIwgfuWhCh+BuInUhMZ3BgUDNl5pwos7eVFzZ XEpOFn0B4nCLiNfhFR2GjOt9YyuWOTYdW/a72XLwSXkVC2eyRvwd9seWWrjDIRb9Jdg+ Oxgf+u4v2TrWXHsstk1swWC2ZROayQu9p/u0p7sv17XXz7vmKepXsbH2grGqnPyWS1tw WEQE8IuNU9pRytNaxuliVs/tWo3bwZV/DtQptgou82Cruc9jI9T72S9nQAr3CWwMrPRq Nyg8Kld2JSJPd/gnhYExNL/8X2mGyQe/x20+ezazuWO62d6MTJ4C1SHuPGgOVwkFtmlM +uKw== Received: by 10.50.161.169 with SMTP id xt9mr15169367igb.62.1352262127105; Tue, 06 Nov 2012 20:22:07 -0800 (PST) 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.50.67.148 with SMTP id n20csp161899igt; Tue, 6 Nov 2012 20:22:06 -0800 (PST) Received: by 10.59.5.229 with SMTP id cp5mr3140160ved.32.1352262126101; Tue, 06 Nov 2012 20:22:06 -0800 (PST) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id fb1si17277108vdb.116.2012.11.06.20.22.05 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 06 Nov 2012 20:22:06 -0800 (PST) Received-SPF: pass (google.com: domain of viresh.linux@gmail.com designates 209.85.220.179 as permitted sender) client-ip=209.85.220.179; Authentication-Results: mx.google.com; spf=pass (google.com: domain of viresh.linux@gmail.com designates 209.85.220.179 as permitted sender) smtp.mail=viresh.linux@gmail.com; dkim=pass header.i=@gmail.com Received: by mail-vc0-f179.google.com with SMTP id f13so1113999vcb.38 for ; Tue, 06 Nov 2012 20:22:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=wwUqDSmXgFh/tpvpZjMIM8ov7RiXtlONODR9/05ZZSk=; b=fzRfa7ztXHnjwpYtAcfrJdVX5PEyRBcXUQfbtMQGQ43iB+BjeVeLe9zec57Yfy1hA6 SlxMzvDBnd+p/0X7x9LIMgXXWJWK6TUDUezdT7nygJ1uSsnk4MMWKX49RaET7ylqPp1N 8j2zGtV8MzHH0IVfAnDSc2/9fVofeZQ1AGtj1lfCz6dtBxpb2P/dn+c1Sal6gA3Tu9F9 VvaJl8IThYxM7qO6zhVjcM4qjxha4FQ1shyihUeC1wFWrlIufhEFkqgCkXjivYd+cY7I A/Ii6y3oEm0HT/wSB9mwMPlimzQx9m8Vx8trq0+t9BBrFgxdeUWW/CATiaFVaV1FNKUC xYwQ== MIME-Version: 1.0 Received: by 10.58.155.169 with SMTP id vx9mr3097235veb.45.1352262125637; Tue, 06 Nov 2012 20:22:05 -0800 (PST) Sender: viresh.linux@gmail.com Received: by 10.221.7.4 with HTTP; Tue, 6 Nov 2012 20:22:05 -0800 (PST) In-Reply-To: <50991C41.50705@gmail.com> References: <64c5278ebdec503f83e9b7002bf13affb7f3260f.1351225085.git.viresh.kumar@linaro.org> <50991C41.50705@gmail.com> Date: Wed, 7 Nov 2012 09:52:05 +0530 X-Google-Sender-Auth: aav8_QFrP-7XSqVZ080uyG2b-2M Message-ID: Subject: Re: [PATCH Resend V2] dt: add helper function to read u8 & u16 variables & arrays From: viresh kumar To: Rob Herring Cc: rob.herring@calxeda.com, grant.likely@secretlab.ca, linaro-dev@lists.linaro.org, andriy.shevchenko@intel.com, patches@linaro.org, devicetree-discuss@lists.ozlabs.org, spear-devel@list.st.com, linux-kernel@vger.kernel.org X-Gm-Message-State: ALoCoQlD9kPc6GFWfmGAJ2eJ+gpMhH+uDjaJgkbJWEE50Th2FxSOXT/cunZxkHwBs8KKqu3u+rtk On Tue, Nov 6, 2012 at 7:48 PM, Rob Herring wrote: >> +#define of_property_read_array(_np, _pname, _out, _sz) \ >> + while (_sz--) \ >> + *_out++ = (typeof(*_out))be32_to_cpup(_val++); \ > This will not work. You are incrementing _out by 1, 2, or 4 bytes, but > _val is always incremented by 4 bytes. > > According to the dtc commit adding this feature, the values are packed: > > With this patch the following property assignment: > > property = /bits/ 16 <0x1234 0x5678 0x0 0xffff>; > > is equivalent to: > > property = <0x12345678 0x0000ffff>; I thought of it a bit more and wasn't actually aligned with your explanation :( If that is the case, how will current implementation of u32 array will work if we pass something like: 0x88 0x84000000 0x5890 from DT? So, i did a dummy test of my current implementation, with following changes in one of my drivers: dts changes: cluster0: cluster@0 { + data1 = <0x50 0x60 0x70>; + data2 = <0x5000 0x6000 0x7000>; + data3 = <0x50000000 0x60000000 0x70000000>; } driver changes: +void test(struct device_node *cluster) +{ + u8 data1[3]; + u16 data2[3]; + u32 data3[3], i; + + of_property_read_u8_array(cluster, "data1", data1, 3); + of_property_read_u16_array(cluster, "data2", data2, 3); + of_property_read_u32_array(cluster, "data3", data3, 3); + + for (i = 0; i < 3; i++) { + printk(KERN_INFO "u8 %d: %x\n", i, data1[i]); + printk(KERN_INFO "u16 %d: %x\n", i, data2[i]); + printk(KERN_INFO "u32 %d: %x\n", i, data3[i]); + } +} And following is the output [    4.087205] u8 0: 50 [    4.093746] u16 0: 5000 [    4.101067] u32 0: 50000000 [    4.109512] u8 1: 60 [    4.116036] u16 1: 6000 [    4.123357] u32 1: 60000000 [    4.131718] u8 2: 70 [    4.138241] u16 2: 7000 [    4.145573] u32 2: 70000000 which looks to be what we were looking for, isn't it? Following is fixup for the doc comment missing: commit 00803aed0781de451048df0d15a3e8c814a343c8 Author: Viresh Kumar Date: Wed Nov 7 09:48:46 2012 +0530 fixup! dt: add helper function to read u8 & u16 variables & arrays --- drivers/of/base.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index fbb634b..4a6632e 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -669,6 +669,7 @@ EXPORT_SYMBOL(of_find_node_by_phandle); * @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. + * @sz: number of array elements to read * * Search for a property in a device node and read 8-bit value(s) from * it. Returns 0 on success, -EINVAL if the property does not exist, @@ -690,6 +691,7 @@ EXPORT_SYMBOL_GPL(of_property_read_u8_array); * @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. + * @sz: number of array elements to read * * Search for a property in a device node and read 16-bit value(s) from * it. Returns 0 on success, -EINVAL if the property does not exist, @@ -712,6 +714,7 @@ EXPORT_SYMBOL_GPL(of_property_read_u16_array); * @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. + * @sz: number of array elements to read * * 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,