From c4236282e5921a410e8f074fec795b6ca0af36d5 Mon Sep 17 00:00:00 2001
From: Len Brown <len.brown@intel.com>
Date: Fri, 28 May 2010 02:22:03 -0400
Subject: [PATCH 1/6] intel_idle: delete substates DEBUG modparam

it isn't useful anymore

Signed-off-by: Len Brown <len.brown@intel.com>
---
 drivers/idle/intel_idle.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index 54f0fb4cd5d2..82c9a58b3ab0 100755
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -79,7 +79,7 @@ static struct cpuidle_driver intel_idle_driver = {
 static int max_cstate = MWAIT_MAX_NUM_CSTATES - 1;
 static int power_policy = 7; /* 0 = max perf; 15 = max powersave */
 
-static unsigned int substates;
+static unsigned int mwait_substates;
 static int (*choose_substate)(int);
 
 /* Reliable LAPIC Timer States, bit 1 for C1 etc.  */
@@ -184,7 +184,8 @@ static int choose_tunable_substate(int cstate)
 	power_policy &= 0xF;	/* valid range: 0-15 */
 	cstate &= 7;	/* valid range: 0-7 */
 
-	num_substates = (substates >> ((cstate) * 4)) & MWAIT_SUBSTATE_MASK;
+	num_substates = (mwait_substates >> ((cstate) * 4))
+				& MWAIT_SUBSTATE_MASK;
 
 	if (num_substates <= 1)
 		return 0;
@@ -259,7 +260,7 @@ static int intel_idle(struct cpuidle_device *dev, struct cpuidle_state *state)
  */
 static int intel_idle_probe(void)
 {
-	unsigned int eax, ebx, ecx, edx;
+	unsigned int eax, ebx, ecx;
 
 	if (max_cstate == 0) {
 		pr_debug(PREFIX "disabled\n");
@@ -275,17 +276,13 @@ static int intel_idle_probe(void)
 	if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
 		return -ENODEV;
 
-	cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &edx);
+	cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &mwait_substates);
 
 	if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
 		!(ecx & CPUID5_ECX_INTERRUPT_BREAK))
 			return -ENODEV;
-#ifdef DEBUG
-	if (substates == 0)	/* can over-ride via modparam */
-#endif
-		substates = edx;
 
-	pr_debug(PREFIX "MWAIT substates: 0x%x\n", substates);
+	pr_debug(PREFIX "MWAIT substates: 0x%x\n", mwait_substates);
 
 	if (boot_cpu_has(X86_FEATURE_ARAT))	/* Always Reliable APIC Timer */
 		lapic_timer_reliable_states = 0xFFFFFFFF;
@@ -376,7 +373,7 @@ static int intel_idle_cpuidle_devices_init(void)
 			}
 
 			/* does the state exist in CPUID.MWAIT? */
-			num_substates = (substates >> ((cstate) * 4))
+			num_substates = (mwait_substates >> ((cstate) * 4))
 						& MWAIT_SUBSTATE_MASK;
 			if (num_substates == 0)
 				continue;
@@ -452,9 +449,6 @@ module_exit(intel_idle_exit);
 
 module_param(power_policy, int, 0644);
 module_param(max_cstate, int, 0444);
-#ifdef DEBUG
-module_param(substates, int, 0444);
-#endif
 
 MODULE_AUTHOR("Len Brown <len.brown@intel.com>");
 MODULE_DESCRIPTION("Cpuidle driver for Intel Hardware v" INTEL_IDLE_VERSION);

From 0394c6676e3fa48587fbe4821390d3264672c530 Mon Sep 17 00:00:00 2001
From: Len Brown <len.brown@intel.com>
Date: Fri, 23 Jul 2010 16:04:46 -0400
Subject: [PATCH 2/6] intel_idle: delete power_policy modparam, and choose
 substate functions

The idea behind power policy was that it would start off as a modparam,
and then hook into the new "global" in-kernel power vs energy tunable.
But that tunable isn't happening, so delete the hook here.

With the policy hook gone, the sub-state choice functions
do not do anything useful, so delete them from the critical path.

To handle sub-states in the future, we will advertise them
with dedicated cpuidle_state entries.  That is necessary
because some of the sub-states will have substantially different
properties than their peer sub-states.

Signed-off-by: Len Brown <len.brown@intel.com>
---
 drivers/idle/intel_idle.c | 43 ---------------------------------------
 1 file changed, 43 deletions(-)

diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index 82c9a58b3ab0..6d43bc3b9e4f 100755
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -77,10 +77,8 @@ static struct cpuidle_driver intel_idle_driver = {
 };
 /* intel_idle.max_cstate=0 disables driver */
 static int max_cstate = MWAIT_MAX_NUM_CSTATES - 1;
-static int power_policy = 7; /* 0 = max perf; 15 = max powersave */
 
 static unsigned int mwait_substates;
-static int (*choose_substate)(int);
 
 /* Reliable LAPIC Timer States, bit 1 for C1 etc.  */
 static unsigned int lapic_timer_reliable_states;
@@ -168,42 +166,6 @@ static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
 		.enter = NULL },	/* disabled */
 };
 
-/*
- * choose_tunable_substate()
- *
- * Run-time decision on which C-state substate to invoke
- * If power_policy = 0, choose shallowest substate (0)
- * If power_policy = 15, choose deepest substate
- * If power_policy = middle, choose middle substate etc.
- */
-static int choose_tunable_substate(int cstate)
-{
-	unsigned int num_substates;
-	unsigned int substate_choice;
-
-	power_policy &= 0xF;	/* valid range: 0-15 */
-	cstate &= 7;	/* valid range: 0-7 */
-
-	num_substates = (mwait_substates >> ((cstate) * 4))
-				& MWAIT_SUBSTATE_MASK;
-
-	if (num_substates <= 1)
-		return 0;
-
-	substate_choice = ((power_policy + (power_policy + 1) *
-				(num_substates - 1)) / 16);
-
-	return substate_choice;
-}
-
-/*
- * choose_zero_substate()
- */
-static int choose_zero_substate(int cstate)
-{
-	return 0;
-}
-
 /**
  * intel_idle
  * @dev: cpuidle_device
@@ -221,8 +183,6 @@ static int intel_idle(struct cpuidle_device *dev, struct cpuidle_state *state)
 
 	cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) & MWAIT_CSTATE_MASK) + 1;
 
-	eax = eax + (choose_substate)(cstate);
-
 	local_irq_disable();
 
 	if (!(lapic_timer_reliable_states & (1 << (cstate))))
@@ -301,13 +261,11 @@ static int intel_idle_probe(void)
 	case 0x25:	/* Westmere */
 	case 0x2C:	/* Westmere */
 		cpuidle_state_table = nehalem_cstates;
-		choose_substate = choose_tunable_substate;
 		break;
 
 	case 0x1C:	/* 28 - Atom Processor */
 		lapic_timer_reliable_states = (1 << 2) | (1 << 1); /* C2, C1 */
 		cpuidle_state_table = atom_cstates;
-		choose_substate = choose_zero_substate;
 		break;
 #ifdef FUTURE_USE
 	case 0x17:	/* 23 - Core 2 Duo */
@@ -447,7 +405,6 @@ static void __exit intel_idle_exit(void)
 module_init(intel_idle_init);
 module_exit(intel_idle_exit);
 
-module_param(power_policy, int, 0644);
 module_param(max_cstate, int, 0444);
 
 MODULE_AUTHOR("Len Brown <len.brown@intel.com>");

From ec67a2ba360d4874b1158e6e87fe1e859b0c9117 Mon Sep 17 00:00:00 2001
From: Len Brown <len.brown@intel.com>
Date: Mon, 26 Jul 2010 23:40:19 -0400
Subject: [PATCH 3/6] intel_idle: add support for Westmere-EX

Signed-off-by: Len Brown <len.brown@intel.com>
---
 drivers/idle/intel_idle.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index 6d43bc3b9e4f..97655ed8a989 100755
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -256,6 +256,7 @@ static int intel_idle_probe(void)
 	case 0x1E:	/* Core i7 and i5 Processor - Lynnfield Jasper Forest */
 	case 0x1F:	/* Core i7 and i5 Processor - Nehalem */
 	case 0x2E:	/* Nehalem-EX Xeon */
+	case 0x2F:	/* Westmere-EX Xeon */
 		lapic_timer_reliable_states = (1 << 1);	 /* C1 */
 
 	case 0x25:	/* Westmere */

From 6ce9cd8669fa1195fdc21643370e34523c7ac988 Mon Sep 17 00:00:00 2001
From: Len Brown <len.brown@intel.com>
Date: Sat, 14 Aug 2010 14:40:36 -0400
Subject: [PATCH 4/6] intel_idle: disable module support

Right now the module capability is cauing more trouble
than it is worth.  At least one distro built intel_idle as a module
where it lost the init race with ACPI, making it useless.

Make intel_idle bool so that if you select it, you will use it.

We can restore module capability after cpuidle is enhanced
to handle run-time changing of idle drivers.

Signed-off-by: Len Brown <len.brown@intel.com>
---
 drivers/idle/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/idle/Kconfig b/drivers/idle/Kconfig
index fb5c5186d4aa..82e4e8650f7b 100644
--- a/drivers/idle/Kconfig
+++ b/drivers/idle/Kconfig
@@ -1,5 +1,5 @@
 config INTEL_IDLE
-	tristate "Cpuidle Driver for Intel Processors"
+	bool "Cpuidle Driver for Intel Processors"
 	depends on CPU_IDLE
 	depends on X86
 	depends on CPU_SUP_INTEL

From 5a5e28daea69652505ac07eb5fbda4d7f0534926 Mon Sep 17 00:00:00 2001
From: Len Brown <len.brown@intel.com>
Date: Sat, 14 Aug 2010 14:44:08 -0400
Subject: [PATCH 5/6] intel_idle: no longer EXPERIMENTAL

This is a fully supported driver.

Signed-off-by: Len Brown <len.brown@intel.com>
---
 drivers/idle/Kconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/idle/Kconfig b/drivers/idle/Kconfig
index 82e4e8650f7b..8489eb58a52c 100644
--- a/drivers/idle/Kconfig
+++ b/drivers/idle/Kconfig
@@ -3,7 +3,6 @@ config INTEL_IDLE
 	depends on CPU_IDLE
 	depends on X86
 	depends on CPU_SUP_INTEL
-	depends on EXPERIMENTAL
 	help
 	  Enable intel_idle, a cpuidle driver that includes knowledge of
 	  native Intel hardware idle features.  The acpi_idle driver

From 4725fd3ce970c27a1678fb0809bfc7c2f4ac3e4f Mon Sep 17 00:00:00 2001
From: Arjan van de Ven <arjan@linux.intel.com>
Date: Wed, 21 Jul 2010 23:42:25 -0400
Subject: [PATCH 6/6] intel_idle: recognize Lincroft Atom Processor

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
---
 drivers/idle/intel_idle.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index 97655ed8a989..b1909fb066ef 100755
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -265,6 +265,7 @@ static int intel_idle_probe(void)
 		break;
 
 	case 0x1C:	/* 28 - Atom Processor */
+	case 0x26:	/* 38 - Lincroft Atom Processor */
 		lapic_timer_reliable_states = (1 << 2) | (1 << 1); /* C2, C1 */
 		cpuidle_state_table = atom_cstates;
 		break;