Commit 5b1f537e authored by Axel Lin's avatar Axel Lin Committed by Mark Brown

regulator: da9063: Convert to use regulator_set/get_current_limit_regmap

Use regulator_set/get_current_limit_regmap helpers to save some code.
Signed-off-by: default avatarAxel Lin <axel.lin@ingics.com>
Acked-by: default avatarSteve Twiss <stwiss@opensource.diasemi.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 958e9b82
...@@ -38,17 +38,12 @@ ...@@ -38,17 +38,12 @@
struct da9063_regulator_info { struct da9063_regulator_info {
struct regulator_desc desc; struct regulator_desc desc;
/* Current limiting */
unsigned n_current_limits;
const int *current_limits;
/* DA9063 main register fields */ /* DA9063 main register fields */
struct reg_field mode; /* buck mode of operation */ struct reg_field mode; /* buck mode of operation */
struct reg_field suspend; struct reg_field suspend;
struct reg_field sleep; struct reg_field sleep;
struct reg_field suspend_sleep; struct reg_field suspend_sleep;
unsigned int suspend_vsel_reg; unsigned int suspend_vsel_reg;
struct reg_field ilimit;
/* DA9063 event detection bit */ /* DA9063 event detection bit */
struct reg_field oc_event; struct reg_field oc_event;
...@@ -73,15 +68,18 @@ struct da9063_regulator_info { ...@@ -73,15 +68,18 @@ struct da9063_regulator_info {
.suspend_vsel_reg = DA9063_REG_V##regl_name##_B .suspend_vsel_reg = DA9063_REG_V##regl_name##_B
/* Macros for voltage DC/DC converters (BUCKs) */ /* Macros for voltage DC/DC converters (BUCKs) */
#define DA9063_BUCK(chip, regl_name, min_mV, step_mV, max_mV, limits_array) \ #define DA9063_BUCK(chip, regl_name, min_mV, step_mV, max_mV, limits_array, \
creg, cmask) \
.desc.id = chip##_ID_##regl_name, \ .desc.id = chip##_ID_##regl_name, \
.desc.name = __stringify(chip##_##regl_name), \ .desc.name = __stringify(chip##_##regl_name), \
.desc.ops = &da9063_buck_ops, \ .desc.ops = &da9063_buck_ops, \
.desc.min_uV = (min_mV) * 1000, \ .desc.min_uV = (min_mV) * 1000, \
.desc.uV_step = (step_mV) * 1000, \ .desc.uV_step = (step_mV) * 1000, \
.desc.n_voltages = ((max_mV) - (min_mV))/(step_mV) + 1, \ .desc.n_voltages = ((max_mV) - (min_mV))/(step_mV) + 1, \
.current_limits = limits_array, \ .desc.csel_reg = (creg), \
.n_current_limits = ARRAY_SIZE(limits_array) .desc.csel_mask = (cmask), \
.desc.curr_table = limits_array, \
.desc.n_current_limits = ARRAY_SIZE(limits_array)
#define DA9063_BUCK_COMMON_FIELDS(regl_name) \ #define DA9063_BUCK_COMMON_FIELDS(regl_name) \
.desc.enable_reg = DA9063_REG_##regl_name##_CONT, \ .desc.enable_reg = DA9063_REG_##regl_name##_CONT, \
...@@ -112,7 +110,6 @@ struct da9063_regulator { ...@@ -112,7 +110,6 @@ struct da9063_regulator {
struct regmap_field *suspend; struct regmap_field *suspend;
struct regmap_field *sleep; struct regmap_field *sleep;
struct regmap_field *suspend_sleep; struct regmap_field *suspend_sleep;
struct regmap_field *ilimit;
}; };
/* Encapsulates all information for the regulators driver */ /* Encapsulates all information for the regulators driver */
...@@ -134,65 +131,32 @@ enum { ...@@ -134,65 +131,32 @@ enum {
/* Current limits array (in uA) for BCORE1, BCORE2, BPRO. /* Current limits array (in uA) for BCORE1, BCORE2, BPRO.
Entry indexes corresponds to register values. */ Entry indexes corresponds to register values. */
static const int da9063_buck_a_limits[] = { static const unsigned int da9063_buck_a_limits[] = {
500000, 600000, 700000, 800000, 900000, 1000000, 1100000, 1200000, 500000, 600000, 700000, 800000, 900000, 1000000, 1100000, 1200000,
1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000
}; };
/* Current limits array (in uA) for BMEM, BIO, BPERI. /* Current limits array (in uA) for BMEM, BIO, BPERI.
Entry indexes corresponds to register values. */ Entry indexes corresponds to register values. */
static const int da9063_buck_b_limits[] = { static const unsigned int da9063_buck_b_limits[] = {
1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000,
2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000 2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000
}; };
/* Current limits array (in uA) for merged BCORE1 and BCORE2. /* Current limits array (in uA) for merged BCORE1 and BCORE2.
Entry indexes corresponds to register values. */ Entry indexes corresponds to register values. */
static const int da9063_bcores_merged_limits[] = { static const unsigned int da9063_bcores_merged_limits[] = {
1000000, 1200000, 1400000, 1600000, 1800000, 2000000, 2200000, 2400000, 1000000, 1200000, 1400000, 1600000, 1800000, 2000000, 2200000, 2400000,
2600000, 2800000, 3000000, 3200000, 3400000, 3600000, 3800000, 4000000 2600000, 2800000, 3000000, 3200000, 3400000, 3600000, 3800000, 4000000
}; };
/* Current limits array (in uA) for merged BMEM and BIO. /* Current limits array (in uA) for merged BMEM and BIO.
Entry indexes corresponds to register values. */ Entry indexes corresponds to register values. */
static const int da9063_bmem_bio_merged_limits[] = { static const unsigned int da9063_bmem_bio_merged_limits[] = {
3000000, 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000, 3000000, 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000,
4600000, 4800000, 5000000, 5200000, 5400000, 5600000, 5800000, 6000000 4600000, 4800000, 5000000, 5200000, 5400000, 5600000, 5800000, 6000000
}; };
static int da9063_set_current_limit(struct regulator_dev *rdev,
int min_uA, int max_uA)
{
struct da9063_regulator *regl = rdev_get_drvdata(rdev);
const struct da9063_regulator_info *rinfo = regl->info;
int n, tval;
for (n = rinfo->n_current_limits - 1; n >= 0; n--) {
tval = rinfo->current_limits[n];
if (tval >= min_uA && tval <= max_uA)
return regmap_field_write(regl->ilimit, n);
}
return -EINVAL;
}
static int da9063_get_current_limit(struct regulator_dev *rdev)
{
struct da9063_regulator *regl = rdev_get_drvdata(rdev);
const struct da9063_regulator_info *rinfo = regl->info;
unsigned int sel;
int ret;
ret = regmap_field_read(regl->ilimit, &sel);
if (ret < 0)
return ret;
if (sel >= rinfo->n_current_limits)
sel = rinfo->n_current_limits - 1;
return rinfo->current_limits[sel];
}
static int da9063_buck_set_mode(struct regulator_dev *rdev, unsigned mode) static int da9063_buck_set_mode(struct regulator_dev *rdev, unsigned mode)
{ {
struct da9063_regulator *regl = rdev_get_drvdata(rdev); struct da9063_regulator *regl = rdev_get_drvdata(rdev);
...@@ -434,8 +398,8 @@ static const struct regulator_ops da9063_buck_ops = { ...@@ -434,8 +398,8 @@ static const struct regulator_ops da9063_buck_ops = {
.get_voltage_sel = regulator_get_voltage_sel_regmap, .get_voltage_sel = regulator_get_voltage_sel_regmap,
.set_voltage_sel = regulator_set_voltage_sel_regmap, .set_voltage_sel = regulator_set_voltage_sel_regmap,
.list_voltage = regulator_list_voltage_linear, .list_voltage = regulator_list_voltage_linear,
.set_current_limit = da9063_set_current_limit, .set_current_limit = regulator_set_current_limit_regmap,
.get_current_limit = da9063_get_current_limit, .get_current_limit = regulator_get_current_limit_regmap,
.set_mode = da9063_buck_set_mode, .set_mode = da9063_buck_set_mode,
.get_mode = da9063_buck_get_mode, .get_mode = da9063_buck_get_mode,
.get_status = da9063_buck_get_status, .get_status = da9063_buck_get_status,
...@@ -465,69 +429,61 @@ static const struct regulator_ops da9063_ldo_ops = { ...@@ -465,69 +429,61 @@ static const struct regulator_ops da9063_ldo_ops = {
static const struct da9063_regulator_info da9063_regulator_info[] = { static const struct da9063_regulator_info da9063_regulator_info[] = {
{ {
DA9063_BUCK(DA9063, BCORE1, 300, 10, 1570, DA9063_BUCK(DA9063, BCORE1, 300, 10, 1570,
da9063_buck_a_limits), da9063_buck_a_limits,
DA9063_REG_BUCK_ILIM_C, DA9063_BCORE1_ILIM_MASK),
DA9063_BUCK_COMMON_FIELDS(BCORE1), DA9063_BUCK_COMMON_FIELDS(BCORE1),
.suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE1_SEL), .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE1_SEL),
.ilimit = BFIELD(DA9063_REG_BUCK_ILIM_C,
DA9063_BCORE1_ILIM_MASK),
}, },
{ {
DA9063_BUCK(DA9063, BCORE2, 300, 10, 1570, DA9063_BUCK(DA9063, BCORE2, 300, 10, 1570,
da9063_buck_a_limits), da9063_buck_a_limits,
DA9063_REG_BUCK_ILIM_C, DA9063_BCORE2_ILIM_MASK),
DA9063_BUCK_COMMON_FIELDS(BCORE2), DA9063_BUCK_COMMON_FIELDS(BCORE2),
.suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE2_SEL), .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE2_SEL),
.ilimit = BFIELD(DA9063_REG_BUCK_ILIM_C,
DA9063_BCORE2_ILIM_MASK),
}, },
{ {
DA9063_BUCK(DA9063, BPRO, 530, 10, 1800, DA9063_BUCK(DA9063, BPRO, 530, 10, 1800,
da9063_buck_a_limits), da9063_buck_a_limits,
DA9063_REG_BUCK_ILIM_B, DA9063_BPRO_ILIM_MASK),
DA9063_BUCK_COMMON_FIELDS(BPRO), DA9063_BUCK_COMMON_FIELDS(BPRO),
.suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBPRO_SEL), .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBPRO_SEL),
.ilimit = BFIELD(DA9063_REG_BUCK_ILIM_B,
DA9063_BPRO_ILIM_MASK),
}, },
{ {
DA9063_BUCK(DA9063, BMEM, 800, 20, 3340, DA9063_BUCK(DA9063, BMEM, 800, 20, 3340,
da9063_buck_b_limits), da9063_buck_b_limits,
DA9063_REG_BUCK_ILIM_A, DA9063_BMEM_ILIM_MASK),
DA9063_BUCK_COMMON_FIELDS(BMEM), DA9063_BUCK_COMMON_FIELDS(BMEM),
.suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBMEM_SEL), .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBMEM_SEL),
.ilimit = BFIELD(DA9063_REG_BUCK_ILIM_A,
DA9063_BMEM_ILIM_MASK),
}, },
{ {
DA9063_BUCK(DA9063, BIO, 800, 20, 3340, DA9063_BUCK(DA9063, BIO, 800, 20, 3340,
da9063_buck_b_limits), da9063_buck_b_limits,
DA9063_REG_BUCK_ILIM_A, DA9063_BIO_ILIM_MASK),
DA9063_BUCK_COMMON_FIELDS(BIO), DA9063_BUCK_COMMON_FIELDS(BIO),
.suspend = BFIELD(DA9063_REG_DVC_2, DA9063_VBIO_SEL), .suspend = BFIELD(DA9063_REG_DVC_2, DA9063_VBIO_SEL),
.ilimit = BFIELD(DA9063_REG_BUCK_ILIM_A,
DA9063_BIO_ILIM_MASK),
}, },
{ {
DA9063_BUCK(DA9063, BPERI, 800, 20, 3340, DA9063_BUCK(DA9063, BPERI, 800, 20, 3340,
da9063_buck_b_limits), da9063_buck_b_limits,
DA9063_REG_BUCK_ILIM_B, DA9063_BPERI_ILIM_MASK),
DA9063_BUCK_COMMON_FIELDS(BPERI), DA9063_BUCK_COMMON_FIELDS(BPERI),
.suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBPERI_SEL), .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBPERI_SEL),
.ilimit = BFIELD(DA9063_REG_BUCK_ILIM_B,
DA9063_BPERI_ILIM_MASK),
}, },
{ {
DA9063_BUCK(DA9063, BCORES_MERGED, 300, 10, 1570, DA9063_BUCK(DA9063, BCORES_MERGED, 300, 10, 1570,
da9063_bcores_merged_limits), da9063_bcores_merged_limits,
DA9063_REG_BUCK_ILIM_C, DA9063_BCORE1_ILIM_MASK),
/* BCORES_MERGED uses the same register fields as BCORE1 */ /* BCORES_MERGED uses the same register fields as BCORE1 */
DA9063_BUCK_COMMON_FIELDS(BCORE1), DA9063_BUCK_COMMON_FIELDS(BCORE1),
.suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE1_SEL), .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE1_SEL),
.ilimit = BFIELD(DA9063_REG_BUCK_ILIM_C,
DA9063_BCORE1_ILIM_MASK),
}, },
{ {
DA9063_BUCK(DA9063, BMEM_BIO_MERGED, 800, 20, 3340, DA9063_BUCK(DA9063, BMEM_BIO_MERGED, 800, 20, 3340,
da9063_bmem_bio_merged_limits), da9063_bmem_bio_merged_limits,
DA9063_REG_BUCK_ILIM_A, DA9063_BMEM_ILIM_MASK),
/* BMEM_BIO_MERGED uses the same register fields as BMEM */ /* BMEM_BIO_MERGED uses the same register fields as BMEM */
DA9063_BUCK_COMMON_FIELDS(BMEM), DA9063_BUCK_COMMON_FIELDS(BMEM),
.suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBMEM_SEL), .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBMEM_SEL),
.ilimit = BFIELD(DA9063_REG_BUCK_ILIM_A,
DA9063_BMEM_ILIM_MASK),
}, },
{ {
DA9063_LDO(DA9063, LDO3, 900, 20, 3440), DA9063_LDO(DA9063, LDO3, 900, 20, 3440),
...@@ -864,13 +820,6 @@ static int da9063_regulator_probe(struct platform_device *pdev) ...@@ -864,13 +820,6 @@ static int da9063_regulator_probe(struct platform_device *pdev)
return PTR_ERR(regl->suspend_sleep); return PTR_ERR(regl->suspend_sleep);
} }
if (regl->info->ilimit.reg) {
regl->ilimit = devm_regmap_field_alloc(&pdev->dev,
da9063->regmap, regl->info->ilimit);
if (IS_ERR(regl->ilimit))
return PTR_ERR(regl->ilimit);
}
/* Register regulator */ /* Register regulator */
memset(&config, 0, sizeof(config)); memset(&config, 0, sizeof(config));
config.dev = &pdev->dev; config.dev = &pdev->dev;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment