From: Axel Lin <axel.lin@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Eric Miao <eric.y.miao@gmail.com>,
Mike Rapoport <mike@compulab.co.il>, Liam Girdwood <lrg@ti.com>,
Mark Brown <broonie@opensource.wolfsonmicro.com>
Subject: [PATCH RFT 1/2] regulator: da903x: Convert to regulator_list_voltage_linear()
Date: Tue, 15 May 2012 10:04:23 +0800 [thread overview]
Message-ID: <1337047463.26683.1.camel@phoenix> (raw)
Use regulator_list_voltage_linear() to replace da903x_list_voltage().
Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
drivers/regulator/da903x.c | 54 +++++++++++++++++--------------------------
1 files changed, 21 insertions(+), 33 deletions(-)
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
index c75e7b7..3a0d080 100644
--- a/drivers/regulator/da903x.c
+++ b/drivers/regulator/da903x.c
@@ -76,9 +76,7 @@
struct da903x_regulator_info {
struct regulator_desc desc;
- int min_uV;
int max_uV;
- int step_uV;
int vol_reg;
int vol_shift;
int vol_nbits;
@@ -96,7 +94,7 @@ static inline struct device *to_da903x_dev(struct regulator_dev *rdev)
static inline int check_range(struct da903x_regulator_info *info,
int min_uV, int max_uV)
{
- if (min_uV < info->min_uV || min_uV > info->max_uV)
+ if (min_uV < info->desc.min_uV || min_uV > info->max_uV)
return -EINVAL;
return 0;
@@ -115,7 +113,7 @@ static int da903x_set_ldo_voltage(struct regulator_dev *rdev,
return -EINVAL;
}
- val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV);
+ val = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step);
*selector = val;
val <<= info->vol_shift;
mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
@@ -172,17 +170,6 @@ static int da903x_is_enabled(struct regulator_dev *rdev)
return !!(reg_val & (1 << info->enable_bit));
}
-static int da903x_list_voltage(struct regulator_dev *rdev, unsigned selector)
-{
- struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
- int ret;
-
- ret = info->min_uV + info->step_uV * selector;
- if (ret > info->max_uV)
- return -EINVAL;
- return ret;
-}
-
/* DA9030 specific operations */
static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
int min_uV, int max_uV,
@@ -198,7 +185,7 @@ static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
return -EINVAL;
}
- val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV);
+ val = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step);
*selector = val;
val <<= info->vol_shift;
mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
@@ -227,12 +214,12 @@ static int da9030_set_ldo14_voltage(struct regulator_dev *rdev,
return -EINVAL;
}
- thresh = (info->max_uV + info->min_uV) / 2;
+ thresh = (info->max_uV + info->desc.min_uV) / 2;
if (min_uV < thresh) {
- val = DIV_ROUND_UP(thresh - min_uV, info->step_uV);
+ val = DIV_ROUND_UP(thresh - min_uV, info->desc.uV_step);
val |= 0x4;
} else {
- val = DIV_ROUND_UP(min_uV - thresh, info->step_uV);
+ val = DIV_ROUND_UP(min_uV - thresh, info->desc.uV_step);
}
*selector = val;
@@ -266,10 +253,11 @@ static int da9030_list_ldo14_voltage(struct regulator_dev *rdev,
int volt;
if (selector & 0x4)
- volt = info->min_uV + info->step_uV * (3 - (selector & ~0x4));
+ volt = rdev->desc->min_uV +
+ rdev->desc->uV_step * (3 - (selector & ~0x4));
else
- volt = (info->max_uV + info->min_uV) / 2 +
- info->step_uV * (selector & ~0x4);
+ volt = (info->max_uV + rdev->desc->min_uV) / 2 +
+ rdev->desc->uV_step * (selector & ~0x4);
if (volt > info->max_uV)
return -EINVAL;
@@ -291,7 +279,7 @@ static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
return -EINVAL;
}
- val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV);
+ val = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step);
*selector = val;
val <<= info->vol_shift;
mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
@@ -317,7 +305,7 @@ static int da9034_set_ldo12_voltage(struct regulator_dev *rdev,
return -EINVAL;
}
- val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV);
+ val = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step);
val = (val >= 20) ? val - 12 : ((val > 7) ? 8 : val);
*selector = val;
val <<= info->vol_shift;
@@ -350,9 +338,9 @@ static int da9034_list_ldo12_voltage(struct regulator_dev *rdev,
int volt;
if (selector >= 8)
- volt = 2700000 + info->step_uV * (selector - 8);
+ volt = 2700000 + rdev->desc->uV_step * (selector - 8);
else
- volt = info->min_uV + info->step_uV * selector;
+ volt = rdev->desc->min_uV + rdev->desc->uV_step * selector;
if (volt > info->max_uV)
return -EINVAL;
@@ -363,7 +351,7 @@ static int da9034_list_ldo12_voltage(struct regulator_dev *rdev,
static struct regulator_ops da903x_regulator_ldo_ops = {
.set_voltage = da903x_set_ldo_voltage,
.get_voltage_sel = da903x_get_voltage_sel,
- .list_voltage = da903x_list_voltage,
+ .list_voltage = regulator_list_voltage_linear,
.enable = da903x_enable,
.disable = da903x_disable,
.is_enabled = da903x_is_enabled,
@@ -383,7 +371,7 @@ static struct regulator_ops da9030_regulator_ldo14_ops = {
static struct regulator_ops da9030_regulator_ldo1_15_ops = {
.set_voltage = da9030_set_ldo1_15_voltage,
.get_voltage_sel = da903x_get_voltage_sel,
- .list_voltage = da903x_list_voltage,
+ .list_voltage = regulator_list_voltage_linear,
.enable = da903x_enable,
.disable = da903x_disable,
.is_enabled = da903x_is_enabled,
@@ -392,7 +380,7 @@ static struct regulator_ops da9030_regulator_ldo1_15_ops = {
static struct regulator_ops da9034_regulator_dvc_ops = {
.set_voltage = da9034_set_dvc_voltage,
.get_voltage_sel = da903x_get_voltage_sel,
- .list_voltage = da903x_list_voltage,
+ .list_voltage = regulator_list_voltage_linear,
.enable = da903x_enable,
.disable = da903x_disable,
.is_enabled = da903x_is_enabled,
@@ -417,10 +405,10 @@ static struct regulator_ops da9034_regulator_ldo12_ops = {
.id = _pmic##_ID_LDO##_id, \
.n_voltages = (step) ? ((max - min) / step + 1) : 1, \
.owner = THIS_MODULE, \
+ .min_uV = (min) * 1000, \
+ .uV_step = (step) * 1000, \
}, \
- .min_uV = (min) * 1000, \
.max_uV = (max) * 1000, \
- .step_uV = (step) * 1000, \
.vol_reg = _pmic##_##vreg, \
.vol_shift = (shift), \
.vol_nbits = (nbits), \
@@ -437,10 +425,10 @@ static struct regulator_ops da9034_regulator_ldo12_ops = {
.id = _pmic##_ID_##_id, \
.n_voltages = (step) ? ((max - min) / step + 1) : 1, \
.owner = THIS_MODULE, \
+ .min_uV = (min) * 1000, \
+ .uV_step = (step) * 1000, \
}, \
- .min_uV = (min) * 1000, \
.max_uV = (max) * 1000, \
- .step_uV = (step) * 1000, \
.vol_reg = _pmic##_##vreg, \
.vol_shift = (0), \
.vol_nbits = (nbits), \
--
1.7.5.4
next reply other threads:[~2012-05-15 2:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-15 2:04 Axel Lin [this message]
2012-05-15 2:06 ` [PATCH RFT 2/2] regulator: da903x: Convert to set_voltage_sel and map_voltage Axel Lin
2012-05-15 17:33 ` [PATCH RFT 1/2] regulator: da903x: Convert to regulator_list_voltage_linear() Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1337047463.26683.1.camel@phoenix \
--to=axel.lin@gmail.com \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=eric.y.miao@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lrg@ti.com \
--cc=mike@compulab.co.il \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.