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: 853965 X-Patchwork-Delegate: jh80.chung@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nifty.com header.i=@nifty.com header.b="MFvl5cwa"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3z7XzR23fQz9s72 for ; Sat, 30 Dec 2017 04:05:55 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id F1453C21C59; Fri, 29 Dec 2017 17:03:03 +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) {