diff options
author | Heiko Stuebner <heiko@sntech.de> | 2015-10-12 12:00:54 -0400 |
---|---|---|
committer | Ulf Hansson <ulf.hansson@linaro.org> | 2015-10-26 11:00:10 -0400 |
commit | 310c805e7f133443cd57f880b73557a4a8f54b30 (patch) | |
tree | 5e3986460913c23d5185bbeceabb38275fe1cc1a /drivers/mmc | |
parent | 9eadcc0581a8ccaf4c2378aa1c193fb164304f1d (diff) |
mmc: core: move ocr-bit to voltage translation into separate function
We will shortly need the calculation of an ocr-bit to the actual
voltage in a second place too, so move it from mmc_regulator_set_ocr
to a common function mmc_ocrbitnum_to_vdd to make that possible.
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Diffstat (limited to 'drivers/mmc')
-rw-r--r-- | drivers/mmc/core/core.c | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 1a36b021b44e..7aa3b305b65d 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c | |||
@@ -1277,6 +1277,40 @@ struct device_node *mmc_of_find_child_device(struct mmc_host *host, | |||
1277 | #ifdef CONFIG_REGULATOR | 1277 | #ifdef CONFIG_REGULATOR |
1278 | 1278 | ||
1279 | /** | 1279 | /** |
1280 | * mmc_ocrbitnum_to_vdd - Convert a OCR bit number to its voltage | ||
1281 | * @vdd_bit: OCR bit number | ||
1282 | * @min_uV: minimum voltage value (mV) | ||
1283 | * @max_uV: maximum voltage value (mV) | ||
1284 | * | ||
1285 | * This function returns the voltage range according to the provided OCR | ||
1286 | * bit number. If conversion is not possible a negative errno value returned. | ||
1287 | */ | ||
1288 | static int mmc_ocrbitnum_to_vdd(int vdd_bit, int *min_uV, int *max_uV) | ||
1289 | { | ||
1290 | int tmp; | ||
1291 | |||
1292 | if (!vdd_bit) | ||
1293 | return -EINVAL; | ||
1294 | |||
1295 | /* | ||
1296 | * REVISIT mmc_vddrange_to_ocrmask() may have set some | ||
1297 | * bits this regulator doesn't quite support ... don't | ||
1298 | * be too picky, most cards and regulators are OK with | ||
1299 | * a 0.1V range goof (it's a small error percentage). | ||
1300 | */ | ||
1301 | tmp = vdd_bit - ilog2(MMC_VDD_165_195); | ||
1302 | if (tmp == 0) { | ||
1303 | *min_uV = 1650 * 1000; | ||
1304 | *max_uV = 1950 * 1000; | ||
1305 | } else { | ||
1306 | *min_uV = 1900 * 1000 + tmp * 100 * 1000; | ||
1307 | *max_uV = *min_uV + 100 * 1000; | ||
1308 | } | ||
1309 | |||
1310 | return 0; | ||
1311 | } | ||
1312 | |||
1313 | /** | ||
1280 | * mmc_regulator_get_ocrmask - return mask of supported voltages | 1314 | * mmc_regulator_get_ocrmask - return mask of supported voltages |
1281 | * @supply: regulator to use | 1315 | * @supply: regulator to use |
1282 | * | 1316 | * |
@@ -1339,22 +1373,7 @@ int mmc_regulator_set_ocr(struct mmc_host *mmc, | |||
1339 | int min_uV, max_uV; | 1373 | int min_uV, max_uV; |
1340 | 1374 | ||
1341 | if (vdd_bit) { | 1375 | if (vdd_bit) { |
1342 | int tmp; | 1376 | mmc_ocrbitnum_to_vdd(vdd_bit, &min_uV, &max_uV); |
1343 | |||
1344 | /* | ||
1345 | * REVISIT mmc_vddrange_to_ocrmask() may have set some | ||
1346 | * bits this regulator doesn't quite support ... don't | ||
1347 | * be too picky, most cards and regulators are OK with | ||
1348 | * a 0.1V range goof (it's a small error percentage). | ||
1349 | */ | ||
1350 | tmp = vdd_bit - ilog2(MMC_VDD_165_195); | ||
1351 | if (tmp == 0) { | ||
1352 | min_uV = 1650 * 1000; | ||
1353 | max_uV = 1950 * 1000; | ||
1354 | } else { | ||
1355 | min_uV = 1900 * 1000 + tmp * 100 * 1000; | ||
1356 | max_uV = min_uV + 100 * 1000; | ||
1357 | } | ||
1358 | 1377 | ||
1359 | result = regulator_set_voltage(supply, min_uV, max_uV); | 1378 | result = regulator_set_voltage(supply, min_uV, max_uV); |
1360 | if (result == 0 && !mmc->regulator_enabled) { | 1379 | if (result == 0 && !mmc->regulator_enabled) { |