From patchwork Mon Apr 22 09:57:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 2471481 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork1.kernel.org (Postfix) with ESMTP id D2AE63FD40 for ; Mon, 22 Apr 2013 11:20:09 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UUDWy-00007Y-RE; Mon, 22 Apr 2013 09:59:31 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UUDVB-0002zB-Iu; Mon, 22 Apr 2013 09:57:37 +0000 Received: from eu1sys200aog121.obsmtp.com ([207.126.144.151]) by merlin.infradead.org with smtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UUDV7-0002ya-Uj for linux-arm-kernel@lists.infradead.org; Mon, 22 Apr 2013 09:57:34 +0000 Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob121.postini.com ([207.126.147.11]) with SMTP ID DSNKUXUJghQiIWp1h4S2GHStqWtgmxA2aPfn@postini.com; Mon, 22 Apr 2013 09:57:33 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id A307514F; Mon, 22 Apr 2013 09:57:21 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 73CCB487F; Mon, 22 Apr 2013 09:57:15 +0000 (GMT) Received: from exdcvycastm022.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm022", Issuer "exdcvycastm022" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id 776DF24C07C; Mon, 22 Apr 2013 11:57:15 +0200 (CEST) Received: from steludxu4075.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.30) with Microsoft SMTP Server (TLS) id 8.3.279.5; Mon, 22 Apr 2013 11:57:20 +0200 From: Linus Walleij To: , Liam Girdwood , Mark Brown Subject: [PATCH 13/23] regulator: ab3100: refactor probe to use IDs Date: Mon, 22 Apr 2013 11:57:14 +0200 Message-ID: <1366624634-6579-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.11.3 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130422_055734_221078_52B86970 X-CRM114-Status: GOOD ( 21.52 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [207.126.144.151 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: devicetree-discuss@lists.ozlabs.org, Linus Walleij , Arnd Bergmann X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Linus Walleij This refactors the AB3100 regulator probe to use regulator IDs and pass this to a separate registration function. This works much smoother when migrating to device tree, as we can use a match table with this regulator ID encoded in the .driver_data. Cc: Mark Brown Signed-off-by: Linus Walleij --- Hi Mark, seeking an ACK on this to take it through the ARM SoC tree. --- drivers/regulator/ab3100.c | 90 ++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c index 111ec69..740735d 100644 --- a/drivers/regulator/ab3100.c +++ b/drivers/regulator/ab3100.c @@ -488,6 +488,58 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = { }, }; +static int ab3100_regulator_register(struct platform_device *pdev, + struct ab3100_platform_data *plfdata, + int id) +{ + struct regulator_desc *desc; + struct ab3100_regulator *reg; + struct regulator_dev *rdev; + struct regulator_config config = { }; + int err, i; + + for (i = 0; i < AB3100_NUM_REGULATORS; i++) { + desc = &ab3100_regulator_desc[i]; + if (desc->id == id) + break; + } + if (desc->id != id) + return -ENODEV; + + /* Same index used for this array */ + reg = &ab3100_regulators[i]; + + /* + * Initialize per-regulator struct. + * Inherit platform data, this comes down from the + * i2c boarddata, from the machine. So if you want to + * see what it looks like for a certain machine, go + * into the machine I2C setup. + */ + reg->dev = &pdev->dev; + if (plfdata) { + /* This will be replaced by device tree data */ + reg->plfdata = plfdata; + config.init_data = &plfdata->reg_constraints[i]; + } + config.dev = &pdev->dev; + config.driver_data = reg; + + rdev = regulator_register(desc, &config); + if (IS_ERR(rdev)) { + err = PTR_ERR(rdev); + dev_err(&pdev->dev, + "%s: failed to register regulator %s err %d\n", + __func__, desc->name, + err); + return err; + } + + /* Then set a pointer back to the registered regulator */ + reg->rdev = rdev; + return 0; +} + /* * NOTE: the following functions are regulators pluralis - it is the * binding to the AB3100 core driver and the parent platform device @@ -497,7 +549,6 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = { static int ab3100_regulators_probe(struct platform_device *pdev) { struct ab3100_platform_data *plfdata = pdev->dev.platform_data; - struct regulator_config config = { }; int err = 0; u8 data; int i; @@ -530,42 +581,11 @@ static int ab3100_regulators_probe(struct platform_device *pdev) /* Register the regulators */ for (i = 0; i < AB3100_NUM_REGULATORS; i++) { - struct ab3100_regulator *reg = &ab3100_regulators[i]; - struct regulator_dev *rdev; - - /* - * Initialize per-regulator struct. - * Inherit platform data, this comes down from the - * i2c boarddata, from the machine. So if you want to - * see what it looks like for a certain machine, go - * into the machine I2C setup. - */ - reg->dev = &pdev->dev; - reg->plfdata = plfdata; - - config.dev = &pdev->dev; - config.driver_data = reg; - config.init_data = &plfdata->reg_constraints[i]; + struct regulator_desc *desc = &ab3100_regulator_desc[i]; - /* - * Register the regulator, pass around - * the ab3100_regulator struct - */ - rdev = regulator_register(&ab3100_regulator_desc[i], &config); - if (IS_ERR(rdev)) { - err = PTR_ERR(rdev); - dev_err(&pdev->dev, - "%s: failed to register regulator %s err %d\n", - __func__, ab3100_regulator_desc[i].name, - err); - /* remove the already registered regulators */ - while (--i >= 0) - regulator_unregister(ab3100_regulators[i].rdev); + err = ab3100_regulator_register(pdev, plfdata, desc->id); + if (err) return err; - } - - /* Then set a pointer back to the registered regulator */ - reg->rdev = rdev; } return 0;