diff options
author | Laxman Dewangan <ldewangan@nvidia.com> | 2011-10-24 21:52:30 +0530 |
---|---|---|
committer | Dan Willemsen <dwillemsen@nvidia.com> | 2011-11-30 21:49:44 -0800 |
commit | e991f992c9a25d4de239963ef6386b29b19527db (patch) | |
tree | b7775633a706d9c898aeeaaa218f55d39f940486 /drivers/regulator | |
parent | 61fc54aed862e0502b618ce8b81a07f4ae76f6a6 (diff) |
regulator: ricoh583: Use register cache to optimise set_voltage
Optimising the read-modify-write operation for setting voltage
by using the register cache.
Reviewed-on: http://git-master/r/60412
(cherry picked from commit 4880f2de83efe7c7c88edf156f1434e7b402b4ce)
Change-Id: I5861838a0e5f98c03badf02a831b852a9eff3952
Reviewed-on: http://git-master/r/61436
Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com>
Tested-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-by: Bitan Biswas <bbiswas@nvidia.com>
Rebase-Id: R7821472f936fce9e270403031d48c6fea3dc1a35
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/ricoh583-regulator.c | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/drivers/regulator/ricoh583-regulator.c b/drivers/regulator/ricoh583-regulator.c index 3044977d31f3..4ea861969b89 100644 --- a/drivers/regulator/ricoh583-regulator.c +++ b/drivers/regulator/ricoh583-regulator.c @@ -45,6 +45,7 @@ struct ricoh583_regulator { u8 disc_bit; u8 vout_reg; u8 vout_mask; + u8 vout_reg_cache; u8 deepsleep_reg; /* chip constraints on regulator behavior */ @@ -149,6 +150,7 @@ static int __ricoh583_set_voltage(struct device *parent, { int vsel; int ret; + uint8_t vout_val; if ((min_uV < ri->min_uV) || (max_uV > ri->max_uV)) return -EDOM; @@ -157,9 +159,13 @@ static int __ricoh583_set_voltage(struct device *parent, if (vsel > ri->nsteps) return -EDOM; - ret = ricoh583_update(parent, ri->vout_reg, vsel, ri->vout_mask); + vout_val = (ri->vout_reg_cache & ~ri->vout_mask) | (vsel & ri->vout_mask); + ret = ricoh583_write(parent, ri->vout_reg, vout_val); if (ret < 0) dev_err(ri->dev, "Error in writing the Voltage register\n"); + else + ri->vout_reg_cache = vout_val; + return ret; } @@ -172,20 +178,12 @@ static int ricoh583_set_voltage(struct regulator_dev *rdev, return __ricoh583_set_voltage(parent, ri, min_uV, max_uV); } - static int ricoh583_get_voltage(struct regulator_dev *rdev) { struct ricoh583_regulator *ri = rdev_get_drvdata(rdev); - struct device *parent = to_ricoh583_dev(rdev); uint8_t vsel; - int ret; - ret = ricoh583_read(parent, ri->vout_reg, &vsel); - if (ret < 0) { - dev_err(&rdev->dev, "Error in reading the Voltage register\n"); - return ret; - } - vsel &= vsel & ri->vout_mask; + vsel = ri->vout_reg_cache & ri->vout_mask; return ri->min_uV + vsel * ri->step_uV; } @@ -318,6 +316,13 @@ static int ricoh583_regulator_preinit(struct device *parent, return ret; } +static inline int ricoh583_cache_regulator_register(struct device *parent, + struct ricoh583_regulator *ri) +{ + ri->vout_reg_cache = 0; + return ricoh583_read(parent, ri->vout_reg, &ri->vout_reg_cache); +} + static int __devinit ricoh583_regulator_probe(struct platform_device *pdev) { struct ricoh583_regulator *ri = NULL; @@ -336,10 +341,17 @@ static int __devinit ricoh583_regulator_probe(struct platform_device *pdev) tps_pdata = pdev->dev.platform_data; ri->dev = &pdev->dev; - err = ricoh583_regulator_preinit(pdev->dev.parent, ri, tps_pdata); - if (err) + err = ricoh583_cache_regulator_register(pdev->dev.parent, ri); + if (err) { + dev_err(&pdev->dev, "Fail in caching register\n"); return err; + } + err = ricoh583_regulator_preinit(pdev->dev.parent, ri, tps_pdata); + if (err) { + dev_err(&pdev->dev, "Fail in pre-initialisation\n"); + return err; + } rdev = regulator_register(&ri->desc, &pdev->dev, &tps_pdata->regulator, ri); if (IS_ERR_OR_NULL(rdev)) { |