From patchwork Fri Dec 29 17:00:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 122944 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4916947qgn; Fri, 29 Dec 2017 09:04:58 -0800 (PST) X-Google-Smtp-Source: ACJfBouEBEFNYgHsGPOX2femdinc37IYhfvE1oIgz/9AZgbdAWe3LRovszIXaVUQUhWrIWLIx5hM X-Received: by 10.80.171.131 with SMTP id u3mr25193753edc.111.1514567097967; Fri, 29 Dec 2017 09:04:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514567097; cv=none; d=google.com; s=arc-20160816; b=L4pcoUuBawSQVz1wcb+ARe5G8bpeKYQVYIiYGcVXIol1Fw0Ob+Pc5ZLHW7LoCyZYyl QdL3U2I7/5Q2B+SCi6jgryopqMh/ygsEcADaIHsYwITAYAAosjUEgsmRon/i25gnLXJ8 4YVHO2Mx+rftYQCLhRYbDyvJFz5qeDO0I+2GR8aXnWJXt8QMHYpsjOvS26NsLTKsAOhc pQwhJx4cOSLykNwPiFWHur3XdLSnSetqb1sUuVaNhMljX05LDENQR5nFJ/qmNQ5ja/WY 5aUnxnUYQbt3YGRVWHvcT8XvTIU/tufk4+Hy2UglGwaSPe/szv6vqeiWe/LtO0fFujQW GpcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:dkim-filter:arc-authentication-results; bh=FDZBYUTASwbL24MRyUW2UB85WoiMzZfuz30rWA8wZoA=; b=wPIl8B3sWLjbPCXcJN4eAp8lWfvsjvtAumtUxTgzNdt7O8V0lhZ+VUdhr9utizYawX AjxYsZ+dvaQHYx18DIi08xX2bnCF+0EE+kBQCN7jWqlGnPmmIj52MStDWCfhmXjQ1wuS GsRgsCqf9pu9IzV0loq1pQoKVkfuSBpgnf553G4A6n+bi0dS2sYrOEmQdFmB7zVBGxec DNSrEI9n0N6NMne6FWN3m157dnj2ef9gJEOEPSugy4/+aR6CPfk9Fd5iwUw3KQeedse/ 5jKGyeAo/fLJQ4tVhg/ATa1DgHE2tT2NpoatVX20HSBdTKpcwiey0KdrTzRRaCyMgJDX vhYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=MFvl5cwa; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id 48si4291463edz.287.2017.12.29.09.04.57; Fri, 29 Dec 2017 09:04:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=MFvl5cwa; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 6168FC21DEF; Fri, 29 Dec 2017 17:03:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id AA5E4C21E0E; Fri, 29 Dec 2017 17:01:33 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 96D53C21DA9; Fri, 29 Dec 2017 17:00:54 +0000 (UTC) Received: from conuserg-08.nifty.com (conuserg-08.nifty.com [210.131.2.75]) by lists.denx.de (Postfix) with ESMTPS id 5481FC21E18 for ; Fri, 29 Dec 2017 17:00:49 +0000 (UTC) Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-08.nifty.com with ESMTP id vBTH0O9I000541; Sat, 30 Dec 2017 02:00:25 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com vBTH0O9I000541 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1514566825; bh=jOB2AIwdGOMa62l/m8m7pdXJyO1MaMQOxHNWCb88DwE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MFvl5cwaLVo6hJmqiNcvihmVLaBQRN/5WeqDfLU1tQ/56gI56cFrbB0HXFOYDDCrw IamPPj6IkDNGz/l6YUlQfGwJ1uz2lCFkX27BmuzZ1YOAigDdaD7wDT1043bXpKzV2q sKWL1/eldjnkEPjUF2hgPPLKsoeum5tlWQmd5UMCD1I21z0wlIhD2FIYA09y+FWqaC P/IWHfj1+V+knXOd6njDtG8hb7n5yGo2Wr00dAiQ/5DREO9xYQBxD7r38NkI7aCKpF QCwPW7b0ov7NsaPNLUVmZtZlFkv0nY8gkV+NFhP9bfGYp+NfC1sUp8vFORVmhYQ9OB 5M+f16XzKq0uA== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Sat, 30 Dec 2017 02:00:05 +0900 Message-Id: <1514566812-16781-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1514566812-16781-1-git-send-email-yamada.masahiro@socionext.com> References: <1514566812-16781-1-git-send-email-yamada.masahiro@socionext.com> Subject: [U-Boot] [PATCH 1/8] dm: add dev_read_u32() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" dev_read_u32_default() always returns something even when the property is missing. So, it is impossible to do nothing in the case. One solution is to use ofnode_read_u32() instead, but adding dev_read_u32() will be helpful. BTW, Linux has an equvalent function, device_property_read_u32(); it is clearer that it reads a property. I cannot understand the behavior of dev_read_u32() from its name. Signed-off-by: Masahiro Yamada --- BTW, I do not understand why we want *_default helpers. It is pretty easy to do equivalent without _default. priv->val = default; /* default in case property is missing */ dev_read_u32(dev, "foo-property", &priv->val); On the other hand, if we want to do nothing for missing property, we will end up with clumsy code. /* we do not want to overwrite priv->val if property is missing */ if (dev_read_bool(dev, "foo-property") { /* default value '0' will not be used anyway */ priv->val = dev_read_u32_default(dev, "foo-property", 0); } One more BTW, it was just painful to write equivalent code twice for CONFIG_DM_DEV_READ_INLINE. drivers/core/read.c | 5 +++++ include/dm/read.h | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/drivers/core/read.c b/drivers/core/read.c index 5d440ce..e027041 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -10,6 +10,11 @@ #include #include +int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp) +{ + return ofnode_read_u32(dev_ofnode(dev), propname, outp); +} + int dev_read_u32_default(struct udevice *dev, const char *propname, int def) { return ofnode_read_u32_default(dev_ofnode(dev), propname, def); diff --git a/include/dm/read.h b/include/dm/read.h index 8114037..5cacec8 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -46,6 +46,16 @@ static inline bool dev_of_valid(struct udevice *dev) #ifndef CONFIG_DM_DEV_READ_INLINE /** + * dev_read_u32() - read a 32-bit integer from a device's DT property + * + * @dev: device to read DT property from + * @propname: name of the property to read from + * @outp: place to put value (if found) + * @return 0 if OK, -ve on error + */ +int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp); + +/** * dev_read_u32_default() - read a 32-bit integer from a device's DT property * * @dev: device to read DT property from @@ -412,6 +422,12 @@ int dev_read_resource_byname(struct udevice *dev, const char *name, #else /* CONFIG_DM_DEV_READ_INLINE is enabled */ +static inline int dev_read_u32(struct udevice *dev, + const char *propname, u32 *outp) +{ + return ofnode_read_u32(dev_ofnode(dev), propname, outp); +} + static inline int dev_read_u32_default(struct udevice *dev, const char *propname, int def) {