X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=drivers%2Fregulator%2Fab3100.c;h=03f4d9c604ec19717abfb2d57f64b8c49c6e42af;hb=2c01e7bc46f10e9190818437e564f7e0db875ae9;hp=042271aace6a65b8a2f40cdc3be75934ae081ff4;hpb=51be08419dc86c72486ac556aa39bc01026a403d;p=~andy%2Flinux diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c index 042271aace6..03f4d9c604e 100644 --- a/drivers/regulator/ab3100.c +++ b/drivers/regulator/ab3100.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -305,53 +304,12 @@ static int ab3100_get_voltage_regulator(struct regulator_dev *reg) return abreg->typ_voltages[regval]; } -static int ab3100_get_best_voltage_index(struct regulator_dev *reg, - int min_uV, int max_uV) -{ - struct ab3100_regulator *abreg = reg->reg_data; - int i; - int bestmatch; - int bestindex; - - /* - * Locate the minimum voltage fitting the criteria on - * this regulator. The switchable voltages are not - * in strict falling order so we need to check them - * all for the best match. - */ - bestmatch = INT_MAX; - bestindex = -1; - for (i = 0; i < abreg->voltages_len; i++) { - if (abreg->typ_voltages[i] <= max_uV && - abreg->typ_voltages[i] >= min_uV && - abreg->typ_voltages[i] < bestmatch) { - bestmatch = abreg->typ_voltages[i]; - bestindex = i; - } - } - - if (bestindex < 0) { - dev_warn(®->dev, "requested %d<=x<=%d uV, out of range!\n", - min_uV, max_uV); - return -EINVAL; - } - return bestindex; -} - -static int ab3100_set_voltage_regulator(struct regulator_dev *reg, - int min_uV, int max_uV, - unsigned *selector) +static int ab3100_set_voltage_regulator_sel(struct regulator_dev *reg, + unsigned selector) { struct ab3100_regulator *abreg = reg->reg_data; u8 regval; int err; - int bestindex; - - bestindex = ab3100_get_best_voltage_index(reg, min_uV, max_uV); - if (bestindex < 0) - return bestindex; - - *selector = bestindex; err = abx500_get_register_interruptible(abreg->dev, 0, abreg->regreg, ®val); @@ -364,7 +322,7 @@ static int ab3100_set_voltage_regulator(struct regulator_dev *reg, /* The highest three bits control the variable regulators */ regval &= ~0xE0; - regval |= (bestindex << 5); + regval |= (selector << 5); err = abx500_set_register_interruptible(abreg->dev, 0, abreg->regreg, regval); @@ -392,7 +350,7 @@ static int ab3100_set_suspend_voltage_regulator(struct regulator_dev *reg, return -EINVAL; /* LDO E and BUCK have special suspend voltages you can set */ - bestindex = ab3100_get_best_voltage_index(reg, uV, uV); + bestindex = regulator_map_voltage_iterate(reg, uV, uV); err = abx500_get_register_interruptible(abreg->dev, 0, targetreg, ®val); @@ -464,7 +422,7 @@ static struct regulator_ops regulator_ops_variable = { .disable = ab3100_disable_regulator, .is_enabled = ab3100_is_enabled_regulator, .get_voltage = ab3100_get_voltage_regulator, - .set_voltage = ab3100_set_voltage_regulator, + .set_voltage_sel = ab3100_set_voltage_regulator_sel, .list_voltage = ab3100_list_voltage_regulator, .enable_time = ab3100_enable_time_regulator, }; @@ -474,7 +432,7 @@ static struct regulator_ops regulator_ops_variable_sleepable = { .disable = ab3100_disable_regulator, .is_enabled = ab3100_is_enabled_regulator, .get_voltage = ab3100_get_voltage_regulator, - .set_voltage = ab3100_set_voltage_regulator, + .set_voltage_sel = ab3100_set_voltage_regulator_sel, .set_suspend_voltage = ab3100_set_suspend_voltage_regulator, .list_voltage = ab3100_list_voltage_regulator, .enable_time = ab3100_enable_time_regulator, @@ -582,6 +540,7 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = { static int __devinit ab3100_regulators_probe(struct platform_device *pdev) { struct ab3100_platform_data *plfdata = pdev->dev.platform_data; + struct regulator_config config = { }; int err = 0; u8 data; int i; @@ -627,15 +586,15 @@ static int __devinit ab3100_regulators_probe(struct platform_device *pdev) reg->dev = &pdev->dev; reg->plfdata = plfdata; + config.dev = &pdev->dev; + config.driver_data = reg; + config.init_data = &plfdata->reg_constraints[i]; + /* * Register the regulator, pass around * the ab3100_regulator struct */ - rdev = regulator_register(&ab3100_regulator_desc[i], - &pdev->dev, - &plfdata->reg_constraints[i], - reg, NULL); - + rdev = regulator_register(&ab3100_regulator_desc[i], &config); if (IS_ERR(rdev)) { err = PTR_ERR(rdev); dev_err(&pdev->dev,