msm: krait-regulator: turn off mdd when ldo is not used

The MDD (master droop detector) unit consumes around 300uA per core.
It is required only when the LDO is being used by the cpu. It can
be safely turned off while in BHS mode. This will save upto 1.2mA
of rock bottom current.

Note that if the cpu is entering retention mode, we turn on the MDD
so the spm can turn on LDO safely when retention is activated. Since
we have to call a out of band api to turn on/off MDD for a given core
associate a cpu number with a krait regulator node. This helps us to get
the necessary data structure quickly and access that core's registers
to turn its MDD on/off.

Change-Id: I03ab80bd979bef05c6c3d39f43788e6ec9f02510
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
diff --git a/include/linux/regulator/krait-regulator.h b/include/linux/regulator/krait-regulator.h
index 2d49046..836f9d6 100644
--- a/include/linux/regulator/krait-regulator.h
+++ b/include/linux/regulator/krait-regulator.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2012-2013, The Linux Foundation. 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
@@ -26,6 +26,22 @@
 #ifdef CONFIG_ARCH_MSM8974
 int __init krait_power_init(void);
 void secondary_cpu_hs_init(void *base_ptr);
+
+/**
+ * krait_power_mdd_enable - function to turn on/off MDD. Turning off MDD
+ *				turns off badngap reference for LDO. If
+ *				a core is running on a LDO, requests to
+ *				turn off MDD will not be honoured
+ * @on:	boolean to indicate whether to turn MDD on/off
+ *
+ * CONTEXT: Can be called in interrupt context, only when the core
+ *		is about to go to idle, this guarantees that there are no
+ *		frequency changes on that cpu happening. Note if going from off
+ *		to on mode there will be settling delays
+ *
+ * RETURNS: -EINVAL if MDD cannot be turned off
+ */
+int krait_power_mdd_enable(int cpu_num, bool on);
 #else
 static inline int __init krait_power_init(void)
 {
@@ -33,6 +49,10 @@
 }
 
 static inline void secondary_cpu_hs_init(void *base_ptr) {}
+static inline int krait_power_mdd_enable(int cpu_num, bool on)
+{
+	return -EINVAL;
+}
 #endif
 
 #endif