From patchwork Tue Sep 20 16:09:40 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: 9347633 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 26708601C2 for ; Fri, 23 Sep 2016 07:51:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14D8529F38 for ; Fri, 23 Sep 2016 07:51:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 09CE32A221; Fri, 23 Sep 2016 07:51:05 +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 46E5729F38 for ; Fri, 23 Sep 2016 07:51:02 +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 1bnLEs-0004OQ-87; Fri, 23 Sep 2016 07:49:42 +0000 Received: from smtp2-g21.free.fr ([212.27.42.2]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bnLEZ-0004JG-Fh for linux-arm-kernel@lists.infradead.org; Fri, 23 Sep 2016 07:49:24 +0000 Received: from localhost (unknown [37.161.93.240]) by smtp2-g21.free.fr (Postfix) with ESMTP id 641DF200398; Fri, 23 Sep 2016 09:48:59 +0200 (CEST) X-Mailbox-Line: From 098a013d31924dfd6dff81927a70e91381b1f8d3 Mon Sep 17 00:00:00 2001 Message-Id: <098a013d31924dfd6dff81927a70e91381b1f8d3.1474616699.git.moinejf@free.fr> In-Reply-To: References: From: Jean-Francois Moine Date: Tue, 20 Sep 2016 18:09:40 +0200 Subject: [PATCH 1/3] regulator: axp20x: simplify poly-phase handling 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_004923_732123_3ADA63DA X-CRM114-Status: GOOD ( 12.58 ) 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 Building a list (bitmap) of the slaves included in poly-phase groups at probe startup time simplifies the treatment in the regulator creation loop. Signed-off-by: Jean-Francois Moine --- drivers/regulator/axp20x-regulator.c | 45 +++++++++++++++++------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c index 54382ef..4e5e7c8 100644 --- a/drivers/regulator/axp20x-regulator.c +++ b/drivers/regulator/axp20x-regulator.c @@ -477,30 +477,24 @@ static int axp20x_set_dcdc_workmode(struct regulator_dev *rdev, int id, u32 work } /* - * This function checks whether a regulator is part of a poly-phase - * output setup based on the registers settings. Returns true if it is. + * This function checks which regulators are part of poly-phase + * output setups based on the registers settings. + * Returns a bitmap of these regulators. */ -static bool axp20x_is_polyphase_slave(struct axp20x_dev *axp20x, int id) +static u32 axp20x_polyphase_slave(struct axp20x_dev *axp20x) { - u32 reg = 0; - - /* Only AXP806 has poly-phase outputs */ - if (axp20x->variant != AXP806_ID) - return false; + u32 reg = 0, bitmap = 0; regmap_read(axp20x->regmap, AXP806_DCDC_MODE_CTRL2, ®); - switch (id) { - case AXP806_DCDCB: - return (((reg & GENMASK(7, 6)) == BIT(6)) || - ((reg & GENMASK(7, 6)) == BIT(7))); - case AXP806_DCDCC: - return ((reg & GENMASK(7, 6)) == BIT(7)); - case AXP806_DCDCE: - return !!(reg & BIT(5)); - } + if ((reg & GENMASK(7, 6)) == BIT(5)) + bitmap |= 1 << AXP806_DCDCE; + if ((reg & GENMASK(7, 6)) == BIT(6)) + bitmap |= 1 << AXP806_DCDCB; + if ((reg & GENMASK(7, 6)) == BIT(7)) + bitmap |= (1 << AXP806_DCDCB) | (1 << AXP806_DCDCC); - return false; + return bitmap; } static int axp20x_regulator_probe(struct platform_device *pdev) @@ -518,6 +512,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev) const char *dcdc1_name = axp22x_regulators[AXP22X_DCDC1].name; const char *dcdc5_name = axp22x_regulators[AXP22X_DCDC5].name; bool drivevbus = false; + u32 skip_bitmap = 0; switch (axp20x->variant) { case AXP202_ID: @@ -535,6 +530,13 @@ static int axp20x_regulator_probe(struct platform_device *pdev) case AXP806_ID: regulators = axp806_regulators; nregulators = AXP806_REG_ID_MAX; + + /* + * The regulators which are slave in a poly-phase setup + * are skipped, as their controls are bound to the master + * regulator and won't work. + */ + skip_bitmap |= axp20x_polyphase_slave(axp20x); break; case AXP809_ID: regulators = axp809_regulators; @@ -553,12 +555,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev) const struct regulator_desc *desc = ®ulators[i]; struct regulator_desc *new_desc; - /* - * If this regulator is a slave in a poly-phase setup, - * skip it, as its controls are bound to the master - * regulator and won't work. - */ - if (axp20x_is_polyphase_slave(axp20x, i)) + if (skip_bitmap & (1 << i)) continue; /*