From patchwork Tue Sep 9 22:23:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 37161 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f70.google.com (mail-yh0-f70.google.com [209.85.213.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EC92720566 for ; Tue, 9 Sep 2014 22:24:15 +0000 (UTC) Received: by mail-yh0-f70.google.com with SMTP id b6sf59133550yha.9 for ; Tue, 09 Sep 2014 15:24:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:date :message-id:subject:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=9NaJp5BBhO0sazH54LFXK+cmziz1UPUH/nRLX6ysd1Q=; b=i9eJzWr4AiL3RHq7NmAvIuHyYssarc2Ed9oq82o1nUzUIns4UmRoMsWS/AJdAIL9bc qgMT8xoB+OM6LuX5zv2bqS8fDWYxpGm0NmNqmsdbKTXKZb3+PGSFE2IGhBxhHMPBUA7p dh/pVW5LCOn3blm/5GfID/NeJQOsPTMysO8Crlq3Onvg3xjtpuOFRn1F3ZscxqxzOfUh 0f2UJSUt3Dh2ejyM/u6x7P7umm+8gW171wwgBQkQ6WoEmlID3tT+ME+mTBjrE5CpdzMT VODp0sg2Hs9VUpC/OFbRHS06ofdg+ktqTBo2/+542mvlsckB4d2aOE8VEBFK85G+HK21 uvJg== X-Gm-Message-State: ALoCoQnDDxlUfRaye1gVBpxTZ7Jqoqce3KLVLpK4RjVCDkvxi4HWAFewiu2hJ6f7SktKVOARcKgj X-Received: by 10.52.29.196 with SMTP id m4mr23506781vdh.4.1410301455764; Tue, 09 Sep 2014 15:24:15 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.38.113 with SMTP id s104ls814159qgs.13.gmail; Tue, 09 Sep 2014 15:24:15 -0700 (PDT) X-Received: by 10.53.0.164 with SMTP id az4mr6829972vdd.52.1410301455584; Tue, 09 Sep 2014 15:24:15 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id qh2si5700925vcb.81.2014.09.09.15.24.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Sep 2014 15:24:15 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id la4so1657567vcb.7 for ; Tue, 09 Sep 2014 15:24:15 -0700 (PDT) X-Received: by 10.220.182.1 with SMTP id ca1mr32665133vcb.21.1410301455414; Tue, 09 Sep 2014 15:24:15 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp350882vcb; Tue, 9 Sep 2014 15:24:14 -0700 (PDT) X-Received: by 10.68.134.104 with SMTP id pj8mr34062368pbb.124.1410301454455; Tue, 09 Sep 2014 15:24:14 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k2si25018591pdr.235.2014.09.09.15.24.13 for ; Tue, 09 Sep 2014 15:24:14 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752802AbaIIWYL (ORCPT + 27 others); Tue, 9 Sep 2014 18:24:11 -0400 Received: from mezzanine.sirena.org.uk ([106.187.55.193]:59860 "EHLO mezzanine.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752092AbaIIWYK (ORCPT ); Tue, 9 Sep 2014 18:24:10 -0400 Received: from host81-132-226-177.range81-132.btcentralplus.com ([81.132.226.177] helo=finisterre) by mezzanine.sirena.org.uk with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1XRTpX-0003c5-Fx; Tue, 09 Sep 2014 22:24:08 +0000 Received: from broonie by finisterre with local (Exim 4.84) (envelope-from ) id 1XRTpN-00009g-QQ; Tue, 09 Sep 2014 23:23:57 +0100 From: Mark Brown To: Liam Girdwood Cc: linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org, Mark Brown Date: Tue, 9 Sep 2014 23:23:54 +0100 Message-Id: <1410301435-554-1-git-send-email-broonie@kernel.org> X-Mailer: git-send-email 2.1.0 X-SA-Exim-Connect-IP: 81.132.226.177 X-SA-Exim-Mail-From: broonie@sirena.org.uk X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on mezzanine.sirena.org.uk X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.3.2 Subject: [PATCH 1/2] regulator: of: Provide simplified DT parsing method X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on mezzanine.sirena.org.uk) Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: broonie@kernel.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Mark Brown Currently regulator drivers which support DT all repeat very similar code to supply a list of known regulator identifiers to be matched with DT, convert that to platform data which is then matched up with the regulators as they are registered. This is both fiddly to get right and for devices which can use the standard helpers to provide their operations is the main source of code in the driver. Since this code is essentially identical for most drivers we can factor it out into the core, moving the identifiers in the match table into the regulator descriptors and also allowing drivers to pass in the name of the subnode to search. When a driver provides an of_match string for the regulator the core will attempt to use that to obtain init_data, allowing the driver to remove all explicit code for DT parsing and simply provide data instead. The current code leaks the phandles for the child nodes, this will be addressed incrementally and makes no practical difference for FDT anyway as the DT data structures are never freed. Signed-off-by: Mark Brown --- drivers/regulator/core.c | 10 +++++--- drivers/regulator/internal.h | 4 ++++ drivers/regulator/of_regulator.c | 51 ++++++++++++++++++++++++++++++++++++++++ include/linux/regulator/driver.h | 4 ++++ 4 files changed, 66 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index b31d706..cd87c0c 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -3602,12 +3602,17 @@ regulator_register(const struct regulator_desc *regulator_desc, return ERR_PTR(-EINVAL); } - init_data = config->init_data; - rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); if (rdev == NULL) return ERR_PTR(-ENOMEM); + init_data = regulator_of_get_init_data(dev, regulator_desc, + &rdev->dev.of_node); + if (!init_data) { + init_data = config->init_data; + rdev->dev.of_node = of_node_get(config->of_node); + } + mutex_lock(®ulator_list_mutex); mutex_init(&rdev->mutex); @@ -3634,7 +3639,6 @@ regulator_register(const struct regulator_desc *regulator_desc, /* register with sysfs */ rdev->dev.class = ®ulator_class; - rdev->dev.of_node = of_node_get(config->of_node); rdev->dev.parent = dev; dev_set_name(&rdev->dev, "regulator.%d", atomic_inc_return(®ulator_no) - 1); diff --git a/drivers/regulator/internal.h b/drivers/regulator/internal.h index 84bbda1..a6043ad 100644 --- a/drivers/regulator/internal.h +++ b/drivers/regulator/internal.h @@ -35,4 +35,8 @@ struct regulator { struct dentry *debugfs; }; +struct regulator_init_data *regulator_of_get_init_data(struct device *dev, + const struct regulator_desc *desc, + struct device_node **node); + #endif diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index ee5e67b..7a51814 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -14,8 +14,11 @@ #include #include #include +#include #include +#include "internal.h" + static void of_get_regulation_constraints(struct device_node *np, struct regulator_init_data **init_data) { @@ -189,3 +192,51 @@ int of_regulator_match(struct device *dev, struct device_node *node, return count; } EXPORT_SYMBOL_GPL(of_regulator_match); + +struct regulator_init_data *regulator_of_get_init_data(struct device *dev, + const struct regulator_desc *desc, + struct device_node **node) +{ + struct device_node *search, *child; + struct regulator_init_data *init_data = NULL; + const char *name; + + if (!dev->of_node || !desc->of_match) + return NULL; + + if (desc->regulators_node) + search = of_get_child_by_name(dev->of_node, + desc->regulators_node); + else + search = dev->of_node; + + if (!search) { + dev_err(dev, "Failed to find regulator container node\n"); + return NULL; + } + + for_each_child_of_node(search, child) { + name = of_get_property(child, "regulator-compatible", NULL); + if (!name) + name = child->name; + + if (strcmp(desc->of_match, name)) + continue; + + init_data = of_get_regulator_init_data(dev, child); + if (!init_data) { + dev_err(dev, + "failed to parse DT for regulator %s\n", + child->name); + break; + } + + of_node_get(child); + *node = child; + break; + } + + of_node_put(search); + + return init_data; +} diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 38b2f1a..fc0ee0c 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -203,6 +203,8 @@ enum regulator_type { * * @name: Identifying name for the regulator. * @supply_name: Identifying the regulator supply + * @of_match: Name used to identify regulator in DT. + * @regulators_node: Name of node containing regulator definitions in DT. * @id: Numerical identifier for the regulator. * @ops: Regulator operations table. * @irq: Interrupt number for the regulator. @@ -245,6 +247,8 @@ enum regulator_type { struct regulator_desc { const char *name; const char *supply_name; + const char *of_match; + const char *regulators_node; int id; bool continuous_voltage_range; unsigned n_voltages;