From patchwork Wed Aug 24 06:40:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 74544 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp155864qga; Tue, 23 Aug 2016 23:40:01 -0700 (PDT) X-Received: by 10.66.78.35 with SMTP id y3mr2671596paw.40.1472020801274; Tue, 23 Aug 2016 23:40:01 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e74si8087385pfk.131.2016.08.23.23.40.01; Tue, 23 Aug 2016 23:40:01 -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=pass header.i=@nifty.com; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753660AbcHXGjg (ORCPT + 27 others); Wed, 24 Aug 2016 02:39:36 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21515 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753356AbcHXGjb (ORCPT ); Wed, 24 Aug 2016 02:39:31 -0400 Received: from beagle.diag.org (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id u7O6cPJt012260; Wed, 24 Aug 2016 15:38:26 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com u7O6cPJt012260 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1472020707; bh=k9pMHEhQr6DnzqPp33eEofMNDyg0qXgKn0bVkHKk/3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=boVJUZZzmNH5sLQd6ZmBhpSfit9YhwirgLKgP7pcPKS/8VUFVd2XVXElYgEPcNEjz EkqCiCaYCxesFT11mJfBRrPIyWioZgh4OXMfjTKUDhb6oSVf771T/OQuPEDTleQVBh ImgjIQVyk0WJF83g2u9LYRFfa8hPjwq6XXoC7abPRc5DySDMyzifQbO02LXqsJ6FKw kZo9AtThjumco60BE/bKQezWFbeUsWlCIPojbCF5s/HjXty6wgSxWcpFEDKkgBU/H1 50+Rgmw3kjIEIl1lvzdUhNSYpawpGXLlmnXEC3cw0m5Hc2wTVCB8rN7qjrpEVAb5CB 47sNEaUYw/taw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kernel@vger.kernel.org, Philipp Zabel Cc: Masahiro Yamada , linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/2] reset: uniphier: use of_device_get_match_data() to get matched data Date: Wed, 24 Aug 2016 15:40:30 +0900 Message-Id: <1472020830-16059-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1472020830-16059-1-git-send-email-yamada.masahiro@socionext.com> References: <1472020830-16059-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use of_device_get_match_data() instead of of_match_node(). With this, we can retrieve the .data field of the OF match table more easily. No more need to define (or declare) the match table before the probe callback. I prefer to collect boilerplates at the bottom of the file, so moved it below. Signed-off-by: Masahiro Yamada --- drivers/reset/reset-uniphier.c | 81 +++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 41 deletions(-) -- 1.9.1 diff --git a/drivers/reset/reset-uniphier.c b/drivers/reset/reset-uniphier.c index 41c62af..9b3f2cd 100644 --- a/drivers/reset/reset-uniphier.c +++ b/drivers/reset/reset-uniphier.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -285,6 +286,45 @@ static const struct reset_control_ops uniphier_reset_ops = { .status = uniphier_reset_status, }; +static int uniphier_reset_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct uniphier_reset_priv *priv; + const struct uniphier_reset_data *p, *data; + struct regmap *regmap; + struct device_node *parent; + unsigned int nr_resets = 0; + + data = of_device_get_match_data(dev); + WARN_ON(!data); + + parent = of_get_parent(dev->of_node); /* parent should be syscon node */ + regmap = syscon_node_to_regmap(parent); + of_node_put(parent); + if (IS_ERR(regmap)) { + dev_err(dev, "failed to get regmap (error %ld)\n", + PTR_ERR(regmap)); + return PTR_ERR(regmap); + } + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + for (p = data; p->id != UNIPHIER_RESET_ID_END; p++) + nr_resets = max(nr_resets, p->id + 1); + + priv->rcdev.ops = &uniphier_reset_ops; + priv->rcdev.owner = dev->driver->owner; + priv->rcdev.of_node = dev->of_node; + priv->rcdev.nr_resets = nr_resets; + priv->dev = dev; + priv->regmap = regmap; + priv->data = data; + + return devm_reset_controller_register(&pdev->dev, &priv->rcdev); +} + static const struct of_device_id uniphier_reset_match[] = { /* System reset */ { @@ -385,47 +425,6 @@ static const struct of_device_id uniphier_reset_match[] = { }; MODULE_DEVICE_TABLE(of, uniphier_reset_match); -static int uniphier_reset_probe(struct platform_device *pdev) -{ - struct device *dev = &pdev->dev; - const struct of_device_id *match; - struct uniphier_reset_priv *priv; - const struct uniphier_reset_data *p; - struct regmap *regmap; - struct device_node *parent; - unsigned int nr_resets = 0; - - match = of_match_node(uniphier_reset_match, pdev->dev.of_node); - if (!match) - return -ENODEV; - - parent = of_get_parent(dev->of_node); /* parent should be syscon node */ - regmap = syscon_node_to_regmap(parent); - of_node_put(parent); - if (IS_ERR(regmap)) { - dev_err(dev, "failed to get regmap (error %ld)\n", - PTR_ERR(regmap)); - return PTR_ERR(regmap); - } - - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; - - for (p = match->data; p->id != UNIPHIER_RESET_ID_END; p++) - nr_resets = max(nr_resets, p->id + 1); - - priv->rcdev.ops = &uniphier_reset_ops; - priv->rcdev.owner = dev->driver->owner; - priv->rcdev.of_node = dev->of_node; - priv->rcdev.nr_resets = nr_resets; - priv->dev = dev; - priv->regmap = regmap; - priv->data = match->data; - - return devm_reset_controller_register(&pdev->dev, &priv->rcdev); -} - static struct platform_driver uniphier_reset_driver = { .probe = uniphier_reset_probe, .driver = {