msm: board-msm7x27a-regulator: Add voltage selector for a regulator

Each regulator in PMIC support a range of voltage over which
it can be operated. This voltage range is changed in certain
minimum voltage step and these steps provide the voltage selector
points for a particular regulator. This range is used by
regulator_count_voltages() function.

Change-Id: I958170f35779eb3d84faad6502c3e2f14b1cafb6
Signed-off-by: Pankaj Kumar <pakuma@codeaurora.org>
diff --git a/arch/arm/mach-msm/board-msm7x27a-regulator.c b/arch/arm/mach-msm/board-msm7x27a-regulator.c
index 1a3bb75..56ead81 100644
--- a/arch/arm/mach-msm/board-msm7x27a-regulator.c
+++ b/arch/arm/mach-msm/board-msm7x27a-regulator.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+ * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 and
@@ -13,6 +13,16 @@
 
 #include "board-msm7x27a-regulator.h"
 
+#define VOLTAGE_RANGE(min_uV, max_uV, step_uV)	((max_uV - min_uV) / step_uV)
+
+/* Physically available PMIC regulator voltage setpoint ranges */
+#define p_ranges VOLTAGE_RANGE(1500000, 3300000, 25000)
+
+#define n_ranges VOLTAGE_RANGE(750000, 1525000, 12500)
+
+#define s_ranges (VOLTAGE_RANGE(700000, 1500000, 12500) + \
+			VOLTAGE_RANGE(1500000, 3050000, 25000))
+
 #define PCOM_VREG_CONSUMERS(name) \
 	static struct regulator_consumer_supply __pcom_vreg_supply_##name[]
 
@@ -37,7 +47,7 @@
 }
 
 #define PCOM_VREG_SMP(_name, _id, _supply, _min_uV, _max_uV, _rise_time, \
-		_pulldown, _always_on, _boot_on, _apply_uV, _supply_uV) \
+	_pulldown, _always_on, _boot_on, _apply_uV, _supply_uV, _range) \
 { \
 	.init_data = PCOM_VREG_INIT_DATA(_name, _supply, _min_uV, _max_uV, \
 			_always_on, _boot_on, _apply_uV, _supply_uV), \
@@ -45,6 +55,7 @@
 	.rise_time = _rise_time, \
 	.pulldown = _pulldown, \
 	.negative = 0, \
+	.n_voltages = _range##_ranges, \
 }
 
 #define PCOM_VREG_LDO PCOM_VREG_SMP
@@ -196,30 +207,31 @@
 	 * B = boot on
 	 * V = automatic voltage set (meaningful for single-voltage regs only)
 	 * S = supply voltage (uV)
