From patchwork Mon Oct 27 12:11:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 5159951 Return-Path: X-Original-To: patchwork-linux-samsung-soc@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 9CAE29F318 for ; Mon, 27 Oct 2014 12:14:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B18B020303 for ; Mon, 27 Oct 2014 12:14:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 215F02027D for ; Mon, 27 Oct 2014 12:14:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752589AbaJ0MMG (ORCPT ); Mon, 27 Oct 2014 08:12:06 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:56746 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752570AbaJ0MME (ORCPT ); Mon, 27 Oct 2014 08:12:04 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NE3000N8RCQ1330@mailout2.w1.samsung.com>; Mon, 27 Oct 2014 12:14:50 +0000 (GMT) X-AuditID: cbfec7f5-b7f956d000005ed7-84-544e369139a2 Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 93.66.24279.1963E445; Mon, 27 Oct 2014 12:12:01 +0000 (GMT) Received: from AMDC1943.digital.local ([106.116.151.171]) by eusync1.samsung.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0NE300EP2R7U7E10@eusync1.samsung.com>; Mon, 27 Oct 2014 12:12:01 +0000 (GMT) From: Krzysztof Kozlowski To: Liam Girdwood , Mark Brown , linux-kernel@vger.kernel.org, Ben Dooks , Kukjin Kim , Russell King , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, devicetree@vger.kernel.org Cc: Kyungmin Park , Marek Szyprowski , Bartlomiej Zolnierkiewicz , Javier Martinez Canillas , Chanwoo Choi , Krzysztof Kozlowski Subject: [PATCH v5 2/4] regulator: max77686: Store opmode non-shifted Date: Mon, 27 Oct 2014 13:11:48 +0100 Message-id: <1414411911-5539-3-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1414411911-5539-1-git-send-email-k.kozlowski@samsung.com> References: <1414411911-5539-1-git-send-email-k.kozlowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOLMWRmVeSWpSXmKPExsVy+t/xy7oTzfxCDI6+1rDYOGM9q8WkdQeY LKY+fMJmcf3Lc1aL+UfOsVoc/V1g8fqFoUXvgqtsFmeb3rBbfLvSwWSx6fE1VovLu+awWcw4 v4/J4vZlXou1R+6yO/B7tDT3sHn8fX6dxePvqhfMHjtn3WX32LSqk81j85J6j74tqxg9Pm+S C+CI4rJJSc3JLEst0rdL4Mp4fng3U8EJlYquvnXsDYzdcl2MnBwSAiYSU74uZIWwxSQu3FvP 1sXIxSEksJRRYu66ViYIp49JYuWywywgVWwCxhKbly9hA7FFBPYzSTyeYAJSxCywmkni55VT zF2MHBzCAq4SLTOtQUwWAVWJLauDQExeATeJjdMYIXbJSZw8NhlsL6eAu8SbOW1gcSGgkmWn HrJPYORdwMiwilE0tTS5oDgpPddIrzgxt7g0L10vOT93EyMkcL/uYFx6zOoQowAHoxIP74Ri 3xAh1sSy4srcQ4wSHMxKIryOP4FCvCmJlVWpRfnxRaU5qcWHGJk4OKUaGOs5bu05NJm/tEVy xjrOBYpfrKfucW45E/5safin75t0nnCK8lyNtjAw1f2dYy1qX8qlry9rPHHr2yCtT2y9JWzf 6ks/WE6JKr2/uXb9xbyMj1wf9GqSmfPqNH1ut0z4/Kz3xaeVWRsMZed/NmXifjx5lkLxn1nd bw9ciVD/E/HM0uh06rkPuUosxRmJhlrMRcWJACqNFA46AgAA Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce simple helper for calculating the shift for OPMODE field in registers. This allows storing the current value of opmode in non-shifted form and simplifies a little set_suspend_disable and enable functions. Additionally this will allow adding support LDOs to the existing set_suspend_disable function. Signed-off-by: Krzysztof Kozlowski Suggested-by: Javier Martinez Canillas Reviewed-by: Javier Martinez Canillas --- drivers/regulator/max77686.c | 49 ++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c index c625a8a7940d..2ebc4257425b 100644 --- a/drivers/regulator/max77686.c +++ b/drivers/regulator/max77686.c @@ -85,20 +85,32 @@ struct max77686_data { unsigned int opmode[MAX77686_REGULATORS]; }; +static unsigned int max77686_get_opmode_shift(int id) +{ + switch (id) { + case MAX77686_BUCK1: + case MAX77686_BUCK5 ... MAX77686_BUCK9: + return 0; + case MAX77686_BUCK2 ... MAX77686_BUCK4: + return MAX77686_OPMODE_BUCK234_SHIFT; + default: + /* all LDOs */ + return MAX77686_OPMODE_SHIFT; + } +} + /* Some BUCKS supports Normal[ON/OFF] mode during suspend */ static int max77686_buck_set_suspend_disable(struct regulator_dev *rdev) { - unsigned int val; + unsigned int val, shift; struct max77686_data *max77686 = rdev_get_drvdata(rdev); int ret, id = rdev_get_id(rdev); - if (id == MAX77686_BUCK1) - val = MAX77686_OFF_PWRREQ; - else - val = MAX77686_OFF_PWRREQ << MAX77686_OPMODE_BUCK234_SHIFT; + shift = max77686_get_opmode_shift(id); + val = MAX77686_OFF_PWRREQ; ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, - rdev->desc->enable_mask, val); + rdev->desc->enable_mask, val << shift); if (ret) return ret; @@ -120,10 +132,10 @@ static int max77686_set_suspend_mode(struct regulator_dev *rdev, switch (mode) { case REGULATOR_MODE_IDLE: /* ON in LP Mode */ - val = MAX77686_LDO_LOWPOWER_PWRREQ << MAX77686_OPMODE_SHIFT; + val = MAX77686_LDO_LOWPOWER_PWRREQ; break; case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ - val = MAX77686_NORMAL << MAX77686_OPMODE_SHIFT; + val = MAX77686_NORMAL; break; default: pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", @@ -132,7 +144,8 @@ static int max77686_set_suspend_mode(struct regulator_dev *rdev, } ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, - rdev->desc->enable_mask, val); + rdev->desc->enable_mask, + val << MAX77686_OPMODE_SHIFT); if (ret) return ret; @@ -150,13 +163,13 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev, switch (mode) { case REGULATOR_MODE_STANDBY: /* switch off */ - val = MAX77686_OFF_PWRREQ << MAX77686_OPMODE_SHIFT; + val = MAX77686_OFF_PWRREQ; break; case REGULATOR_MODE_IDLE: /* ON in LP Mode */ - val = MAX77686_LDO_LOWPOWER_PWRREQ << MAX77686_OPMODE_SHIFT; + val = MAX77686_LDO_LOWPOWER_PWRREQ; break; case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ - val = MAX77686_NORMAL << MAX77686_OPMODE_SHIFT; + val = MAX77686_NORMAL; break; default: pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", @@ -165,7 +178,8 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev, } ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, - rdev->desc->enable_mask, val); + rdev->desc->enable_mask, + val << MAX77686_OPMODE_SHIFT); if (ret) return ret; @@ -176,10 +190,14 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev, static int max77686_enable(struct regulator_dev *rdev) { struct max77686_data *max77686 = rdev_get_drvdata(rdev); + unsigned int shift; + int id = rdev_get_id(rdev); + + shift = max77686_get_opmode_shift(id); return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, rdev->desc->enable_mask, - max77686->opmode[rdev_get_id(rdev)]); + max77686->opmode[id] << shift); } static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) @@ -495,7 +513,8 @@ static int max77686_pmic_probe(struct platform_device *pdev) config.init_data = pdata->regulators[i].initdata; config.of_node = pdata->regulators[i].of_node; - max77686->opmode[i] = regulators[i].enable_mask; + max77686->opmode[i] = regulators[i].enable_mask >> + max77686_get_opmode_shift(i); rdev = devm_regulator_register(&pdev->dev, ®ulators[i], &config); if (IS_ERR(rdev)) {