From patchwork Tue Sep 20 16:38:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Francois Moine X-Patchwork-Id: 9347637 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C2E60601C2 for ; Fri, 23 Sep 2016 07:51:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3C9C2A230 for ; Fri, 23 Sep 2016 07:51:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A77F92A237; Fri, 23 Sep 2016 07:51:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 26F2F2A230 for ; Fri, 23 Sep 2016 07:51:33 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bnLFR-00052m-Pk; Fri, 23 Sep 2016 07:50:17 +0000 Received: from smtp2-g21.free.fr ([2a01:e0c:1:1599::11]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bnLEa-0004JH-EJ for linux-arm-kernel@lists.infradead.org; Fri, 23 Sep 2016 07:49:25 +0000 Received: from localhost (unknown [37.161.93.240]) by smtp2-g21.free.fr (Postfix) with ESMTP id D3B552003D6; Fri, 23 Sep 2016 09:48:59 +0200 (CEST) X-Mailbox-Line: From 7496199d0a35463dc66346eb0985d059cbdcfc11 Mon Sep 17 00:00:00 2001 Message-Id: <7496199d0a35463dc66346eb0985d059cbdcfc11.1474616699.git.moinejf@free.fr> In-Reply-To: References: From: Jean-Francois Moine Date: Tue, 20 Sep 2016 18:38:31 +0200 Subject: [PATCH 2/3] regulator: axp20x: simplify the treatment of linked regulators To: Chen-Yu Tsai , Mark Rutland , Rob Herring X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160923_004924_854281_8A5A9374 X-CRM114-Status: GOOD ( 10.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-sunxi@googlegroups.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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 Using ancillary variables for handling the linked regulators simplifies the loop of regulator creation and makes easier the addition of new regulator types. Signed-off-by: Jean-Francois Moine --- drivers/regulator/axp20x-regulator.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c index 4e5e7c8..7405f5b 100644 --- a/drivers/regulator/axp20x-regulator.c +++ b/drivers/regulator/axp20x-regulator.c @@ -511,6 +511,10 @@ static int axp20x_regulator_probe(struct platform_device *pdev) u32 workmode; const char *dcdc1_name = axp22x_regulators[AXP22X_DCDC1].name; const char *dcdc5_name = axp22x_regulators[AXP22X_DCDC5].name; + s8 dcdc1_ix = -1; + s8 dcdc5_ix = -1; + s8 dc1sw_ix = -1; + s8 dc5ldo_ix = -1; bool drivevbus = false; u32 skip_bitmap = 0; @@ -524,6 +528,10 @@ static int axp20x_regulator_probe(struct platform_device *pdev) case AXP223_ID: regulators = axp22x_regulators; nregulators = AXP22X_REG_ID_MAX; + dcdc1_ix = AXP22X_DCDC1; + dcdc5_ix = AXP22X_DCDC5; + dc1sw_ix = AXP22X_DC1SW; + dc5ldo_ix = AXP22X_DC5LDO; drivevbus = of_property_read_bool(pdev->dev.parent->of_node, "x-powers,drive-vbus-en"); break; @@ -541,6 +549,10 @@ static int axp20x_regulator_probe(struct platform_device *pdev) case AXP809_ID: regulators = axp809_regulators; nregulators = AXP809_REG_ID_MAX; + dcdc1_ix = AXP809_DCDC1; + dcdc5_ix = AXP809_DCDC5; + dc1sw_ix = AXP809_DC1SW; + dc5ldo_ix = AXP809_DC5LDO; break; default: dev_err(&pdev->dev, "Unsupported AXP variant: %ld\n", @@ -567,8 +579,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev) * part of this loop to see where we save the DT defined * name. */ - if ((regulators == axp22x_regulators && i == AXP22X_DC1SW) || - (regulators == axp809_regulators && i == AXP809_DC1SW)) { + if (i == dc1sw_ix && dcdc1_name) { new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL); *new_desc = regulators[i]; @@ -576,8 +587,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev) desc = new_desc; } - if ((regulators == axp22x_regulators && i == AXP22X_DC5LDO) || - (regulators == axp809_regulators && i == AXP809_DC5LDO)) { + if (i == dc5ldo_ix && dcdc5_name) { new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL); *new_desc = regulators[i]; @@ -605,14 +615,12 @@ static int axp20x_regulator_probe(struct platform_device *pdev) /* * Save AXP22X DCDC1 / DCDC5 regulator names for later. */ - if ((regulators == axp22x_regulators && i == AXP22X_DCDC1) || - (regulators == axp809_regulators && i == AXP809_DCDC1)) + if (i == dcdc1_ix) of_property_read_string(rdev->dev.of_node, "regulator-name", &dcdc1_name); - if ((regulators == axp22x_regulators && i == AXP22X_DCDC5) || - (regulators == axp809_regulators && i == AXP809_DCDC5)) + if (i == dcdc5_ix) of_property_read_string(rdev->dev.of_node, "regulator-name", &dcdc5_name);