From patchwork Fri May 18 08:39:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 8790 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id D913323E23 for ; Fri, 18 May 2012 08:39:32 +0000 (UTC) Received: from mail-yw0-f52.google.com (mail-yw0-f52.google.com [209.85.213.52]) by fiordland.canonical.com (Postfix) with ESMTP id 8EF14A181BC for ; Fri, 18 May 2012 08:39:32 +0000 (UTC) Received: by yhpp61 with SMTP id p61so3161765yhp.11 for ; Fri, 18 May 2012 01:39:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=b1NWztjNALxzFEeBfr0UoXmRtJQYcGaEa3AKzumdtF8=; b=TvhoLiV2N5bF4qYhzI3C8ZQfldFFKH8q15oq7pDNNRKjFQW+59zxOZf5WOEJMafTQZ uu8eufB/wnxMiIrI2CgZu4Fc3g3QN+s0wckHdchzrPC3egsQBkfzATnku5c0iCReGiRy 1Mi2x2TbfnsvgKFmtcc2zrXhl7ncQFGIEv9FeWrlljtlM/Ddnq7MeMlxtxpn6MmYywnH zSukK/EX6YT7+CVMB1fmF89s/KuXrP6CES82bke3L/IHbP68Tru4tUpUmC4Fii4srleR zo1b8UkanIgUmT+mdKNsWf4q3r4xh0GN07E2ehY346l4188R0JQQ0ljXEqUsEXGOUdO5 44YA== Received: by 10.42.119.129 with SMTP id b1mr274778icr.48.1337330371872; Fri, 18 May 2012 01:39:31 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.35.72 with SMTP id o8csp86434ibd; Fri, 18 May 2012 01:39:31 -0700 (PDT) Received: by 10.180.91.225 with SMTP id ch1mr26205575wib.18.1337330370704; Fri, 18 May 2012 01:39:30 -0700 (PDT) Received: from mail-wg0-f42.google.com (mail-wg0-f42.google.com [74.125.82.42]) by mx.google.com with ESMTPS id t6si11776051wiz.4.2012.05.18.01.39.30 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 18 May 2012 01:39:30 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.42 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=74.125.82.42; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.42 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) smtp.mail=lee.jones@linaro.org Received: by wgbds11 with SMTP id ds11so649782wgb.1 for ; Fri, 18 May 2012 01:39:30 -0700 (PDT) Received: by 10.216.27.199 with SMTP id e49mr6765573wea.45.1337330370145; Fri, 18 May 2012 01:39:30 -0700 (PDT) Received: from localhost.localdomain (cpc1-aztw13-0-0-cust473.18-1.cable.virginmedia.com. [77.102.241.218]) by mx.google.com with ESMTPS id bn9sm63091322wib.5.2012.05.18.01.39.28 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 18 May 2012 01:39:29 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, arnd@arndb.de, linus.walleij@stericsson.com, grant.likely@secretlab.ca, cjb@laptop.org, broonie@opensource.wolfsonmicro.com, sameo@linux.intel.com Cc: Lee Jones , linux-kernel@vger.kernel.org Subject: [PATCH 05/16] regulator: db8500-prcmu: Separate regulator registration from probe Date: Fri, 18 May 2012 09:39:04 +0100 Message-Id: <1337330355-17747-6-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1337330355-17747-1-git-send-email-lee.jones@linaro.org> References: <1337330355-17747-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQmeNXmPW7oW7jcyAK4dFRbsyy0Plqomh42bcWtYPDwM/bxtvAD+l++wgu1FX1NghCADNnYU This will provide us with a convenient way to register regulators when booting with Device Tree both enabled & disabled and will save us a great deal of code duplication in time. Cc: linux-kernel@vger.kernel.org Signed-off-by: Lee Jones --- drivers/regulator/db8500-prcmu.c | 71 +++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/drivers/regulator/db8500-prcmu.c b/drivers/regulator/db8500-prcmu.c index 87b2e83..d6b4d4c 100644 --- a/drivers/regulator/db8500-prcmu.c +++ b/drivers/regulator/db8500-prcmu.c @@ -410,40 +410,58 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { }, }; +static __devinit int db8500_regulator_register(struct platform_device *pdev, + struct regulator_init_data *init_data, + int id, + struct device_node *np) +{ + struct dbx500_regulator_info *info; + struct regulator_config config = { }; + int err; + + /* assign per-regulator data */ + info = &dbx500_regulator_info[id]; + info->dev = &pdev->dev; + + config.dev = &pdev->dev; + config.init_data = init_data; + config.driver_data = info; + config.of_node = np; + + /* register with the regulator framework */ + info->rdev = regulator_register(&info->desc, &config); + if (IS_ERR(info->rdev)) { + err = PTR_ERR(info->rdev); + dev_err(&pdev->dev, "failed to register %s: err %i\n", + info->desc.name, err); + + /* if failing, unregister all earlier regulators */ + while (--id >= 0) { + info = &dbx500_regulator_info[id]; + regulator_unregister(info->rdev); + } + return err; + } + + dev_dbg(rdev_get_dev(info->rdev), + "regulator-%s-probed\n", info->desc.name); + + return 0; +} + static int __devinit db8500_regulator_probe(struct platform_device *pdev) { struct regulator_init_data *db8500_init_data = dev_get_platdata(&pdev->dev); - struct regulator_config config = { }; int i, err; /* register all regulators */ for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) { - struct dbx500_regulator_info *info; - struct regulator_init_data *init_data = &db8500_init_data[i]; - - /* assign per-regulator data */ - info = &dbx500_regulator_info[i]; - info->dev = &pdev->dev; - - config.dev = &pdev->dev; - config.init_data = init_data; - config.driver_data = info; - - /* register with the regulator framework */ - info->rdev = regulator_register(&info->desc, &config); - if (IS_ERR(info->rdev)) { - err = PTR_ERR(info->rdev); - dev_err(&pdev->dev, "failed to register %s: err %i\n", - info->desc.name, err); - - /* if failing, unregister all earlier regulators */ - while (--i >= 0) { - info = &dbx500_regulator_info[i]; - regulator_unregister(info->rdev); - } + err = db8500_regulator_register(pdev, + &db8500_init_data[i], + i, NULL); + if (err) return err; - } dev_dbg(rdev_get_dev(info->rdev), "regulator-%s-probed\n", info->desc.name); @@ -451,8 +469,7 @@ static int __devinit db8500_regulator_probe(struct platform_device *pdev) err = ux500_regulator_debug_init(pdev, dbx500_regulator_info, ARRAY_SIZE(dbx500_regulator_info)); - - return err; + return 0; } static int __exit db8500_regulator_remove(struct platform_device *pdev)