From patchwork Tue Jun 17 07:38:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris BREZILLON X-Patchwork-Id: 4364601 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2AC7D9F26E for ; Tue, 17 Jun 2014 07:42:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 45D3E201BC for ; Tue, 17 Jun 2014 07:42:43 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 743112018E for ; Tue, 17 Jun 2014 07:42:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wwo0X-0006TV-Qi; Tue, 17 Jun 2014 07:40:41 +0000 Received: from top.free-electrons.com ([176.31.233.9] helo=mail.free-electrons.com) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WwnzV-0004kl-Ka for linux-arm-kernel@lists.infradead.org; Tue, 17 Jun 2014 07:39:38 +0000 Received: by mail.free-electrons.com (Postfix, from userid 106) id C8EAC1240; Tue, 17 Jun 2014 09:39:06 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from localhost.localdomain (col31-4-88-188-83-94.fbx.proxad.net [88.188.83.94]) by mail.free-electrons.com (Postfix) with ESMTPSA id 15B07FD1; Tue, 17 Jun 2014 09:38:50 +0200 (CEST) From: Boris BREZILLON To: Samuel Ortiz , Lee Jones , Liam Girdwood , Mark Brown Subject: [PATCH v4 6/7] regulator: axp20x: make use of devm_regulator_set_register Date: Tue, 17 Jun 2014 09:38:42 +0200 Message-Id: <1402990723-28138-7-git-send-email-boris.brezillon@free-electrons.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1402990723-28138-1-git-send-email-boris.brezillon@free-electrons.com> References: <1402990723-28138-1-git-send-email-boris.brezillon@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140617_003938_009497_6852A04D X-CRM114-Status: GOOD ( 16.15 ) X-Spam-Score: -0.0 (/) Cc: devicetree@vger.kernel.org, linux-doc@vger.kernel.org, dev@linux-sunxi.org, Boris BREZILLON , linux-kernel@vger.kernel.org, Shuge , Carlo Caione , Maxime Ripard , kevin@allwinnertech.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Make use of the devm_regulator_set_register instead of registering each regulator provided by the PMIC. This also solves a self dependency issue where one regulator of the PMIC is used as a supply for anoher regulator provided by the same PMIC. Signed-off-by: Boris BREZILLON --- drivers/regulator/axp20x-regulator.c | 59 ++++++++++++++---------------------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c index d42bf6d..e8f0df7 100644 --- a/drivers/regulator/axp20x-regulator.c +++ b/drivers/regulator/axp20x-regulator.c @@ -301,66 +301,53 @@ static int axp20x_set_dcdc_workmode(struct regulator_dev *rdev, int id, u32 work static int axp20x_regulator_probe(struct platform_device *pdev) { - struct regulator_dev *rdev; + struct regulator_set *rset; struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); - struct regulator_config config = { }; - struct regulator_init_data *init_data; + struct regulator_set_config config; struct of_regulator_match *matches; - int nmatches; - const struct regulator_desc *regulators; - int nregulators; int ret, i; u32 workmode; + memset(&config, 0, sizeof(config)); + config.dev = &pdev->dev; + config.regmap = axp20x->regmap; if (axp20x->variant == AXP221_ID) { matches = axp22x_matches; - nmatches = ARRAY_SIZE(axp22x_matches); - regulators = axp22x_regulators; - nregulators = AXP22X_REG_ID_MAX; + config.descs = axp22x_regulators; + config.nregulators = AXP22X_REG_ID_MAX; } else { matches = axp20x_matches; - nmatches = ARRAY_SIZE(axp20x_matches); - regulators = axp20x_regulators; - nregulators = AXP20X_REG_ID_MAX; + config.descs = axp20x_regulators; + config.nregulators = AXP20X_REG_ID_MAX; } + config.matches = matches; /* * Reset matches table (this table might have been modified by a * previous AXP2xx device probe). */ - for (i = 0; i < nmatches; i++) { + for (i = 0; i < config.nregulators; i++) { matches[i].init_data = NULL; matches[i].of_node = NULL; } - ret = axp20x_regulator_parse_dt(pdev, matches, nmatches); + ret = axp20x_regulator_parse_dt(pdev, matches, + config.nregulators); if (ret) return ret; - for (i = 0; i < AXP20X_REG_ID_MAX; i++) { - init_data = matches[i].init_data; + rset = devm_regulator_set_register(&pdev->dev, &config); + if (IS_ERR(rset)) + return PTR_ERR(rset); - config.dev = &pdev->dev; - config.init_data = init_data; - config.regmap = axp20x->regmap; - config.of_node = matches[i].of_node; - - rdev = devm_regulator_register(&pdev->dev, ®ulators[i], - &config); - if (IS_ERR(rdev)) { - dev_err(&pdev->dev, "Failed to register %s\n", - regulators[i].name); - - return PTR_ERR(rdev); - } - - ret = of_property_read_u32(matches[i].of_node, "x-powers,dcdc-workmode", + for (i = 0; i < rset->nregulators; i++) { + ret = of_property_read_u32(config.matches[i].of_node, + "x-powers,dcdc-workmode", &workmode); - if (!ret) { - if (axp20x_set_dcdc_workmode(rdev, i, workmode)) - dev_err(&pdev->dev, "Failed to set workmode on %s\n", - regulators[i].name); - } + if (!ret && + axp20x_set_dcdc_workmode(rset->regulators[i], i, workmode)) + dev_err(&pdev->dev, "Failed to set workmode on %s\n", + config.descs[i].name); } return 0;