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>
This commit is contained in:
Родитель
9eadcc0581
Коммит
310c805e7f
|
@ -1276,6 +1276,40 @@ struct device_node *mmc_of_find_child_device(struct mmc_host *host,
|
||||||
|
|
||||||
#ifdef CONFIG_REGULATOR
|
#ifdef CONFIG_REGULATOR
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mmc_ocrbitnum_to_vdd - Convert a OCR bit number to its voltage
|
||||||
|
* @vdd_bit: OCR bit number
|
||||||
|
* @min_uV: minimum voltage value (mV)
|
||||||
|
* @max_uV: maximum voltage value (mV)
|
||||||
|
*
|
||||||
|
* This function returns the voltage range according to the provided OCR
|
||||||
|
* bit number. If conversion is not possible a negative errno value returned.
|
||||||
|
*/
|
||||||
|
static int mmc_ocrbitnum_to_vdd(int vdd_bit, int *min_uV, int *max_uV)
|
||||||
|
{
|
||||||
|
int tmp;
|
||||||
|
|
||||||
|
if (!vdd_bit)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* REVISIT mmc_vddrange_to_ocrmask() may have set some
|
||||||
|
* bits this regulator doesn't quite support ... don't
|
||||||
|
* be too picky, most cards and regulators are OK with
|
||||||
|
* a 0.1V range goof (it's a small error percentage).
|
||||||
|
*/
|
||||||
|
tmp = vdd_bit - ilog2(MMC_VDD_165_195);
|
||||||
|
if (tmp == 0) {
|
||||||
|
*min_uV = 1650 * 1000;
|
||||||
|
*max_uV = 1950 * 1000;
|
||||||
|
} else {
|
||||||
|
*min_uV = 1900 * 1000 + tmp * 100 * 1000;
|
||||||
|
*max_uV = *min_uV + 100 * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mmc_regulator_get_ocrmask - return mask of supported voltages
|
* mmc_regulator_get_ocrmask - return mask of supported voltages
|
||||||
* @supply: regulator to use
|
* @supply: regulator to use
|
||||||
|
@ -1339,22 +1373,7 @@ int mmc_regulator_set_ocr(struct mmc_host *mmc,
|
||||||
int min_uV, max_uV;
|
int min_uV, max_uV;
|
||||||
|
|
||||||
if (vdd_bit) {
|
if (vdd_bit) {
|
||||||
int tmp;
|
mmc_ocrbitnum_to_vdd(vdd_bit, &min_uV, &max_uV);
|
||||||
|
|
||||||
/*
|
|
||||||
* REVISIT mmc_vddrange_to_ocrmask() may have set some
|
|
||||||
* bits this regulator doesn't quite support ... don't
|
|
||||||
* be too picky, most cards and regulators are OK with
|
|
||||||
* a 0.1V range goof (it's a small error percentage).
|
|
||||||
*/
|
|
||||||
tmp = vdd_bit - ilog2(MMC_VDD_165_195);
|
|
||||||
if (tmp == 0) {
|
|
||||||
min_uV = 1650 * 1000;
|
|
||||||
max_uV = 1950 * 1000;
|
|
||||||
} else {
|
|
||||||
min_uV = 1900 * 1000 + tmp * 100 * 1000;
|
|
||||||
max_uV = min_uV + 100 * 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = regulator_set_voltage(supply, min_uV, max_uV);
|
result = regulator_set_voltage(supply, min_uV, max_uV);
|
||||||
if (result == 0 && !mmc->regulator_enabled) {
|
if (result == 0 && !mmc->regulator_enabled) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче