Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9838553ybi; Wed, 24 Jul 2019 10:50:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqymb44Nnrfighq1LgWLqSnGXGTrYUuTz8J7eDkp7MQOdczHpXX4gXc3Xld+djulnC54G2+l X-Received: by 2002:a62:5487:: with SMTP id i129mr12868581pfb.69.1563990618304; Wed, 24 Jul 2019 10:50:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563990618; cv=none; d=google.com; s=arc-20160816; b=Drviuo1Ng5+0Yqw6FjqNxu1j3GG+e6OvFYVmPq7hBXks/yWL2rldTnuc4CZ6D4da8p 0D5HPkQrM9BRwl+ZPuorTwCg7FNbWlNWECbKxqO6YO8XX3QAQtVMIKxL1OxZxCuozeph WUVffNo6ya7R1P7ItwvWlUZPMpKi/zAD1nTxy42hrd5FRO/cUUxbUKn0WnOP8zECXs1z WAlA3BW7snS8LSKker/caowBBjOX2hRLPU723bcGB+KAqLLBJS1G5sBe3FFOsu8BUTfR 2E3hJKTtova/vj4ya1eS5TNstqUwTye33sbD4Xq0Z9zKvDP2J2cISaOCLJHS8R7pSgHD 11UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/3Ah8FKXnjzRiOWf3wczuIH2HmTLx+HtvIJLBEWIgPQ=; b=HoU0/ejnxSuCq1SG6bGP5MGjUpTyoQhqsya3evHQxdt4U66El/NJo9WriAtSaOPJMa KaOA71b1nxNhHG9dMc3wyE6i/1Cag8y0SDVbe4QmhyGhRIXjvDmNMzKMtLK9Qo0wp+2F aPpRxNYEWoU8+Gc4JEc4W6Rvh7b9EBKCH62QYKHyDVTQOc5x6xBex2QxMU8hzc7Af4fa dWfAesslbFolhaOp8QpVsOsjYUaspSkpnYkjeetuTOSyNBBXYpuqaMc/hos4FIR2S5XF PslsAXNokNEJMYyLaFxcOAgg4jNAU2B/uA6h5tbCBQIDRLnuuRkpU3Jq91h123nSEcjS 0VTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@crapouillou.net header.s=mail header.b=nNv4CdDI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cp2si15742562plb.437.2019.07.24.10.50.03; Wed, 24 Jul 2019 10:50:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@crapouillou.net header.s=mail header.b=nNv4CdDI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728364AbfGXRRC (ORCPT + 99 others); Wed, 24 Jul 2019 13:17:02 -0400 Received: from outils.crapouillou.net ([89.234.176.41]:49362 "EHLO crapouillou.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728175AbfGXRRA (ORCPT ); Wed, 24 Jul 2019 13:17:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1563988615; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/3Ah8FKXnjzRiOWf3wczuIH2HmTLx+HtvIJLBEWIgPQ=; b=nNv4CdDIpER41aTP6dFPkZcunw7px4KoQ+XqesgDrN83plO/tOBEU6zdJHiRVylgxwigXO DKMC4zaNj15reDjvGl6eRcUrIXDFXxpfnX32u+QTcrUbAPqAThq78hh2s8VyrmTTQYWfeh xYasc+CnAWA2uZ4gc3UsH3xbIq6uZe4= From: Paul Cercueil To: Ralf Baechle , Paul Burton , James Hogan , Jonathan Corbet , Lee Jones , Arnd Bergmann , Daniel Lezcano , Thomas Gleixner , Michael Turquette , Stephen Boyd , Jason Cooper , Marc Zyngier , Rob Herring , Mark Rutland Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mips@vger.kernel.org, linux-clk@vger.kernel.org, od@zcrc.me, Mathieu Malaterre , Paul Cercueil Subject: [PATCH v15 04/13] mfd/syscon: Add device_node_to_regmap() Date: Wed, 24 Jul 2019 13:16:06 -0400 Message-Id: <20190724171615.20774-5-paul@crapouillou.net> In-Reply-To: <20190724171615.20774-1-paul@crapouillou.net> References: <20190724171615.20774-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org device_node_to_regmap() is exactly like syscon_node_to_regmap(), but it does not check that the node is compatible with "syscon", and won't attach the first clock it finds to the regmap. The rationale behind this, is that one device node with a standard compatible string "foo,bar" can be covered by multiple drivers sharing a regmap, or by a single driver doing all the job without a regmap, but these are implementation details which shouldn't reflect on the devicetree. Signed-off-by: Paul Cercueil --- Notes: v15: New patch drivers/mfd/syscon.c | 46 +++++++++++++++++++++++++------------- include/linux/mfd/syscon.h | 6 +++++ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c index b65e585fc8c6..660723276481 100644 --- a/drivers/mfd/syscon.c +++ b/drivers/mfd/syscon.c @@ -40,7 +40,7 @@ static const struct regmap_config syscon_regmap_config = { .reg_stride = 4, }; -static struct syscon *of_syscon_register(struct device_node *np) +static struct syscon *of_syscon_register(struct device_node *np, bool check_clk) { struct clk *clk; struct syscon *syscon; @@ -51,9 +51,6 @@ static struct syscon *of_syscon_register(struct device_node *np) struct regmap_config syscon_config = syscon_regmap_config; struct resource res; - if (!of_device_is_compatible(np, "syscon")) - return ERR_PTR(-EINVAL); - syscon = kzalloc(sizeof(*syscon), GFP_KERNEL); if (!syscon) return ERR_PTR(-ENOMEM); @@ -117,16 +114,18 @@ static struct syscon *of_syscon_register(struct device_node *np) goto err_regmap; } - clk = of_clk_get(np, 0); - if (IS_ERR(clk)) { - ret = PTR_ERR(clk); - /* clock is optional */ - if (ret != -ENOENT) - goto err_clk; - } else { - ret = regmap_mmio_attach_clk(regmap, clk); - if (ret) - goto err_attach; + if (check_clk) { + clk = of_clk_get(np, 0); + if (IS_ERR(clk)) { + ret = PTR_ERR(clk); + /* clock is optional */ + if (ret != -ENOENT) + goto err_clk; + } else { + ret = regmap_mmio_attach_clk(regmap, clk); + if (ret) + goto err_attach; + } } syscon->regmap = regmap; @@ -150,7 +149,8 @@ static struct syscon *of_syscon_register(struct device_node *np) return ERR_PTR(ret); } -struct regmap *syscon_node_to_regmap(struct device_node *np) +static struct regmap *device_node_get_regmap(struct device_node *np, + bool check_clk) { struct syscon *entry, *syscon = NULL; @@ -165,13 +165,27 @@ struct regmap *syscon_node_to_regmap(struct device_node *np) spin_unlock(&syscon_list_slock); if (!syscon) - syscon = of_syscon_register(np); + syscon = of_syscon_register(np, check_clk); if (IS_ERR(syscon)) return ERR_CAST(syscon); return syscon->regmap; } + +struct regmap *device_node_to_regmap(struct device_node *np) +{ + return device_node_get_regmap(np, false); +} +EXPORT_SYMBOL_GPL(device_node_to_regmap); + +struct regmap *syscon_node_to_regmap(struct device_node *np) +{ + if (!of_device_is_compatible(np, "syscon")) + return ERR_PTR(-EINVAL); + + return device_node_get_regmap(np, true); +} EXPORT_SYMBOL_GPL(syscon_node_to_regmap); struct regmap *syscon_regmap_lookup_by_compatible(const char *s) diff --git a/include/linux/mfd/syscon.h b/include/linux/mfd/syscon.h index 8cfda0554381..112dc66262cc 100644 --- a/include/linux/mfd/syscon.h +++ b/include/linux/mfd/syscon.h @@ -17,12 +17,18 @@ struct device_node; #ifdef CONFIG_MFD_SYSCON +extern struct regmap *device_node_to_regmap(struct device_node *np); extern struct regmap *syscon_node_to_regmap(struct device_node *np); extern struct regmap *syscon_regmap_lookup_by_compatible(const char *s); extern struct regmap *syscon_regmap_lookup_by_phandle( struct device_node *np, const char *property); #else +static inline struct regmap *device_node_to_regmap(struct device_node *np) +{ + return ERR_PTR(-ENOTSUPP); +} + static inline struct regmap *syscon_node_to_regmap(struct device_node *np) { return ERR_PTR(-ENOTSUPP); -- 2.21.0.593.g511ec345e18