From: Krzysztof Kozlowski Date: Mon, 27 Oct 2014 12:11:48 +0000 (+0100) Subject: regulator: max77686: Store opmode non-shifted X-Git-Tag: v4.14-rc1~6395^2~2^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=68c5d1868bfed0643eb4d2c608cead41f6bf4132;p=platform%2Fkernel%2Flinux-rpi.git regulator: max77686: Store opmode non-shifted 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 Signed-off-by: Mark Brown --- diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c index db01c09..0c15417 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)) {