Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4116257pxb; Tue, 10 Nov 2020 08:18:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHL1OQZmRS/fOASXFcTD3opUgBSDguHoQ5TFP7qridpRHjNrKwNMobXRL6ihEFIH4e3JLR X-Received: by 2002:a17:906:6b86:: with SMTP id l6mr20519294ejr.524.1605025112752; Tue, 10 Nov 2020 08:18:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605025112; cv=none; d=google.com; s=arc-20160816; b=YD+P7h66zOgvlbuGCtqFS9Hl65pvaOuYPCKHEreD04RzsfGj9DwgBDSr9w26J5RJ4Q lzl+stN+O1gN0HwZlmHsxlvT/BYFpOelSawo2x7vMGS2oDsqBrqiGNc9HbJhCiINgWOj 0bn1bbEel0c4v5MlqphTN7jQGltHGXiv9/+l7ZaJxWod+Hvrf6HzukhJxw6p5RQr5FtN 5yqQnRY4O/ccYZ0BCnmqdDr52cCDCUeKuh9nemMM46X4lLtSHPSkR7LvRLeK1N01R/IK u9Kbhc0OErvi7WJZ/8fJH7SxDJp15fvijDm+FXJ+wTUvE+G9uzQP/I3uFynA4p7sie4Z cOxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=iNUUjceyuN6t6Q0304SsgD3VGQhzv5DgyE+JRedpv8I=; b=hhX4sQYDDPYvFop+Dmu/lk3ADbqEeOTCqRlfYSdVMtm4ownn1dzXITKcNRslnJR+sN YyDgnU4FY5rLp7B+EaW1q7GtNpis0Uvxs2N8NDWKf/gpKQ8WvPD0nzeqRww83FEQP2Y9 aopdvhuQbeDni9KtYLpCPz8bjrZOxOuJOBQKj7oiuKWp5FsxjYOxNuMndTlaYQOoyLfy q/uICKFv5eacfnr4z4WJ7nAHhjojkM9VVwQqzR/Kp2LT6AvnP9N8VUpqBjHt0sMFY+VN M/T7/kVZU39ZF+1gzxEuaOYVuD5UqXGZId1BcPPZ6t+ViMkNPli5EeMW0FM5hL46ZfGK nupg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u13si8913925edd.278.2020.11.10.08.18.04; Tue, 10 Nov 2020 08:18:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726467AbgKJQNq (ORCPT + 99 others); Tue, 10 Nov 2020 11:13:46 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:56170 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726307AbgKJQNq (ORCPT ); Tue, 10 Nov 2020 11:13:46 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 0C8141F44CE8 From: Enric Balletbo i Serra To: linux-kernel@vger.kernel.org Cc: Collabora Kernel ML , Nicolas Boichat , Matthias Brugger , Arnd Bergmann , Lee Jones Subject: [PATCH v2] mfd: syscon: Add syscon_regmap_lookup_by_phandle_optional() function. Date: Tue, 10 Nov 2020 17:13:37 +0100 Message-Id: <20201110161338.18198-1-enric.balletbo@collabora.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds syscon_regmap_lookup_by_phandle_optional() function to get an optional regmap. It behaves the same as syscon_regmap_lookup_by_phandle() except where there is no regmap phandle. In this case, instead of returning -ENODEV, the function returns NULL. This makes error checking simpler when the regmap phandle is optional. Suggested-by: Nicolas Boichat Signed-off-by: Enric Balletbo i Serra Reviewed-by: Matthias Brugger --- Changes in v2: - Add Matthias r-b tag. - Add the explanation from the patch description to the code. - Return NULL instead of -ENOTSUPP when regmap helpers are not enabled. drivers/mfd/syscon.c | 18 ++++++++++++++++++ include/linux/mfd/syscon.h | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c index ca465794ea9c..c6f139b2e0c0 100644 --- a/drivers/mfd/syscon.c +++ b/drivers/mfd/syscon.c @@ -255,6 +255,24 @@ struct regmap *syscon_regmap_lookup_by_phandle_args(struct device_node *np, } EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_phandle_args); +/* + * It behaves the same as syscon_regmap_lookup_by_phandle() except where + * there is no regmap phandle. In this case, instead of returning -ENODEV, + * the function returns NULL. + */ +struct regmap *syscon_regmap_lookup_by_phandle_optional(struct device_node *np, + const char *property) +{ + struct regmap *regmap; + + regmap = syscon_regmap_lookup_by_phandle(np, property); + if (IS_ERR(regmap) && PTR_ERR(regmap) == -ENODEV) + return NULL; + + return regmap; +} +EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_phandle_optional); + static int syscon_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; diff --git a/include/linux/mfd/syscon.h b/include/linux/mfd/syscon.h index 7f20e9b502a5..fecc2fa2a364 100644 --- a/include/linux/mfd/syscon.h +++ b/include/linux/mfd/syscon.h @@ -28,6 +28,9 @@ extern struct regmap *syscon_regmap_lookup_by_phandle_args( const char *property, int arg_count, unsigned int *out_args); +extern struct regmap *syscon_regmap_lookup_by_phandle_optional( + struct device_node *np, + const char *property); #else static inline struct regmap *device_node_to_regmap(struct device_node *np) { @@ -59,6 +62,14 @@ static inline struct regmap *syscon_regmap_lookup_by_phandle_args( { return ERR_PTR(-ENOTSUPP); } + +static inline struct regmap *syscon_regmap_lookup_by_phandle_optional( + struct device_node *np, + const char *property) +{ + return NULL; +} + #endif #endif /* __LINUX_MFD_SYSCON_H__ */ -- 2.28.0