-	 *             name  id  supp    min uV    max uV  R   P  A  B  V  S */
-	PCOM_VREG_SMP(smps1,  3, NULL,  1100000,  1100000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_SMP(smps2,  4, NULL,  1100000,  1100000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_SMP(smps3,  2, NULL,  1800000,  1800000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_SMP(smps4, 24, NULL,  2100000,  2100000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo01, 12, NULL,  2100000,  2100000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo02, 13, NULL,  2850000,  2850000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo03, 49, NULL,  1200000,  1200000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo04, 50, NULL,  1100000,  1100000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo05, 45, NULL,  1300000,  1350000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo06, 51, NULL,  1200000,  1200000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo07,  0, NULL,  2600000,  2600000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo08,  9, NULL,  2850000,  2850000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo09, 44, NULL,  1800000,  1800000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo10, 52, NULL,  1800000,  3000000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo11, 53, NULL,  1800000,  1800000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo12, 21, NULL,  2850000,  2850000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo13, 18, NULL,  2850000,  2850000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo14, 16, NULL,  3300000,  3300000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo15, 54, NULL,  1800000,  2850000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo16, 19, NULL,  1800000,  2850000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo17, 56, NULL,  2900000,  3300000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo18, 11, NULL,  2700000,  2700000, 0, -1, 0, 0, 0, 0),
-	PCOM_VREG_LDO(ldo19, 57, NULL,  1200000,  1800000, 0, -1, 0, 0, 0, 0),
+	 * T = type of regulator (smps, pldo, nldo)
+	 *            name   id  supp  min uV    max uV  R   P  A  B  V  S  T*/
+	PCOM_VREG_SMP(smps1,  3, NULL, 1100000, 1100000, 0, -1, 0, 0, 0, 0, s),
+	PCOM_VREG_SMP(smps2,  4, NULL, 1100000, 1100000, 0, -1, 0, 0, 0, 0, s),
+	PCOM_VREG_SMP(smps3,  2, NULL, 1800000, 1800000, 0, -1, 0, 0, 0, 0, s),
+	PCOM_VREG_SMP(smps4, 24, NULL, 2100000, 2100000, 0, -1, 0, 0, 0, 0, s),
+	PCOM_VREG_LDO(ldo01, 12, NULL, 2100000, 2100000, 0, -1, 0, 0, 0, 0, p),
+	PCOM_VREG_LDO(ldo02, 13, NULL, 2850000, 2850000, 0, -1, 0, 0, 0, 0, p),
+	PCOM_VREG_LDO(ldo03, 49, NULL, 1200000, 1200000, 0, -1, 0, 0, 0, 0, n),
+	PCOM_VREG_LDO(ldo04, 50, NULL, 1100000, 1100000, 0, -1, 0, 0, 0, 0, n),
+	PCOM_VREG_LDO(ldo05, 45, NULL, 1300000, 1350000, 0, -1, 0, 0, 0, 0, n),
+	PCOM_VREG_LDO(ldo06, 51, NULL, 1200000, 1200000, 0, -1, 0, 0, 0, 0, n),
+	PCOM_VREG_LDO(ldo07,  0, NULL, 2600000, 2600000, 0, -1, 0, 0, 0, 0, p),
+	PCOM_VREG_LDO(ldo08,  9, NULL, 2850000, 2850000, 0, -1, 0, 0, 0, 0, p),
+	PCOM_VREG_LDO(ldo09, 44, NULL, 1800000, 1800000, 0, -1, 0, 0, 0, 0, p),
+	PCOM_VREG_LDO(ldo10, 52, NULL, 1800000, 3000000, 0, -1, 0, 0, 0, 0, p),
+	PCOM_VREG_LDO(ldo11, 53, NULL, 1800000, 1800000, 0, -1, 0, 0, 0, 0, p),
+	PCOM_VREG_LDO(ldo12, 21, NULL, 2850000, 2850000, 0, -1, 0, 0, 0, 0, p),
+	PCOM_VREG_LDO(ldo13, 18, NULL, 2850000, 2850000, 0, -1, 0, 0, 0, 0, p),
+	PCOM_VREG_LDO(ldo14, 16, NULL, 3300000, 3300000, 0, -1, 0, 0, 0, 0, p),
+	PCOM_VREG_LDO(ldo15, 54, NULL, 1800000, 2850000, 0, -1, 0, 0, 0, 0, p),
+	PCOM_VREG_LDO(ldo16, 19, NULL, 1800000, 2850000, 0, -1, 0, 0, 0, 0, p),
+	PCOM_VREG_LDO(ldo17, 56, NULL, 2900000, 3300000, 0, -1, 0, 0, 0, 0, p),
+	PCOM_VREG_LDO(ldo18, 11, NULL, 2700000, 2700000, 0, -1, 0, 0, 0, 0, p),
+	PCOM_VREG_LDO(ldo19, 57, NULL, 1200000, 1800000, 0, -1, 0, 0, 0, 0, p),
 
 	PCOM_VREG_NCP(ncp,   31, NULL, -1800000, -1800000, 0,     0, 0, 0, 0),
 };
diff --git a/arch/arm/mach-msm/proccomm-regulator.c b/arch/arm/mach-msm/proccomm-regulator.c
index e5b093f..ba10d38 100644
--- a/arch/arm/mach-msm/proccomm-regulator.c
+++ b/arch/arm/mach-msm/proccomm-regulator.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+ * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 and
@@ -245,6 +245,7 @@
 	d->rise_time	= info->rise_time;
 	d->enabled	= 0;
 	d->negative	= info->negative;
+	d->rdesc.n_voltages = info->n_voltages;
 
 	rdev = regulator_register(&d->rdesc, parent, &info->init_data, d);
 
diff --git a/arch/arm/mach-msm/proccomm-regulator.h b/arch/arm/mach-msm/proccomm-regulator.h
index 2eb4f79..46d3b13 100644
--- a/arch/arm/mach-msm/proccomm-regulator.h
+++ b/arch/arm/mach-msm/proccomm-regulator.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+ * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 and
@@ -48,6 +48,7 @@
 	int				rise_time;
 	int				pulldown;
 	int				negative;
+	int				n_voltages;
 };
 
 /**