diff mbox

[v3,1/7] mmc: core: move ocr-bit to voltage translation into separate function

Message ID 1444654110-32293-2-git-send-email-heiko@sntech.de (mailing list archive)
State New, archived
Headers show

Commit Message

Heiko Stuebner Oct. 12, 2015, 12:48 p.m. UTC
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>
---
 drivers/mmc/core/core.c | 51 +++++++++++++++++++++++++++++++++----------------
 1 file changed, 35 insertions(+), 16 deletions(-)

Comments

kernel test robot Oct. 12, 2015, 1:26 p.m. UTC | #1
Hi Heiko,

[auto build test WARNING on rockchip/for-next -- if it's inappropriate base, please suggest rules for selecting the more suitable base]

url:    https://github.com/0day-ci/linux/commits/Heiko-Stuebner/mmc-dw_mmc-rockchip-allow-tuning-using-the-clk-phase-api/20151012-205613
config: x86_64-randconfig-x011-10121751 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

>> drivers/mmc/core/core.c:1277:12: warning: 'mmc_ocrbitnum_to_vdd' defined but not used [-Wunused-function]
    static int mmc_ocrbitnum_to_vdd(int vdd_bit, int *min_uV, int *max_uV)
               ^

vim +/mmc_ocrbitnum_to_vdd +1277 drivers/mmc/core/core.c

  1261		while (vdd_max >= vdd_min)
  1262			mask |= 1 << vdd_max--;
  1263	
  1264		return mask;
  1265	}
  1266	EXPORT_SYMBOL(mmc_vddrange_to_ocrmask);
  1267	
  1268	/**
  1269	 * mmc_ocrbitnum_to_vdd - Convert a OCR bit number to its voltage
  1270	 * @vdd_bit:	OCR bit number
  1271	 * @min_uV:	minimum voltage value (mV)
  1272	 * @max_uV:	maximum voltage value (mV)
  1273	 *
  1274	 * This function returns the voltage range according to the provided OCR
  1275	 * bit number. If conversion is not possible a negative errno value returned.
  1276	 */
> 1277	static int mmc_ocrbitnum_to_vdd(int vdd_bit, int *min_uV, int *max_uV)
  1278	{
  1279		int		tmp;
  1280	
  1281		if (!vdd_bit)
  1282			return -EINVAL;
  1283	
  1284		/*
  1285		 * REVISIT mmc_vddrange_to_ocrmask() may have set some

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Heiko Stuebner Oct. 12, 2015, 1:44 p.m. UTC | #2
Hi,

Am Montag, 12. Oktober 2015, 21:26:04 schrieb kbuild test robot:
> [auto build test WARNING on rockchip/for-next -- if it's inappropriate base,
> please suggest rules for selecting the more suitable base]
> 
> url:   
> https://github.com/0day-ci/linux/commits/Heiko-Stuebner/mmc-dw_mmc-rockchip
> -allow-tuning-using-the-clk-phase-api/20151012-205613 config:
> x86_64-randconfig-x011-10121751 (attached as .config)
> reproduce:
>         # save the attached .config to linux build tree
>         make ARCH=x86_64
> 
> All warnings (new ones prefixed by >>):
> >> drivers/mmc/core/core.c:1277:12: warning: 'mmc_ocrbitnum_to_vdd' defined
> >> but not used [-Wunused-function]
>     static int mmc_ocrbitnum_to_vdd(int vdd_bit, int *min_uV, int *max_uV)
>                ^

I'm not 100% sure I understand that warning. Is it just because we're ignoring 
the return value in the current first user of the function? [Which is done, 
because we already tested for the vdd_bit != 0 just before invoking 
mmc_ocrbitnum_to_vdd .

The second user added in the following patch then checks the return value. So 
I guess this should stay as it is? I guess Ulf's call - maybe he wants it 
differently anyway ;-) .


Heiko
diff mbox

Patch

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 0520064..548b5e1 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -1265,6 +1265,40 @@  u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max)
 }
 EXPORT_SYMBOL(mmc_vddrange_to_ocrmask);
 
+/**
+ * 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;
+}
+
 #ifdef CONFIG_OF
 
 /**
@@ -1401,22 +1435,7 @@  int mmc_regulator_set_ocr(struct mmc_host *mmc,
 	int			min_uV, max_uV;
 
 	if (vdd_bit) {
-		int		tmp;
-
-		/*
-		 * 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;
-		}
+		mmc_ocrbitnum_to_vdd(vdd_bit, &min_uV, &max_uV);
 
 		result = regulator_set_voltage(supply, min_uV, max_uV);
 		if (result == 0 && !mmc->regulator_enabled) {