linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/9] PM: Create the AVS class of drivers
@ 2012-03-19 16:12 jean.pihet
  2012-03-19 16:12 ` [PATCH 1/9] ARM: OMAP3+: voltage: export functions to plat/voltage.h jean.pihet
                   ` (12 more replies)
  0 siblings, 13 replies; 31+ messages in thread
From: jean.pihet @ 2012-03-19 16:12 UTC (permalink / raw)
  To: linux-omap, linux-arm-kernel, Kevin Hilman, Rafael J. Wysocki, LKML
  Cc: Jean Pihet

From: Jean Pihet <j-pihet@ti.com>

AVS is a power management technique which controls the operating
voltage of a device in order to optimize (i.e. reduce) its power
consumption. The voltage is adapted depending on static factors
(chip manufacturing process) and dynamic factors (temperature
depending performance).
AVS is also called SmartReflex on OMAP devices.

To that end, create the AVS framework in drivers/power/avs and
move the OMAP SmartReflex code to the new directory.

In preparation to the move of the OMAP code the following changes have been
made:
- split the include files into generic and platform specific code,
- fill in platform data from the device initialization code and pass
  it to the driver,
- create CONFIG_AVS* config options accordingly.

The platform integration data for SmartReflex is passed from hwmod
and the voltage layer to the driver using pdata.


Tested on OMAP3 Beagleboard using omap2plus_defconfig with the
CONFIG_POWER_AVS* options set.
Based on master branch of the l-o git tree (3.3.0-rc6) [1], commit
85244e0edd240da2004bb2ab7cbcbc67a336f20d.

[1] git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap.git


History:
v2: rework after the comments on MLs
 . Keep the OMAP Kconfig options in the arch dir (Rafael),
 . Move the shared header file from plat-omap to
    include/linux/power/ (Tony)

v1: initial revision
 

Jean Pihet (9):
  ARM: OMAP3+: voltage: export functions to plat/voltage.h
  ARM: OMAP2+: SmartReflex: move the driver specific macros in
    include/linux/power
  ARM: OMAP3+: SmartReflex: class drivers should use struct omap_sr *
  ARM: OMAP2+: smartreflex: Use the names from hwmod data instead of
    voltage domains.
  ARM: OMAP3: hwmod: rename the smartreflex entries
  ARM: OMAP2+: SmartReflex: introduce a busy loop condition test macro
  ARM: OMAP2+: SmartReflex: Use per-OPP data structure
  ARM: OMAP2+: SmartReflex: add POWER_AVS Kconfig options
  ARM: OMAP: SmartReflex: Move smartreflex driver to drivers/

 arch/arm/mach-omap2/Makefile               |    4 +-
 arch/arm/mach-omap2/omap_hwmod_3xxx_data.c |   12 +-
 arch/arm/mach-omap2/omap_hwmod_44xx_data.c |    3 +-
 arch/arm/mach-omap2/pm.h                   |    2 +-
 arch/arm/mach-omap2/smartreflex-class3.c   |   60 --
 arch/arm/mach-omap2/smartreflex.c          | 1165 ----------------------------
 arch/arm/mach-omap2/smartreflex.h          |  256 ------
 arch/arm/mach-omap2/sr_device.c            |   38 +-
 arch/arm/mach-omap2/voltage.h              |    1 -
 arch/arm/mach-omap2/vp.h                   |    2 -
 arch/arm/plat-omap/Kconfig                 |   30 +-
 arch/arm/plat-omap/include/plat/voltage.h  |    3 +
 drivers/power/Kconfig                      |    2 +
 drivers/power/Makefile                     |    2 +
 drivers/power/avs/Kconfig                  |   12 +
 drivers/power/avs/Makefile                 |    2 +
 drivers/power/avs/smartreflex-class3.c     |   61 ++
 drivers/power/avs/smartreflex.c            | 1118 ++++++++++++++++++++++++++
 drivers/power/avs/smartreflex.h            |  238 ++++++
 include/linux/power/smartreflex.h          |   97 +++
 20 files changed, 1590 insertions(+), 1518 deletions(-)
 delete mode 100644 arch/arm/mach-omap2/smartreflex-class3.c
 delete mode 100644 arch/arm/mach-omap2/smartreflex.c
 delete mode 100644 arch/arm/mach-omap2/smartreflex.h
 create mode 100644 drivers/power/avs/Kconfig
 create mode 100644 drivers/power/avs/Makefile
 create mode 100644 drivers/power/avs/smartreflex-class3.c
 create mode 100644 drivers/power/avs/smartreflex.c
 create mode 100644 drivers/power/avs/smartreflex.h
 create mode 100644 include/linux/power/smartreflex.h

-- 
1.7.5.4


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH 1/9] ARM: OMAP3+: voltage: export functions to plat/voltage.h
  2012-03-19 16:12 [PATCH v2 0/9] PM: Create the AVS class of drivers jean.pihet
@ 2012-03-19 16:12 ` jean.pihet
  2012-04-18 17:27   ` Kevin Hilman
  2012-03-19 16:12 ` [PATCH 2/9] ARM: OMAP2+: SmartReflex: move the driver specific macros in include/linux/power jean.pihet
                   ` (11 subsequent siblings)
  12 siblings, 1 reply; 31+ messages in thread
From: jean.pihet @ 2012-03-19 16:12 UTC (permalink / raw)
  To: linux-omap, linux-arm-kernel, Kevin Hilman, Rafael J. Wysocki, LKML
  Cc: Jean Pihet

From: Jean Pihet <j-pihet@ti.com>

Move some functions from mach-omap2/ dir to the plat/ dir.
The SmartReflex class driver is a user of the basic voltage domains
functions (enable, disable, reset).

Signed-off-by: Jean Pihet <j-pihet@ti.com>
Cc: Kevin Hilman <khilman@ti.com>
---
 arch/arm/mach-omap2/smartreflex-class3.c  |    1 +
 arch/arm/mach-omap2/smartreflex.h         |    2 +-
 arch/arm/mach-omap2/voltage.h             |    1 -
 arch/arm/mach-omap2/vp.h                  |    2 --
 arch/arm/plat-omap/include/plat/voltage.h |    3 +++
 5 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-omap2/smartreflex-class3.c b/arch/arm/mach-omap2/smartreflex-class3.c
index 955566e..e12c51e 100644
--- a/arch/arm/mach-omap2/smartreflex-class3.c
+++ b/arch/arm/mach-omap2/smartreflex-class3.c
@@ -12,6 +12,7 @@
  */
 
 #include "smartreflex.h"
+#include "voltage.h"
 
 static int sr_class3_enable(struct voltagedomain *voltdm)
 {
diff --git a/arch/arm/mach-omap2/smartreflex.h b/arch/arm/mach-omap2/smartreflex.h
index 5809141..c4e8530 100644
--- a/arch/arm/mach-omap2/smartreflex.h
+++ b/arch/arm/mach-omap2/smartreflex.h
@@ -22,7 +22,7 @@
 
 #include <linux/platform_device.h>
 
-#include "voltage.h"
+#include <plat/voltage.h>
 
 /*
  * Different Smartreflex IPs version. The v1 is the 65nm version used in
diff --git a/arch/arm/mach-omap2/voltage.h b/arch/arm/mach-omap2/voltage.h
index 16a1b09..a81dea8 100644
--- a/arch/arm/mach-omap2/voltage.h
+++ b/arch/arm/mach-omap2/voltage.h
@@ -167,6 +167,5 @@ int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
 			  int (*fn)(struct voltagedomain *voltdm,
 				    struct powerdomain *pwrdm));
 int voltdm_scale(struct voltagedomain *voltdm, unsigned long target_volt);
-void voltdm_reset(struct voltagedomain *voltdm);
 unsigned long voltdm_get_voltage(struct voltagedomain *voltdm);
 #endif
diff --git a/arch/arm/mach-omap2/vp.h b/arch/arm/mach-omap2/vp.h
index 7c155d2..837cb8d 100644
--- a/arch/arm/mach-omap2/vp.h
+++ b/arch/arm/mach-omap2/vp.h
@@ -118,8 +118,6 @@ extern struct omap_vp_instance omap4_vp_iva;
 extern struct omap_vp_instance omap4_vp_core;
 
 void omap_vp_init(struct voltagedomain *voltdm);
-void omap_vp_enable(struct voltagedomain *voltdm);
-void omap_vp_disable(struct voltagedomain *voltdm);
 int omap_vp_forceupdate_scale(struct voltagedomain *voltdm,
 			      unsigned long target_volt);
 int omap_vp_update_errorgain(struct voltagedomain *voltdm,
diff --git a/arch/arm/plat-omap/include/plat/voltage.h b/arch/arm/plat-omap/include/plat/voltage.h
index 0a6a482..1842709 100644
--- a/arch/arm/plat-omap/include/plat/voltage.h
+++ b/arch/arm/plat-omap/include/plat/voltage.h
@@ -16,5 +16,8 @@ struct voltagedomain;
 struct voltagedomain *voltdm_lookup(const char *name);
 int voltdm_scale(struct voltagedomain *voltdm, unsigned long target_volt);
 unsigned long voltdm_get_voltage(struct voltagedomain *voltdm);
+void voltdm_reset(struct voltagedomain *voltdm);
 
+void omap_vp_enable(struct voltagedomain *voltdm);
+void omap_vp_disable(struct voltagedomain *voltdm);
 #endif
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 2/9] ARM: OMAP2+: SmartReflex: move the driver specific macros in include/linux/power
  2012-03-19 16:12 [PATCH v2 0/9] PM: Create the AVS class of drivers jean.pihet
  2012-03-19 16:12 ` [PATCH 1/9] ARM: OMAP3+: voltage: export functions to plat/voltage.h jean.pihet
@ 2012-03-19 16:12 ` jean.pihet
  2012-04-04 19:10   ` Trilok Soni
  2012-03-19 16:12 ` [PATCH 3/9] ARM: OMAP3+: SmartReflex: class drivers should use struct omap_sr * jean.pihet
                   ` (10 subsequent siblings)
  12 siblings, 1 reply; 31+ messages in thread
From: jean.pihet @ 2012-03-19 16:12 UTC (permalink / raw)
  To: linux-omap, linux-arm-kernel, Kevin Hilman, Rafael J. Wysocki, LKML
  Cc: Jean Pihet

From: Jean Pihet <j-pihet@ti.com>

Move the driver specific macros from the smartreflex header file
(arch/arm/mach-omap2/smartreflex.h) in a new header file
include/linux/power/smartreflex.h.

This change makes the SmartReflex implementation ready for the move
to drivers/.

Signed-off-by: Jean Pihet <j-pihet@ti.com>
---
 arch/arm/mach-omap2/omap_hwmod_3xxx_data.c |    4 +-
 arch/arm/mach-omap2/omap_hwmod_44xx_data.c |    3 +-
 arch/arm/mach-omap2/smartreflex.c          |    2 +-
 arch/arm/mach-omap2/smartreflex.h          |   42 -----------------
 arch/arm/mach-omap2/sr_device.c            |    2 +-
 include/linux/power/smartreflex.h          |   67 ++++++++++++++++++++++++++++
 6 files changed, 72 insertions(+), 48 deletions(-)
 create mode 100644 include/linux/power/smartreflex.h

diff --git a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
index 0cc6a40..d7d4c70 100644
--- a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
@@ -13,6 +13,8 @@
  *
  * XXX these should be marked initdata for multi-OMAP kernels
  */
+#include <linux/power/smartreflex.h>
+
 #include <plat/omap_hwmod.h>
 #include <mach/irqs.h>
 #include <plat/cpu.h>
@@ -28,8 +30,6 @@
 #include <plat/dmtimer.h>
 
 #include "omap_hwmod_common_data.h"
-
-#include "smartreflex.h"
 #include "prm-regbits-34xx.h"
 #include "cm-regbits-34xx.h"
 #include "wd_timer.h"
diff --git a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
index 48e5834..31e7b87 100644
--- a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
@@ -19,6 +19,7 @@
  */
 
 #include <linux/io.h>
+#include <linux/power/smartreflex.h>
 
 #include <plat/omap_hwmod.h>
 #include <plat/cpu.h>
@@ -32,8 +33,6 @@
 #include <plat/common.h>
 
 #include "omap_hwmod_common_data.h"
-
-#include "smartreflex.h"
 #include "cm1_44xx.h"
 #include "cm2_44xx.h"
 #include "prm44xx.h"
diff --git a/arch/arm/mach-omap2/smartreflex.c b/arch/arm/mach-omap2/smartreflex.c
index 008fbd7..33e2825 100644
--- a/arch/arm/mach-omap2/smartreflex.c
+++ b/arch/arm/mach-omap2/smartreflex.c
@@ -25,9 +25,9 @@
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/pm_runtime.h>
+#include <linux/power/smartreflex.h>
 
 #include "common.h"
-
 #include "pm.h"
 #include "smartreflex.h"
 
diff --git a/arch/arm/mach-omap2/smartreflex.h b/arch/arm/mach-omap2/smartreflex.h
index c4e8530..8835422 100644
--- a/arch/arm/mach-omap2/smartreflex.h
+++ b/arch/arm/mach-omap2/smartreflex.h
@@ -152,14 +152,6 @@ struct omap_sr_pmic_data {
 	void (*sr_pmic_init) (void);
 };
 
-/**
- * struct omap_smartreflex_dev_attr - Smartreflex Device attribute.
- *
- * @sensor_voltdm_name:       Name of voltdomain of SR instance
- */
-struct omap_smartreflex_dev_attr {
-	const char      *sensor_voltdm_name;
-};
 
 #ifdef CONFIG_OMAP_SMARTREFLEX
 /*
@@ -194,40 +186,6 @@ struct omap_sr_class_data {
 	u8 class_type;
 };
 
-/**
- * struct omap_sr_nvalue_table	- Smartreflex n-target value info
- *
- * @efuse_offs:	The offset of the efuse where n-target values are stored.
- * @nvalue:	The n-target value.
- */
-struct omap_sr_nvalue_table {
-	u32 efuse_offs;
-	u32 nvalue;
-};
-
-/**
- * struct omap_sr_data - Smartreflex platform data.
- *
- * @ip_type:		Smartreflex IP type.
- * @senp_mod:		SENPENABLE value for the sr
- * @senn_mod:		SENNENABLE value for sr
- * @nvalue_count:	Number of distinct nvalues in the nvalue table
- * @enable_on_init:	whether this sr module needs to enabled at
- *			boot up or not.
- * @nvalue_table:	table containing the  efuse offsets and nvalues
- *			corresponding to them.
- * @voltdm:		Pointer to the voltage domain associated with the SR
- */
-struct omap_sr_data {
-	int				ip_type;
-	u32				senp_mod;
-	u32				senn_mod;
-	int				nvalue_count;
-	bool				enable_on_init;
-	struct omap_sr_nvalue_table	*nvalue_table;
-	struct voltagedomain		*voltdm;
-};
-
 /* Smartreflex module enable/disable interface */
 void omap_sr_enable(struct voltagedomain *voltdm);
 void omap_sr_disable(struct voltagedomain *voltdm);
diff --git a/arch/arm/mach-omap2/sr_device.c b/arch/arm/mach-omap2/sr_device.c
index a503e1e..86e438e 100644
--- a/arch/arm/mach-omap2/sr_device.c
+++ b/arch/arm/mach-omap2/sr_device.c
@@ -17,6 +17,7 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
+#include <linux/power/smartreflex.h>
 
 #include <linux/err.h>
 #include <linux/slab.h>
@@ -24,7 +25,6 @@
 
 #include <plat/omap_device.h>
 
-#include "smartreflex.h"
 #include "voltage.h"
 #include "control.h"
 #include "pm.h"
diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
new file mode 100644
index 0000000..4a15640
--- /dev/null
+++ b/include/linux/power/smartreflex.h
@@ -0,0 +1,67 @@
+/*
+ * OMAP Smartreflex Defines and Routines
+ *
+ * Copyright (C) 2012 Texas Instruments, Inc.
+ * Jean Pihet <j-pihet@ti.com>
+ *
+ * Copyright (C) 2008 Nokia Corporation
+ * Kalle Jokiniemi
+ *
+ * Copyright (C) 2007 Texas Instruments, Inc.
+ * Lesly A M <x0080970@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef __POWER_SMARTREFLEX_H
+#define __POWER_SMARTREFLEX_H
+
+#include <linux/types.h>
+
+#include <plat/voltage.h>
+
+/**
+ * struct omap_sr_nvalue_table	- Smartreflex n-target value info
+ *
+ * @efuse_offs:	The offset of the efuse where n-target values are stored.
+ * @nvalue:	The n-target value.
+ */
+struct omap_sr_nvalue_table {
+	u32 efuse_offs;
+	u32 nvalue;
+};
+
+/**
+ * struct omap_sr_data - Smartreflex platform data.
+ *
+ * @ip_type:		Smartreflex IP type.
+ * @senp_mod:		SENPENABLE value for the sr
+ * @senn_mod:		SENNENABLE value for sr
+ * @nvalue_count:	Number of distinct nvalues in the nvalue table
+ * @enable_on_init:	whether this sr module needs to enabled at
+ *			boot up or not.
+ * @nvalue_table:	table containing the  efuse offsets and nvalues
+ *			corresponding to them.
+ * @voltdm:		Pointer to the voltage domain associated with the SR
+ */
+struct omap_sr_data {
+	int				ip_type;
+	u32				senp_mod;
+	u32				senn_mod;
+	int				nvalue_count;
+	bool				enable_on_init;
+	struct omap_sr_nvalue_table	*nvalue_table;
+	struct voltagedomain		*voltdm;
+};
+
+/**
+ * struct omap_smartreflex_dev_attr - Smartreflex Device attribute.
+ *
+ * @sensor_voltdm_name:       Name of voltdomain of SR instance
+ */
+struct omap_smartreflex_dev_attr {
+	const char      *sensor_voltdm_name;
+};
+
+#endif
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 3/9] ARM: OMAP3+: SmartReflex: class drivers should use struct omap_sr *
  2012-03-19 16:12 [PATCH v2 0/9] PM: Create the AVS class of drivers jean.pihet
  2012-03-19 16:12 ` [PATCH 1/9] ARM: OMAP3+: voltage: export functions to plat/voltage.h jean.pihet
  2012-03-19 16:12 ` [PATCH 2/9] ARM: OMAP2+: SmartReflex: move the driver specific macros in include/linux/power jean.pihet
@ 2012-03-19 16:12 ` jean.pihet
  2012-03-19 16:12 ` [PATCH 4/9] ARM: OMAP2+: smartreflex: Use the names from hwmod data instead of voltage domains jean.pihet
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 31+ messages in thread
From: jean.pihet @ 2012-03-19 16:12 UTC (permalink / raw)
  To: linux-omap, linux-arm-kernel, Kevin Hilman, Rafael J. Wysocki, LKML
  Cc: Jean Pihet, Paul Walmsley, Thara Gopinath, Nishanth Menon

From: Jean Pihet <j-pihet@ti.com>

Convert SmartReflex "class" functions to take a struct omap_sr *, rather than
a struct voltagedomain *.  SmartReflex code should be driver code and not
tightly coupled to OMAP subarchitecture-specific structures.

Based on Paul's original code for the SmartReflex driver conversion.

Signed-off-by: Jean Pihet <j-pihet@ti.com>
Cc: Paul Walmsley <paul@pwsan.com>
Cc: Thara Gopinath <thara@ti.com>
Cc: Nishanth Menon <nm@ti.com>
Cc: Kevin Hilman <khilman@ti.com>
---
 arch/arm/mach-omap2/smartreflex-class3.c |   24 +++++++++---------
 arch/arm/mach-omap2/smartreflex.c        |   37 +++++------------------------
 arch/arm/mach-omap2/smartreflex.h        |    9 ++++---
 include/linux/power/smartreflex.h        |   23 ++++++++++++++++++
 4 files changed, 47 insertions(+), 46 deletions(-)

diff --git a/arch/arm/mach-omap2/smartreflex-class3.c b/arch/arm/mach-omap2/smartreflex-class3.c
index e12c51e..54ba048 100644
--- a/arch/arm/mach-omap2/smartreflex-class3.c
+++ b/arch/arm/mach-omap2/smartreflex-class3.c
@@ -14,34 +14,34 @@
 #include "smartreflex.h"
 #include "voltage.h"
 
-static int sr_class3_enable(struct voltagedomain *voltdm)
+static int sr_class3_enable(struct omap_sr *sr)
 {
-	unsigned long volt = voltdm_get_voltage(voltdm);
+	unsigned long volt = voltdm_get_voltage(sr->voltdm);
 
 	if (!volt) {
 		pr_warning("%s: Curr voltage unknown. Cannot enable sr_%s\n",
-				__func__, voltdm->name);
+				__func__, sr->voltdm->name);
 		return -ENODATA;
 	}
 
-	omap_vp_enable(voltdm);
-	return sr_enable(voltdm, volt);
+	omap_vp_enable(sr->voltdm);
+	return sr_enable(sr->voltdm, volt);
 }
 
-static int sr_class3_disable(struct voltagedomain *voltdm, int is_volt_reset)
+static int sr_class3_disable(struct omap_sr *sr, int is_volt_reset)
 {
-	sr_disable_errgen(voltdm);
-	omap_vp_disable(voltdm);
-	sr_disable(voltdm);
+	sr_disable_errgen(sr->voltdm);
+	omap_vp_disable(sr->voltdm);
+	sr_disable(sr->voltdm);
 	if (is_volt_reset)
-		voltdm_reset(voltdm);
+		voltdm_reset(sr->voltdm);
 
 	return 0;
 }
 
-static int sr_class3_configure(struct voltagedomain *voltdm)
+static int sr_class3_configure(struct omap_sr *sr)
 {
-	return sr_configure_errgen(voltdm);
+	return sr_configure_errgen(sr->voltdm);
 }
 
 /* SR class3 structure */
diff --git a/arch/arm/mach-omap2/smartreflex.c b/arch/arm/mach-omap2/smartreflex.c
index 33e2825..dbb6a0c 100644
--- a/arch/arm/mach-omap2/smartreflex.c
+++ b/arch/arm/mach-omap2/smartreflex.c
@@ -35,29 +35,6 @@
 #define NVALUE_NAME_LEN		40
 #define SR_DISABLE_TIMEOUT	200
 
-struct omap_sr {
-	struct list_head		node;
-	struct platform_device		*pdev;
-	struct omap_sr_nvalue_table	*nvalue_table;
-	struct voltagedomain		*voltdm;
-	struct dentry			*dbg_dir;
-	unsigned int			irq;
-	int				srid;
-	int				ip_type;
-	int				nvalue_count;
-	bool				autocomp_active;
-	u32				clk_length;
-	u32				err_weight;
-	u32				err_minlimit;
-	u32				err_maxlimit;
-	u32				accum_data;
-	u32				senn_avgweight;
-	u32				senp_avgweight;
-	u32				senp_mod;
-	u32				senn_mod;
-	void __iomem			*base;
-};
-
 /* sr_list contains all the instances of smartreflex module */
 static LIST_HEAD(sr_list);
 
@@ -148,7 +125,7 @@ static irqreturn_t sr_interrupt(int irq, void *data)
 	}
 
 	if (sr_class->notify)
-		sr_class->notify(sr_info->voltdm, status);
+		sr_class->notify(sr_info, status);
 
 	return IRQ_HANDLED;
 }
@@ -226,7 +203,7 @@ static void sr_start_vddautocomp(struct omap_sr *sr)
 		return;
 	}
 
-	if (!sr_class->enable(sr->voltdm))
+	if (!sr_class->enable(sr))
 		sr->autocomp_active = true;
 }
 
@@ -240,7 +217,7 @@ static void sr_stop_vddautocomp(struct omap_sr *sr)
 	}
 
 	if (sr->autocomp_active) {
-		sr_class->disable(sr->voltdm, 1);
+		sr_class->disable(sr, 1);
 		sr->autocomp_active = false;
 	}
 }
@@ -655,7 +632,7 @@ int sr_enable(struct voltagedomain *voltdm, unsigned long volt)
 		return 0;
 
 	/* Configure SR */
-	ret = sr_class->configure(voltdm);
+	ret = sr_class->configure(sr);
 	if (ret)
 		return ret;
 
@@ -773,7 +750,7 @@ void omap_sr_enable(struct voltagedomain *voltdm)
 		return;
 	}
 
-	sr_class->enable(voltdm);
+	sr_class->enable(sr);
 }
 
 /**
@@ -806,7 +783,7 @@ void omap_sr_disable(struct voltagedomain *voltdm)
 		return;
 	}
 
-	sr_class->disable(voltdm, 0);
+	sr_class->disable(sr, 0);
 }
 
 /**
@@ -839,7 +816,7 @@ void omap_sr_disable_reset_volt(struct voltagedomain *voltdm)
 		return;
 	}
 
-	sr_class->disable(voltdm, 1);
+	sr_class->disable(sr, 1);
 }
 
 /**
diff --git a/arch/arm/mach-omap2/smartreflex.h b/arch/arm/mach-omap2/smartreflex.h
index 8835422..6f9b677 100644
--- a/arch/arm/mach-omap2/smartreflex.h
+++ b/arch/arm/mach-omap2/smartreflex.h
@@ -21,6 +21,7 @@
 #define __ASM_ARM_OMAP_SMARTREFLEX_H
 
 #include <linux/platform_device.h>
+#include <linux/power/smartreflex.h>
 
 #include <plat/voltage.h>
 
@@ -178,10 +179,10 @@ struct omap_sr_pmic_data {
  *			based decisions.
  */
 struct omap_sr_class_data {
-	int (*enable)(struct voltagedomain *voltdm);
-	int (*disable)(struct voltagedomain *voltdm, int is_volt_reset);
-	int (*configure)(struct voltagedomain *voltdm);
-	int (*notify)(struct voltagedomain *voltdm, u32 status);
+	int (*enable)(struct omap_sr *sr);
+	int (*disable)(struct omap_sr *sr, int is_volt_reset);
+	int (*configure)(struct omap_sr *sr);
+	int (*notify)(struct omap_sr *sr, u32 status);
 	u8 notify_flags;
 	u8 class_type;
 };
diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
index 4a15640..cf292ac 100644
--- a/include/linux/power/smartreflex.h
+++ b/include/linux/power/smartreflex.h
@@ -21,6 +21,29 @@
 
 #include <plat/voltage.h>
 
+struct omap_sr {
+	struct list_head		node;
+	struct platform_device		*pdev;
+	struct omap_sr_nvalue_table	*nvalue_table;
+	struct voltagedomain		*voltdm;
+	struct dentry			*dbg_dir;
+	unsigned int			irq;
+	int				srid;
+	int				ip_type;
+	int				nvalue_count;
+	bool				autocomp_active;
+	u32				clk_length;
+	u32				err_weight;
+	u32				err_minlimit;
+	u32				err_maxlimit;
+	u32				accum_data;
+	u32				senn_avgweight;
+	u32				senp_avgweight;
+	u32				senp_mod;
+	u32				senn_mod;
+	void __iomem			*base;
+};
+
 /**
  * struct omap_sr_nvalue_table	- Smartreflex n-target value info
  *
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 4/9] ARM: OMAP2+: smartreflex: Use the names from hwmod data instead of voltage domains.
  2012-03-19 16:12 [PATCH v2 0/9] PM: Create the AVS class of drivers jean.pihet
                   ` (2 preceding siblings ...)
  2012-03-19 16:12 ` [PATCH 3/9] ARM: OMAP3+: SmartReflex: class drivers should use struct omap_sr * jean.pihet
@ 2012-03-19 16:12 ` jean.pihet
  2012-03-19 16:12 ` [PATCH 5/9] ARM: OMAP3: hwmod: rename the smartreflex entries jean.pihet
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 31+ messages in thread
From: jean.pihet @ 2012-03-19 16:12 UTC (permalink / raw)
  To: linux-omap, linux-arm-kernel, Kevin Hilman, Rafael J. Wysocki, LKML
  Cc: Jean Pihet

From: Jean Pihet <j-pihet@ti.com>

Associate a name with each SmartReflex instance from the hwmod data,
rather than attempting to reuse the name of a voltage domain. The name
from hwmod better reflects the smartreflex integration in the system.

Also have the name passed to the drivers using pdata, which helps to remove
any dependencies on SoC-specific structures.

Signed-off-by: Jean Pihet <j-pihet@ti.com>
---
 arch/arm/mach-omap2/smartreflex-class3.c |    4 +-
 arch/arm/mach-omap2/smartreflex.c        |   65 ++++++++++++------------------
 arch/arm/mach-omap2/sr_device.c          |    1 +
 include/linux/power/smartreflex.h        |    3 +
 4 files changed, 32 insertions(+), 41 deletions(-)

diff --git a/arch/arm/mach-omap2/smartreflex-class3.c b/arch/arm/mach-omap2/smartreflex-class3.c
index 54ba048..f63c950 100644
--- a/arch/arm/mach-omap2/smartreflex-class3.c
+++ b/arch/arm/mach-omap2/smartreflex-class3.c
@@ -19,8 +19,8 @@ static int sr_class3_enable(struct omap_sr *sr)
 	unsigned long volt = voltdm_get_voltage(sr->voltdm);
 
 	if (!volt) {
-		pr_warning("%s: Curr voltage unknown. Cannot enable sr_%s\n",
-				__func__, sr->voltdm->name);
+		pr_warning("%s: Curr voltage unknown. Cannot enable %s\n",
+				__func__, sr->name);
 		return -ENODATA;
 	}
 
diff --git a/arch/arm/mach-omap2/smartreflex.c b/arch/arm/mach-omap2/smartreflex.c
index dbb6a0c..c18d47d 100644
--- a/arch/arm/mach-omap2/smartreflex.c
+++ b/arch/arm/mach-omap2/smartreflex.c
@@ -184,7 +184,7 @@ static void sr_set_regfields(struct omap_sr *sr)
 		sr->err_weight = OMAP3430_SR_ERRWEIGHT;
 		sr->err_maxlimit = OMAP3430_SR_ERRMAXLIMIT;
 		sr->accum_data = OMAP3430_SR_ACCUMDATA;
-		if (!(strcmp(sr->voltdm->name, "mpu"))) {
+		if (!(strcmp(sr->name, "sr1"))) {
 			sr->senn_avgweight = OMAP3430_SR1_SENNAVGWEIGHT;
 			sr->senp_avgweight = OMAP3430_SR1_SENPAVGWEIGHT;
 		} else {
@@ -235,19 +235,13 @@ static void sr_stop_vddautocomp(struct omap_sr *sr)
  */
 static int sr_late_init(struct omap_sr *sr_info)
 {
-	char *name;
 	struct omap_sr_data *pdata = sr_info->pdev->dev.platform_data;
 	struct resource *mem;
 	int ret = 0;
 
 	if (sr_class->notify && sr_class->notify_flags && sr_info->irq) {
-		name = kasprintf(GFP_KERNEL, "sr_%s", sr_info->voltdm->name);
-		if (name == NULL) {
-			ret = -ENOMEM;
-			goto error;
-		}
 		ret = request_irq(sr_info->irq, sr_interrupt,
-				0, name, sr_info);
+				  0, sr_info->name, sr_info);
 		if (ret)
 			goto error;
 		disable_irq(sr_info->irq);
@@ -266,7 +260,6 @@ error:
 	dev_err(&sr_info->pdev->dev, "%s: ERROR in registering"
 		"interrupt handler. Smartreflex will"
 		"not function as desired\n", __func__);
-	kfree(name);
 	kfree(sr_info);
 
 	return ret;
@@ -396,8 +389,7 @@ int sr_configure_errgen(struct voltagedomain *voltdm)
 	struct omap_sr *sr = _sr_lookup(voltdm);
 
 	if (IS_ERR(sr)) {
-		pr_warning("%s: omap_sr struct for sr_%s not found\n",
-			__func__, voltdm->name);
+		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
 		return PTR_ERR(sr);
 	}
 
@@ -464,8 +456,7 @@ int sr_disable_errgen(struct voltagedomain *voltdm)
 	struct omap_sr *sr = _sr_lookup(voltdm);
 
 	if (IS_ERR(sr)) {
-		pr_warning("%s: omap_sr struct for sr_%s not found\n",
-			__func__, voltdm->name);
+		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
 		return PTR_ERR(sr);
 	}
 
@@ -515,8 +506,7 @@ int sr_configure_minmax(struct voltagedomain *voltdm)
 	struct omap_sr *sr = _sr_lookup(voltdm);
 
 	if (IS_ERR(sr)) {
-		pr_warning("%s: omap_sr struct for sr_%s not found\n",
-			__func__, voltdm->name);
+		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
 		return PTR_ERR(sr);
 	}
 
@@ -601,8 +591,7 @@ int sr_enable(struct voltagedomain *voltdm, unsigned long volt)
 	int ret;
 
 	if (IS_ERR(sr)) {
-		pr_warning("%s: omap_sr struct for sr_%s not found\n",
-			__func__, voltdm->name);
+		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
 		return PTR_ERR(sr);
 	}
 
@@ -655,8 +644,7 @@ void sr_disable(struct voltagedomain *voltdm)
 	struct omap_sr *sr = _sr_lookup(voltdm);
 
 	if (IS_ERR(sr)) {
-		pr_warning("%s: omap_sr struct for sr_%s not found\n",
-			__func__, voltdm->name);
+		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
 		return;
 	}
 
@@ -736,8 +724,7 @@ void omap_sr_enable(struct voltagedomain *voltdm)
 	struct omap_sr *sr = _sr_lookup(voltdm);
 
 	if (IS_ERR(sr)) {
-		pr_warning("%s: omap_sr struct for sr_%s not found\n",
-			__func__, voltdm->name);
+		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
 		return;
 	}
 
@@ -769,8 +756,7 @@ void omap_sr_disable(struct voltagedomain *voltdm)
 	struct omap_sr *sr = _sr_lookup(voltdm);
 
 	if (IS_ERR(sr)) {
-		pr_warning("%s: omap_sr struct for sr_%s not found\n",
-			__func__, voltdm->name);
+		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
 		return;
 	}
 
@@ -802,8 +788,7 @@ void omap_sr_disable_reset_volt(struct voltagedomain *voltdm)
 	struct omap_sr *sr = _sr_lookup(voltdm);
 
 	if (IS_ERR(sr)) {
-		pr_warning("%s: omap_sr struct for sr_%s not found\n",
-			__func__, voltdm->name);
+		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
 		return;
 	}
 
@@ -890,7 +875,6 @@ static int __init omap_sr_probe(struct platform_device *pdev)
 	struct dentry *nvalue_dir;
 	struct omap_volt_data *volt_data;
 	int i, ret = 0;
-	char *name;
 
 	sr_info = kzalloc(sizeof(struct omap_sr), GFP_KERNEL);
 	if (!sr_info) {
@@ -927,6 +911,14 @@ static int __init omap_sr_probe(struct platform_device *pdev)
 	pm_runtime_enable(&pdev->dev);
 	pm_runtime_irq_safe(&pdev->dev);
 
+	sr_info->name = kasprintf(GFP_KERNEL, "sr_%s", pdata->name);
+	if (!sr_info->name) {
+		dev_err(&pdev->dev, "%s: Unable to alloc SR instance name\n",
+			__func__);
+		ret = -ENOMEM;
+		goto err_release_region;
+	}
+
 	sr_info->pdev = pdev;
 	sr_info->srid = pdev->id;
 	sr_info->voltdm = pdata->voltdm;
@@ -974,20 +966,12 @@ static int __init omap_sr_probe(struct platform_device *pdev)
 		}
 	}
 
-	name = kasprintf(GFP_KERNEL, "sr_%s", sr_info->voltdm->name);
-	if (!name) {
-		dev_err(&pdev->dev, "%s: Unable to alloc debugfs name\n",
-			__func__);
-		ret = -ENOMEM;
-		goto err_iounmap;
-	}
-	sr_info->dbg_dir = debugfs_create_dir(name, sr_dbg_dir);
-	kfree(name);
+	sr_info->dbg_dir = debugfs_create_dir(sr_info->name, sr_dbg_dir);
 	if (IS_ERR_OR_NULL(sr_info->dbg_dir)) {
 		dev_err(&pdev->dev, "%s: Unable to create debugfs directory\n",
 			__func__);
 		ret = PTR_ERR(sr_info->dbg_dir);
-		goto err_iounmap;
+		goto err_free_name;
 	}
 
 	(void) debugfs_create_file("autocomp", S_IRUGO | S_IWUSR,
@@ -1009,10 +993,10 @@ static int __init omap_sr_probe(struct platform_device *pdev)
 
 	omap_voltage_get_volttable(sr_info->voltdm, &volt_data);
 	if (!volt_data) {
-		dev_warn(&pdev->dev, "%s: No Voltage table for the"
-			" corresponding vdd vdd_%s. Cannot create debugfs"
+		dev_warn(&pdev->dev, "%s: %s: No Voltage table for the"
+			" corresponding vdd. Cannot create debugfs"
 			"entries for n-values\n",
-			__func__, sr_info->voltdm->name);
+			__func__, sr_info->name);
 		ret = -ENODATA;
 		goto err_debugfs;
 	}
@@ -1030,6 +1014,8 @@ static int __init omap_sr_probe(struct platform_device *pdev)
 
 err_debugfs:
 	debugfs_remove_recursive(sr_info->dbg_dir);
+err_free_name:
+	kfree(sr_info->name);
 err_iounmap:
 	list_del(&sr_info->node);
 	iounmap(sr_info->base);
@@ -1066,6 +1052,7 @@ static int __devexit omap_sr_remove(struct platform_device *pdev)
 
 	list_del(&sr_info->node);
 	iounmap(sr_info->base);
+	kfree(sr_info->name);
 	kfree(sr_info);
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	release_mem_region(mem->start, resource_size(mem));
diff --git a/arch/arm/mach-omap2/sr_device.c b/arch/arm/mach-omap2/sr_device.c
index 86e438e..e081174 100644
--- a/arch/arm/mach-omap2/sr_device.c
+++ b/arch/arm/mach-omap2/sr_device.c
@@ -93,6 +93,7 @@ static int __init sr_dev_init(struct omap_hwmod *oh, void *user)
 		goto exit;
 	}
 
+	sr_data->name = oh->name;
 	sr_data->ip_type = oh->class->rev;
 	sr_data->senn_mod = 0x1;
 	sr_data->senp_mod = 0x1;
diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
index cf292ac..e7dff08 100644
--- a/include/linux/power/smartreflex.h
+++ b/include/linux/power/smartreflex.h
@@ -22,6 +22,7 @@
 #include <plat/voltage.h>
 
 struct omap_sr {
+	char				*name;
 	struct list_head		node;
 	struct platform_device		*pdev;
 	struct omap_sr_nvalue_table	*nvalue_table;
@@ -58,6 +59,7 @@ struct omap_sr_nvalue_table {
 /**
  * struct omap_sr_data - Smartreflex platform data.
  *
+ * @name:		instance name
  * @ip_type:		Smartreflex IP type.
  * @senp_mod:		SENPENABLE value for the sr
  * @senn_mod:		SENNENABLE value for sr
@@ -69,6 +71,7 @@ struct omap_sr_nvalue_table {
  * @voltdm:		Pointer to the voltage domain associated with the SR
  */
 struct omap_sr_data {
+	const char			*name;
 	int				ip_type;
 	u32				senp_mod;
 	u32				senn_mod;
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 5/9] ARM: OMAP3: hwmod: rename the smartreflex entries
  2012-03-19 16:12 [PATCH v2 0/9] PM: Create the AVS class of drivers jean.pihet
                   ` (3 preceding siblings ...)
  2012-03-19 16:12 ` [PATCH 4/9] ARM: OMAP2+: smartreflex: Use the names from hwmod data instead of voltage domains jean.pihet
@ 2012-03-19 16:12 ` jean.pihet
  2012-04-18 17:33   ` Kevin Hilman
  2012-03-19 16:12 ` [PATCH 6/9] ARM: OMAP2+: SmartReflex: introduce a busy loop condition test macro jean.pihet
                   ` (7 subsequent siblings)
  12 siblings, 1 reply; 31+ messages in thread
From: jean.pihet @ 2012-03-19 16:12 UTC (permalink / raw)
  To: linux-omap, linux-arm-kernel, Kevin Hilman, Rafael J. Wysocki, LKML
  Cc: Jean Pihet

From: Jean Pihet <j-pihet@ti.com>

Change the name field value to better reflect the smartreflex
integration in the system

Signed-off-by: Jean Pihet <j-pihet@ti.com>
---
 arch/arm/mach-omap2/omap_hwmod_3xxx_data.c |    8 ++++----
 arch/arm/mach-omap2/smartreflex.c          |    2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
index d7d4c70..40f57c4 100644
--- a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
@@ -2751,7 +2751,7 @@ static struct omap_hwmod_ocp_if *omap34xx_sr1_slaves[] = {
 };
 
 static struct omap_hwmod omap34xx_sr1_hwmod = {
-	.name		= "sr1",
+	.name		= "mpu_iva",
 	.class		= &omap34xx_smartreflex_hwmod_class,
 	.main_clk	= "sr1_fck",
 	.prcm		= {
@@ -2775,7 +2775,7 @@ static struct omap_hwmod_ocp_if *omap36xx_sr1_slaves[] = {
 };
 
 static struct omap_hwmod omap36xx_sr1_hwmod = {
-	.name		= "sr1",
+	.name		= "mpu_iva",
 	.class		= &omap36xx_smartreflex_hwmod_class,
 	.main_clk	= "sr1_fck",
 	.prcm		= {
@@ -2803,7 +2803,7 @@ static struct omap_hwmod_ocp_if *omap34xx_sr2_slaves[] = {
 };
 
 static struct omap_hwmod omap34xx_sr2_hwmod = {
-	.name		= "sr2",
+	.name		= "core",
 	.class		= &omap34xx_smartreflex_hwmod_class,
 	.main_clk	= "sr2_fck",
 	.prcm		= {
@@ -2827,7 +2827,7 @@ static struct omap_hwmod_ocp_if *omap36xx_sr2_slaves[] = {
 };
 
 static struct omap_hwmod omap36xx_sr2_hwmod = {
-	.name		= "sr2",
+	.name		= "core",
 	.class		= &omap36xx_smartreflex_hwmod_class,
 	.main_clk	= "sr2_fck",
 	.prcm		= {
diff --git a/arch/arm/mach-omap2/smartreflex.c b/arch/arm/mach-omap2/smartreflex.c
index c18d47d..b2728a5 100644
--- a/arch/arm/mach-omap2/smartreflex.c
+++ b/arch/arm/mach-omap2/smartreflex.c
@@ -184,7 +184,7 @@ static void sr_set_regfields(struct omap_sr *sr)
 		sr->err_weight = OMAP3430_SR_ERRWEIGHT;
 		sr->err_maxlimit = OMAP3430_SR_ERRMAXLIMIT;
 		sr->accum_data = OMAP3430_SR_ACCUMDATA;
-		if (!(strcmp(sr->name, "sr1"))) {
+		if (!(strcmp(sr->name, "sr_mpu_iva"))) {
 			sr->senn_avgweight = OMAP3430_SR1_SENNAVGWEIGHT;
 			sr->senp_avgweight = OMAP3430_SR1_SENPAVGWEIGHT;
 		} else {
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 6/9] ARM: OMAP2+: SmartReflex: introduce a busy loop condition test macro
  2012-03-19 16:12 [PATCH v2 0/9] PM: Create the AVS class of drivers jean.pihet
                   ` (4 preceding siblings ...)
  2012-03-19 16:12 ` [PATCH 5/9] ARM: OMAP3: hwmod: rename the smartreflex entries jean.pihet
@ 2012-03-19 16:12 ` jean.pihet
  2012-03-19 16:12 ` [PATCH 7/9] ARM: OMAP2+: SmartReflex: Use per-OPP data structure jean.pihet
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 31+ messages in thread
From: jean.pihet @ 2012-03-19 16:12 UTC (permalink / raw)
  To: linux-omap, linux-arm-kernel, Kevin Hilman, Rafael J. Wysocki, LKML
  Cc: Jean Pihet

From: Jean Pihet <j-pihet@ti.com>

Now that omap_test_timeout is only accessible from mach-omap2/,
introduce a similar function for SR.

This change makes the SmartReflex implementation ready for the move
to drivers/.

Signed-off-by: Jean Pihet <j-pihet@ti.com>
---
 arch/arm/mach-omap2/smartreflex.c |   12 ++++++------
 arch/arm/mach-omap2/smartreflex.h |   23 +++++++++++++++++++++++
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-omap2/smartreflex.c b/arch/arm/mach-omap2/smartreflex.c
index b2728a5..5f3faf3 100644
--- a/arch/arm/mach-omap2/smartreflex.c
+++ b/arch/arm/mach-omap2/smartreflex.c
@@ -290,9 +290,9 @@ static void sr_v1_disable(struct omap_sr *sr)
 	 * Wait for SR to be disabled.
 	 * wait until ERRCONFIG.MCUDISACKINTST = 1. Typical latency is 1us.
 	 */
-	omap_test_timeout((sr_read_reg(sr, ERRCONFIG_V1) &
-			ERRCONFIG_MCUDISACKINTST), SR_DISABLE_TIMEOUT,
-			timeout);
+	sr_test_cond_timeout((sr_read_reg(sr, ERRCONFIG_V1) &
+			     ERRCONFIG_MCUDISACKINTST), SR_DISABLE_TIMEOUT,
+			     timeout);
 
 	if (timeout >= SR_DISABLE_TIMEOUT)
 		dev_warn(&sr->pdev->dev, "%s: Smartreflex disable timedout\n",
@@ -335,9 +335,9 @@ static void sr_v2_disable(struct omap_sr *sr)
 	 * Wait for SR to be disabled.
 	 * wait until IRQSTATUS.MCUDISACKINTST = 1. Typical latency is 1us.
 	 */
-	omap_test_timeout((sr_read_reg(sr, IRQSTATUS) &
-			IRQSTATUS_MCUDISABLEACKINT), SR_DISABLE_TIMEOUT,
-			timeout);
+	sr_test_cond_timeout((sr_read_reg(sr, IRQSTATUS) &
+			     IRQSTATUS_MCUDISABLEACKINT), SR_DISABLE_TIMEOUT,
+			     timeout);
 
 	if (timeout >= SR_DISABLE_TIMEOUT)
 		dev_warn(&sr->pdev->dev, "%s: Smartreflex disable timedout\n",
diff --git a/arch/arm/mach-omap2/smartreflex.h b/arch/arm/mach-omap2/smartreflex.h
index 6f9b677..a87bac1 100644
--- a/arch/arm/mach-omap2/smartreflex.h
+++ b/arch/arm/mach-omap2/smartreflex.h
@@ -21,6 +21,7 @@
 #define __ASM_ARM_OMAP_SMARTREFLEX_H
 
 #include <linux/platform_device.h>
+#include <linux/delay.h>
 #include <linux/power/smartreflex.h>
 
 #include <plat/voltage.h>
@@ -144,6 +145,28 @@
 #define OMAP3430_SR_ERRMAXLIMIT		0x02
 
 /**
+ * test_cond_timeout - busy-loop, testing a condition
+ * @cond: condition to test until it evaluates to true
+ * @timeout: maximum number of microseconds in the timeout
+ * @index: loop index (integer)
+ *
+ * Loop waiting for @cond to become true or until at least @timeout
+ * microseconds have passed.  To use, define some integer @index in the
+ * calling code.  After running, if @index == @timeout, then the loop has
+ * timed out.
+ *
+ * Copied from omap_test_timeout
+ */
+#define sr_test_cond_timeout(cond, timeout, index)		\
+({								\
+	for (index = 0; index < timeout; index++) {		\
+		if (cond)					\
+			break;					\
+		udelay(1);					\
+	}							\
+})
+
+/**
  * struct omap_sr_pmic_data - Strucutre to be populated by pmic code to pass
  *				pmic specific info to smartreflex driver
  *
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 7/9] ARM: OMAP2+: SmartReflex: Use per-OPP data structure
  2012-03-19 16:12 [PATCH v2 0/9] PM: Create the AVS class of drivers jean.pihet
                   ` (5 preceding siblings ...)
  2012-03-19 16:12 ` [PATCH 6/9] ARM: OMAP2+: SmartReflex: introduce a busy loop condition test macro jean.pihet
@ 2012-03-19 16:12 ` jean.pihet
  2012-04-18 18:21   ` Kevin Hilman
  2012-03-19 16:12 ` [PATCH 8/9] ARM: OMAP2+: SmartReflex: add POWER_AVS Kconfig options jean.pihet
                   ` (5 subsequent siblings)
  12 siblings, 1 reply; 31+ messages in thread
From: jean.pihet @ 2012-03-19 16:12 UTC (permalink / raw)
  To: linux-omap, linux-arm-kernel, Kevin Hilman, Rafael J. Wysocki, LKML
  Cc: Jean Pihet, Paul Walmsley, Thara Gopinath, Nishanth Menon

From: Jean Pihet <j-pihet@ti.com>

The SmartReflex driver incorrectly treats some per-OPP data as data
common to all OPPs (e.g., ERRMINLIMIT).  Move this data into a per-OPP
data structure.
The SmartReflex driver should not be dependent on whether the host SoC
uses eFuses to store SmartReflex parameters or not.  (Even SoCs that
do store SR data in eFuses often need to override that data with
software-defined values.)  So, convert sr_retrieve_nvalue() to look up
per-OPP data by the OPP's nominal voltage, rather than by the eFuse
offset.

While at it:
 . tidy up the code wrt default values in the data tables,
 . remove the global errminlimit debugfs entry and create per-voltage
   entries from the data tables.

Furthermore, in order to make the SmartReflex implementation ready for
the move to drivers/, remove the dependency from the SR driver code
to the voltage layer by querying the data tables only from the SR device
init code.

Based on Paul's original code for the SmartReflex driver conversion.

Signed-off-by: Jean Pihet <j-pihet@ti.com>
Cc: Paul Walmsley <paul@pwsan.com>
Cc: Thara Gopinath <thara@ti.com>
Cc: Nishanth Menon <nm@ti.com>
Cc: Kevin Hilman <khilman@ti.com>
---
 arch/arm/mach-omap2/smartreflex.c |   57 +++++++++++++++---------------------
 arch/arm/mach-omap2/sr_device.c   |   35 +++++++++++++++++++----
 include/linux/power/smartreflex.h |    8 ++++-
 3 files changed, 59 insertions(+), 41 deletions(-)

diff --git a/arch/arm/mach-omap2/smartreflex.c b/arch/arm/mach-omap2/smartreflex.c
index 5f3faf3..71f70ca 100644
--- a/arch/arm/mach-omap2/smartreflex.c
+++ b/arch/arm/mach-omap2/smartreflex.c
@@ -348,22 +348,24 @@ static void sr_v2_disable(struct omap_sr *sr)
 	sr_write_reg(sr, IRQSTATUS, IRQSTATUS_MCUDISABLEACKINT);
 }
 
-static u32 sr_retrieve_nvalue(struct omap_sr *sr, u32 efuse_offs)
+static struct omap_sr_nvalue_table *sr_retrieve_nvalue_row(
+				struct omap_sr *sr,
+				unsigned long volt_nominal)
 {
 	int i;
 
 	if (!sr->nvalue_table) {
 		dev_warn(&sr->pdev->dev, "%s: Missing ntarget value table\n",
 			__func__);
-		return 0;
+		return NULL;
 	}
 
 	for (i = 0; i < sr->nvalue_count; i++) {
-		if (sr->nvalue_table[i].efuse_offs == efuse_offs)
-			return sr->nvalue_table[i].nvalue;
+		if (sr->nvalue_table[i].volt_nominal == volt_nominal)
+			return &sr->nvalue_table[i];
 	}
 
-	return 0;
+	return NULL;
 }
 
 /* Public Functions */
@@ -585,9 +587,8 @@ int sr_configure_minmax(struct voltagedomain *voltdm)
  */
 int sr_enable(struct voltagedomain *voltdm, unsigned long volt)
 {
-	struct omap_volt_data *volt_data;
 	struct omap_sr *sr = _sr_lookup(voltdm);
-	u32 nvalue_reciprocal;
+	struct omap_sr_nvalue_table *nvalue_row;
 	int ret;
 
 	if (IS_ERR(sr)) {
@@ -595,24 +596,16 @@ int sr_enable(struct voltagedomain *voltdm, unsigned long volt)
 		return PTR_ERR(sr);
 	}
 
-	volt_data = omap_voltage_get_voltdata(sr->voltdm, volt);
-
-	if (IS_ERR(volt_data)) {
-		dev_warn(&sr->pdev->dev, "%s: Unable to get voltage table"
-			"for nominal voltage %ld\n", __func__, volt);
-		return PTR_ERR(volt_data);
-	}
-
-	nvalue_reciprocal = sr_retrieve_nvalue(sr, volt_data->sr_efuse_offs);
-
-	if (!nvalue_reciprocal) {
-		dev_warn(&sr->pdev->dev, "%s: NVALUE = 0 at voltage %ld\n",
-			__func__, volt);
+	nvalue_row = sr_retrieve_nvalue_row(sr, volt);
+	if (!nvalue_row) {
+		dev_warn(&sr->pdev->dev, "%s: failure getting SR data for this voltage %ld\n",
+			 __func__, volt);
 		return -ENODATA;
 	}
 
+
 	/* errminlimit is opp dependent and hence linked to voltage */
-	sr->err_minlimit = volt_data->sr_errminlimit;
+	sr->err_minlimit = nvalue_row->errminlimit;
 
 	pm_runtime_get_sync(&sr->pdev->dev);
 
@@ -625,7 +618,7 @@ int sr_enable(struct voltagedomain *voltdm, unsigned long volt)
 	if (ret)
 		return ret;
 
-	sr_write_reg(sr, NVALUERECIPROCAL, nvalue_reciprocal);
+	sr_write_reg(sr, NVALUERECIPROCAL, nvalue_row->nvalue);
 
 	/* SRCONFIG - enable SR */
 	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SRENABLE, SRCONFIG_SRENABLE);
@@ -873,7 +866,6 @@ static int __init omap_sr_probe(struct platform_device *pdev)
 	struct omap_sr_data *pdata = pdev->dev.platform_data;
 	struct resource *mem, *irq;
 	struct dentry *nvalue_dir;
-	struct omap_volt_data *volt_data;
 	int i, ret = 0;
 
 	sr_info = kzalloc(sizeof(struct omap_sr), GFP_KERNEL);
@@ -980,8 +972,6 @@ static int __init omap_sr_probe(struct platform_device *pdev)
 			&sr_info->err_weight);
 	(void) debugfs_create_x32("errmaxlimit", S_IRUGO, sr_info->dbg_dir,
 			&sr_info->err_maxlimit);
-	(void) debugfs_create_x32("errminlimit", S_IRUGO, sr_info->dbg_dir,
-			&sr_info->err_minlimit);
 
 	nvalue_dir = debugfs_create_dir("nvalue", sr_info->dbg_dir);
 	if (IS_ERR_OR_NULL(nvalue_dir)) {
@@ -991,12 +981,9 @@ static int __init omap_sr_probe(struct platform_device *pdev)
 		goto err_debugfs;
 	}
 
-	omap_voltage_get_volttable(sr_info->voltdm, &volt_data);
-	if (!volt_data) {
-		dev_warn(&pdev->dev, "%s: %s: No Voltage table for the"
-			" corresponding vdd. Cannot create debugfs"
-			"entries for n-values\n",
-			__func__, sr_info->name);
+	if (sr_info->nvalue_count == 0 || !sr_info->nvalue_table) {
+		dev_warn(&pdev->dev, "%s: %s: No Voltage table for the corresponding vdd. Cannot create debugfs entries for n-values\n",
+			 __func__, sr_info->name);
 		ret = -ENODATA;
 		goto err_debugfs;
 	}
@@ -1004,10 +991,14 @@ static int __init omap_sr_probe(struct platform_device *pdev)
 	for (i = 0; i < sr_info->nvalue_count; i++) {
 		char name[NVALUE_NAME_LEN + 1];
 
-		snprintf(name, sizeof(name), "volt_%d",
-			 volt_data[i].volt_nominal);
+		snprintf(name, sizeof(name), "volt_%lu",
+			 sr_info->nvalue_table[i].volt_nominal);
 		(void) debugfs_create_x32(name, S_IRUGO | S_IWUSR, nvalue_dir,
 				&(sr_info->nvalue_table[i].nvalue));
+		snprintf(name, sizeof(name), "errminlimit_%lu",
+			 sr_info->nvalue_table[i].volt_nominal);
+		(void) debugfs_create_x32(name, S_IRUGO | S_IWUSR, nvalue_dir,
+				&(sr_info->nvalue_table[i].errminlimit));
 	}
 
 	return ret;
diff --git a/arch/arm/mach-omap2/sr_device.c b/arch/arm/mach-omap2/sr_device.c
index e081174..67d967e 100644
--- a/arch/arm/mach-omap2/sr_device.c
+++ b/arch/arm/mach-omap2/sr_device.c
@@ -36,7 +36,10 @@ static void __init sr_set_nvalues(struct omap_volt_data *volt_data,
 				struct omap_sr_data *sr_data)
 {
 	struct omap_sr_nvalue_table *nvalue_table;
-	int i, count = 0;
+	int i, j, count = 0;
+
+	sr_data->nvalue_count = 0;
+	sr_data->nvalue_table = NULL;
 
 	while (volt_data[count].volt_nominal)
 		count++;
@@ -44,8 +47,14 @@ static void __init sr_set_nvalues(struct omap_volt_data *volt_data,
 	nvalue_table = kzalloc(sizeof(struct omap_sr_nvalue_table)*count,
 			GFP_KERNEL);
 
-	for (i = 0; i < count; i++) {
+	if (!nvalue_table) {
+		pr_err("OMAP: SmartReflex: cannot allocate memory for n-value table\n");
+		return;
+	}
+
+	for (i = 0, j = 0; i < count; i++) {
 		u32 v;
+
 		/*
 		 * In OMAP4 the efuse registers are 24 bit aligned.
 		 * A __raw_readl will fail for non-32 bit aligned address
@@ -58,15 +67,29 @@ static void __init sr_set_nvalues(struct omap_volt_data *volt_data,
 				omap_ctrl_readb(offset + 1) << 8 |
 				omap_ctrl_readb(offset + 2) << 16;
 		} else {
-			 v = omap_ctrl_readl(volt_data[i].sr_efuse_offs);
+			v = omap_ctrl_readl(volt_data[i].sr_efuse_offs);
 		}
 
-		nvalue_table[i].efuse_offs = volt_data[i].sr_efuse_offs;
-		nvalue_table[i].nvalue = v;
+		/*
+		 * Many OMAP SoCs don't have the eFuse values set.
+		 * For example, pretty much all OMAP3xxx before
+		 * ES3.something.
+		 *
+		 * XXX There needs to be some way for board files or
+		 * userspace to add these in.
+		 */
+		if (v == 0)
+			continue;
+
+		nvalue_table[j].nvalue = v;
+		nvalue_table[j].errminlimit = volt_data[i].sr_errminlimit;
+		nvalue_table[j].volt_nominal = volt_data[i].volt_nominal;
+
+		j++;
 	}
 
 	sr_data->nvalue_table = nvalue_table;
-	sr_data->nvalue_count = count;
+	sr_data->nvalue_count = j;
 }
 
 static int __init sr_dev_init(struct omap_hwmod *oh, void *user)
diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
index e7dff08..0f7c81b 100644
--- a/include/linux/power/smartreflex.h
+++ b/include/linux/power/smartreflex.h
@@ -48,12 +48,16 @@ struct omap_sr {
 /**
  * struct omap_sr_nvalue_table	- Smartreflex n-target value info
  *
- * @efuse_offs:	The offset of the efuse where n-target values are stored.
- * @nvalue:	The n-target value.
+ * @efuse_offs:	  The offset of the efuse where n-target values are stored.
+ * @nvalue:	  The n-target value.
+ * @errminlimit:  The value of the ERRMINLIMIT bitfield for this n-target
+ * @volt_nominal: microvolts DC that the VDD is initially programmed to
  */
 struct omap_sr_nvalue_table {
 	u32 efuse_offs;
 	u32 nvalue;
+	u32 errminlimit;
+	unsigned long volt_nominal;
 };
 
 /**
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 8/9] ARM: OMAP2+: SmartReflex: add POWER_AVS Kconfig options
  2012-03-19 16:12 [PATCH v2 0/9] PM: Create the AVS class of drivers jean.pihet
                   ` (6 preceding siblings ...)
  2012-03-19 16:12 ` [PATCH 7/9] ARM: OMAP2+: SmartReflex: Use per-OPP data structure jean.pihet
@ 2012-03-19 16:12 ` jean.pihet
  2012-03-19 16:12 ` [PATCH 9/9] ARM: OMAP: SmartReflex: Move smartreflex driver to drivers/ jean.pihet
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 31+ messages in thread
From: jean.pihet @ 2012-03-19 16:12 UTC (permalink / raw)
  To: linux-omap, linux-arm-kernel, Kevin Hilman, Rafael J. Wysocki, LKML
  Cc: Jean Pihet

From: Jean Pihet <j-pihet@ti.com>

Add a Kconfig menu (POWER_AVS) and rename the Kconfig options
for the OMAP SmartReflex implementation:
 CONFIG_OMAP_SMARTREFLEX renames to CONFIG_POWER_AVS_OMAP
 CONFIG_OMAP_SMARTREFLEX_CLASS3 renames to CONFIG_POWER_AVS_OMAP_CLASS3

This change makes the SmartReflex implementation ready for the move
to drivers/.

Signed-off-by: Jean Pihet <j-pihet@ti.com>
---
 arch/arm/mach-omap2/Makefile      |    5 ++-
 arch/arm/mach-omap2/pm.h          |    2 +-
 arch/arm/mach-omap2/smartreflex.h |    6 ++--
 arch/arm/plat-omap/Kconfig        |   45 ++++++++++++++++++++++++------------
 4 files changed, 37 insertions(+), 21 deletions(-)

diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile
index 9746529..30666fd 100644
--- a/arch/arm/mach-omap2/Makefile
+++ b/arch/arm/mach-omap2/Makefile
@@ -68,8 +68,9 @@ obj-$(CONFIG_ARCH_OMAP3)		+= pm34xx.o sleep34xx.o \
 obj-$(CONFIG_ARCH_OMAP4)		+= pm44xx.o omap-mpuss-lowpower.o \
 					   cpuidle44xx.o
 obj-$(CONFIG_PM_DEBUG)			+= pm-debug.o
-obj-$(CONFIG_OMAP_SMARTREFLEX)          += sr_device.o smartreflex.o
-obj-$(CONFIG_OMAP_SMARTREFLEX_CLASS3)	+= smartreflex-class3.o
+
+obj-$(CONFIG_POWER_AVS_OMAP)		+= sr_device.o smartreflex.o
+obj-$(CONFIG_POWER_AVS_OMAP_CLASS3)	+= smartreflex-class3.o
 
 AFLAGS_sleep24xx.o			:=-Wa,-march=armv6
 AFLAGS_sleep34xx.o			:=-Wa,-march=armv7-a$(plus_sec)
diff --git a/arch/arm/mach-omap2/pm.h b/arch/arm/mach-omap2/pm.h
index a051431..1a2d483 100644
--- a/arch/arm/mach-omap2/pm.h
+++ b/arch/arm/mach-omap2/pm.h
@@ -110,7 +110,7 @@ extern void enable_omap3630_toggle_l2_on_restore(void);
 static inline void enable_omap3630_toggle_l2_on_restore(void) { }
 #endif		/* defined(CONFIG_PM) && defined(CONFIG_ARCH_OMAP3) */
 
-#ifdef CONFIG_OMAP_SMARTREFLEX
+#ifdef CONFIG_POWER_AVS_OMAP
 extern int omap_devinit_smartreflex(void);
 extern void omap_enable_smartreflex_on_init(void);
 #else
diff --git a/arch/arm/mach-omap2/smartreflex.h b/arch/arm/mach-omap2/smartreflex.h
index a87bac1..754f6aa 100644
--- a/arch/arm/mach-omap2/smartreflex.h
+++ b/arch/arm/mach-omap2/smartreflex.h
@@ -17,8 +17,8 @@
  * published by the Free Software Foundation.
  */
 
-#ifndef __ASM_ARM_OMAP_SMARTREFLEX_H
-#define __ASM_ARM_OMAP_SMARTREFLEX_H
+#ifndef __DRIVERS_POWER_AVS_SMARTREFLEX_H
+#define __DRIVERS_POWER_AVS_SMARTREFLEX_H
 
 #include <linux/platform_device.h>
 #include <linux/delay.h>
@@ -177,7 +177,7 @@ struct omap_sr_pmic_data {
 };
 
 
-#ifdef CONFIG_OMAP_SMARTREFLEX
+#ifdef CONFIG_POWER_AVS_OMAP
 /*
  * The smart reflex driver supports CLASS1 CLASS2 and CLASS3 SR.
  * The smartreflex class driver should pass the class type.
diff --git a/arch/arm/plat-omap/Kconfig b/arch/arm/plat-omap/Kconfig
index f419a08..6ec9237 100644
--- a/arch/arm/plat-omap/Kconfig
+++ b/arch/arm/plat-omap/Kconfig
@@ -44,37 +44,52 @@ config OMAP_DEBUG_LEDS
 	depends on OMAP_DEBUG_DEVICES
 	default y if LEDS_CLASS
 
-config OMAP_SMARTREFLEX
-	bool "SmartReflex support"
-	depends on (ARCH_OMAP3 || ARCH_OMAP4) && PM
+menuconfig POWER_AVS
+	tristate "Adaptive Voltage Scaling class support"
 	help
-	  Say Y if you want to enable SmartReflex.
+	  AVS is a power management technique which finely controls the
+	  operating voltage of a device in order to optimize (i.e. reduce)
+	  its power consumption.
+	  At a given operating point the voltage is adapted depending on
+	  static factors (chip manufacturing process) and dynamic factors
+	  (temperature depending performance).
+	  AVS is also called SmartReflex on OMAP devices.
+
+	  Say Y here to enable Adaptive Voltage Scaling class support.
+
+if POWER_AVS
 
-	  SmartReflex can perform continuous dynamic voltage
-	  scaling around the nominal operating point voltage
-	  according to silicon characteristics and operating
-	  conditions. Enabling SmartReflex reduces power
-	  consumption.
+config POWER_AVS_OMAP
+	bool "AVS support for the OMAP IP versions 1&2"
+	depends on (ARCH_OMAP3 || ARCH_OMAP4) && PM
+	help
+	  Say Y to enable AVS support on OMAP containing the version 1 or
+	  version 2 of the SmartReflex IP.
+	  V1 is the 65nm version used in OMAP3430.
+	  V2 is the update for the 45nm version of the IP used in OMAP3630
+	  and OMAP4430
 
 	  Please note, that by default SmartReflex is only
-	  initialized. To enable the automatic voltage
-	  compensation for vdd mpu  and vdd core from user space,
+	  initialized and not enabled. To enable the automatic voltage
+	  compensation for vdd mpu and vdd core from user space,
 	  user must write 1 to
-		/debug/voltage/vdd_<X>/smartreflex/autocomp,
-	  where X is mpu or core for OMAP3.
+		/debug/smartreflex/sr_<X>/autocomp,
+	  where X is mpu_iva or core for OMAP3.
 	  Optionally autocompensation can be enabled in the kernel
 	  by default during system init via the enable_on_init flag
 	  which an be passed as platform data to the smartreflex driver.
 
-config OMAP_SMARTREFLEX_CLASS3
+config POWER_AVS_OMAP_CLASS3
 	bool "Class 3 mode of Smartreflex Implementation"
-	depends on OMAP_SMARTREFLEX && TWL4030_CORE
+	depends on POWER_AVS_OMAP && TWL4030_CORE
 	help
 	  Say Y to enable Class 3 implementation of Smartreflex
 
 	  Class 3 implementation of Smartreflex employs continuous hardware
 	  voltage calibration.
 
+endif # POWER_AVS
+
 config OMAP_RESET_CLOCKS
 	bool "Reset unused clocks during boot"
 	depends on ARCH_OMAP
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 9/9] ARM: OMAP: SmartReflex: Move smartreflex driver to drivers/
  2012-03-19 16:12 [PATCH v2 0/9] PM: Create the AVS class of drivers jean.pihet
                   ` (7 preceding siblings ...)
  2012-03-19 16:12 ` [PATCH 8/9] ARM: OMAP2+: SmartReflex: add POWER_AVS Kconfig options jean.pihet
@ 2012-03-19 16:12 ` jean.pihet
  2012-04-18 18:17   ` Kevin Hilman
  2012-04-03 11:14 ` [PATCH v2 0/9] PM: Create the AVS class of drivers Jean Pihet
                   ` (3 subsequent siblings)
  12 siblings, 1 reply; 31+ messages in thread
From: jean.pihet @ 2012-03-19 16:12 UTC (permalink / raw)
  To: linux-omap, linux-arm-kernel, Kevin Hilman, Rafael J. Wysocki, LKML
  Cc: Jean Pihet

From: Jean Pihet <j-pihet@ti.com>

After a clean-up of the interfaces the OMAP IP driver and class
support code is now a generic driver.
Move it to drivers/power/avs/.

The build is controlled by the following Kconfig options:
 . CONFIG_POWER_AVS: general knob for Adaptive Voltage Scaling support,
 . CONFIG_POWER_AVS_OMAP: AVS support on OMAP containing the version 1
    or version 2 of the SmartReflex IP,
 . CONFIG_POWER_AVS_OMAP_CLASS3: Class 3 implementation of Smartreflex.

Signed-off-by: Jean Pihet <j-pihet@ti.com>
---
 arch/arm/mach-omap2/Makefile             |    3 +-
 arch/arm/mach-omap2/smartreflex-class3.c |   61 --
 arch/arm/mach-omap2/smartreflex.c        | 1120 ------------------------------
 arch/arm/mach-omap2/smartreflex.h        |  238 -------
 arch/arm/plat-omap/Kconfig               |   19 +-
 drivers/power/Kconfig                    |    2 +
 drivers/power/Makefile                   |    2 +
 drivers/power/avs/Kconfig                |   12 +
 drivers/power/avs/Makefile               |    2 +
 drivers/power/avs/smartreflex-class3.c   |   61 ++
 drivers/power/avs/smartreflex.c          | 1118 +++++++++++++++++++++++++++++
 drivers/power/avs/smartreflex.h          |  238 +++++++
 12 files changed, 1437 insertions(+), 1439 deletions(-)
 delete mode 100644 arch/arm/mach-omap2/smartreflex-class3.c
 delete mode 100644 arch/arm/mach-omap2/smartreflex.c
 delete mode 100644 arch/arm/mach-omap2/smartreflex.h
 create mode 100644 drivers/power/avs/Kconfig
 create mode 100644 drivers/power/avs/Makefile
 create mode 100644 drivers/power/avs/smartreflex-class3.c
 create mode 100644 drivers/power/avs/smartreflex.c
 create mode 100644 drivers/power/avs/smartreflex.h

diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile
index 30666fd..bb23056 100644
--- a/arch/arm/mach-omap2/Makefile
+++ b/arch/arm/mach-omap2/Makefile
@@ -69,8 +69,7 @@ obj-$(CONFIG_ARCH_OMAP4)		+= pm44xx.o omap-mpuss-lowpower.o \
 					   cpuidle44xx.o
 obj-$(CONFIG_PM_DEBUG)			+= pm-debug.o
 
-obj-$(CONFIG_POWER_AVS_OMAP)		+= sr_device.o smartreflex.o
-obj-$(CONFIG_POWER_AVS_OMAP_CLASS3)	+= smartreflex-class3.o
+obj-$(CONFIG_POWER_AVS_OMAP)		+= sr_device.o
 
 AFLAGS_sleep24xx.o			:=-Wa,-march=armv6
 AFLAGS_sleep34xx.o			:=-Wa,-march=armv7-a$(plus_sec)
diff --git a/arch/arm/mach-omap2/smartreflex-class3.c b/arch/arm/mach-omap2/smartreflex-class3.c
deleted file mode 100644
index f63c950..0000000
--- a/arch/arm/mach-omap2/smartreflex-class3.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Smart reflex Class 3 specific implementations
- *
- * Author: Thara Gopinath       <thara@ti.com>
- *
- * Copyright (C) 2010 Texas Instruments, Inc.
- * Thara Gopinath <thara@ti.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#include "smartreflex.h"
-#include "voltage.h"
-
-static int sr_class3_enable(struct omap_sr *sr)
-{
-	unsigned long volt = voltdm_get_voltage(sr->voltdm);
-
-	if (!volt) {
-		pr_warning("%s: Curr voltage unknown. Cannot enable %s\n",
-				__func__, sr->name);
-		return -ENODATA;
-	}
-
-	omap_vp_enable(sr->voltdm);
-	return sr_enable(sr->voltdm, volt);
-}
-
-static int sr_class3_disable(struct omap_sr *sr, int is_volt_reset)
-{
-	sr_disable_errgen(sr->voltdm);
-	omap_vp_disable(sr->voltdm);
-	sr_disable(sr->voltdm);
-	if (is_volt_reset)
-		voltdm_reset(sr->voltdm);
-
-	return 0;
-}
-
-static int sr_class3_configure(struct omap_sr *sr)
-{
-	return sr_configure_errgen(sr->voltdm);
-}
-
-/* SR class3 structure */
-static struct omap_sr_class_data class3_data = {
-	.enable = sr_class3_enable,
-	.disable = sr_class3_disable,
-	.configure = sr_class3_configure,
-	.class_type = SR_CLASS3,
-};
-
-/* Smartreflex Class3 init API to be called from board file */
-static int __init sr_class3_init(void)
-{
-	pr_info("SmartReflex Class3 initialized\n");
-	return sr_register_class(&class3_data);
-}
-late_initcall(sr_class3_init);
diff --git a/arch/arm/mach-omap2/smartreflex.c b/arch/arm/mach-omap2/smartreflex.c
deleted file mode 100644
index 71f70ca..0000000
--- a/arch/arm/mach-omap2/smartreflex.c
+++ /dev/null
@@ -1,1120 +0,0 @@
-/*
- * OMAP SmartReflex Voltage Control
- *
- * Author: Thara Gopinath	<thara@ti.com>
- *
- * Copyright (C) 2010 Texas Instruments, Inc.
- * Thara Gopinath <thara@ti.com>
- *
- * Copyright (C) 2008 Nokia Corporation
- * Kalle Jokiniemi
- *
- * Copyright (C) 2007 Texas Instruments, Inc.
- * Lesly A M <x0080970@ti.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#include <linux/module.h>
-#include <linux/interrupt.h>
-#include <linux/clk.h>
-#include <linux/io.h>
-#include <linux/debugfs.h>
-#include <linux/delay.h>
-#include <linux/slab.h>
-#include <linux/pm_runtime.h>
-#include <linux/power/smartreflex.h>
-
-#include "common.h"
-#include "pm.h"
-#include "smartreflex.h"
-
-#define SMARTREFLEX_NAME_LEN	16
-#define NVALUE_NAME_LEN		40
-#define SR_DISABLE_TIMEOUT	200
-
-/* sr_list contains all the instances of smartreflex module */
-static LIST_HEAD(sr_list);
-
-static struct omap_sr_class_data *sr_class;
-static struct omap_sr_pmic_data *sr_pmic_data;
-static struct dentry		*sr_dbg_dir;
-
-static inline void sr_write_reg(struct omap_sr *sr, unsigned offset, u32 value)
-{
-	__raw_writel(value, (sr->base + offset));
-}
-
-static inline void sr_modify_reg(struct omap_sr *sr, unsigned offset, u32 mask,
-					u32 value)
-{
-	u32 reg_val;
-
-	/*
-	 * Smartreflex error config register is special as it contains
-	 * certain status bits which if written a 1 into means a clear
-	 * of those bits. So in order to make sure no accidental write of
-	 * 1 happens to those status bits, do a clear of them in the read
-	 * value. This mean this API doesn't rewrite values in these bits
-	 * if they are currently set, but does allow the caller to write
-	 * those bits.
-	 */
-	if (sr->ip_type == SR_TYPE_V1 && offset == ERRCONFIG_V1)
-		mask |= ERRCONFIG_STATUS_V1_MASK;
-	else if (sr->ip_type == SR_TYPE_V2 && offset == ERRCONFIG_V2)
-		mask |= ERRCONFIG_VPBOUNDINTST_V2;
-
-	reg_val = __raw_readl(sr->base + offset);
-	reg_val &= ~mask;
-
-	value &= mask;
-
-	reg_val |= value;
-
-	__raw_writel(reg_val, (sr->base + offset));
-}
-
-static inline u32 sr_read_reg(struct omap_sr *sr, unsigned offset)
-{
-	return __raw_readl(sr->base + offset);
-}
-
-static struct omap_sr *_sr_lookup(struct voltagedomain *voltdm)
-{
-	struct omap_sr *sr_info;
-
-	if (!voltdm) {
-		pr_err("%s: Null voltage domain passed!\n", __func__);
-		return ERR_PTR(-EINVAL);
-	}
-
-	list_for_each_entry(sr_info, &sr_list, node) {
-		if (voltdm == sr_info->voltdm)
-			return sr_info;
-	}
-
-	return ERR_PTR(-ENODATA);
-}
-
-static irqreturn_t sr_interrupt(int irq, void *data)
-{
-	struct omap_sr *sr_info = data;
-	u32 status = 0;
-
-	switch (sr_info->ip_type) {
-	case SR_TYPE_V1:
-		/* Read the status bits */
-		status = sr_read_reg(sr_info, ERRCONFIG_V1);
-
-		/* Clear them by writing back */
-		sr_write_reg(sr_info, ERRCONFIG_V1, status);
-		break;
-	case SR_TYPE_V2:
-		/* Read the status bits */
-		status = sr_read_reg(sr_info, IRQSTATUS);
-
-		/* Clear them by writing back */
-		sr_write_reg(sr_info, IRQSTATUS, status);
-		break;
-	default:
-		dev_err(&sr_info->pdev->dev, "UNKNOWN IP type %d\n",
-			sr_info->ip_type);
-		return IRQ_NONE;
-	}
-
-	if (sr_class->notify)
-		sr_class->notify(sr_info, status);
-
-	return IRQ_HANDLED;
-}
-
-static void sr_set_clk_length(struct omap_sr *sr)
-{
-	struct clk *sys_ck;
-	u32 sys_clk_speed;
-
-	if (cpu_is_omap34xx())
-		sys_ck = clk_get(NULL, "sys_ck");
-	else
-		sys_ck = clk_get(NULL, "sys_clkin_ck");
-
-	if (IS_ERR(sys_ck)) {
-		dev_err(&sr->pdev->dev, "%s: unable to get sys clk\n",
-			__func__);
-		return;
-	}
-
-	sys_clk_speed = clk_get_rate(sys_ck);
-	clk_put(sys_ck);
-
-	switch (sys_clk_speed) {
-	case 12000000:
-		sr->clk_length = SRCLKLENGTH_12MHZ_SYSCLK;
-		break;
-	case 13000000:
-		sr->clk_length = SRCLKLENGTH_13MHZ_SYSCLK;
-		break;
-	case 19200000:
-		sr->clk_length = SRCLKLENGTH_19MHZ_SYSCLK;
-		break;
-	case 26000000:
-		sr->clk_length = SRCLKLENGTH_26MHZ_SYSCLK;
-		break;
-	case 38400000:
-		sr->clk_length = SRCLKLENGTH_38MHZ_SYSCLK;
-		break;
-	default:
-		dev_err(&sr->pdev->dev, "%s: Invalid sysclk value: %d\n",
-			__func__, sys_clk_speed);
-		break;
-	}
-}
-
-static void sr_set_regfields(struct omap_sr *sr)
-{
-	/*
-	 * For time being these values are defined in smartreflex.h
-	 * and populated during init. May be they can be moved to board
-	 * file or pmic specific data structure. In that case these structure
-	 * fields will have to be populated using the pdata or pmic structure.
-	 */
-	if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
-		sr->err_weight = OMAP3430_SR_ERRWEIGHT;
-		sr->err_maxlimit = OMAP3430_SR_ERRMAXLIMIT;
-		sr->accum_data = OMAP3430_SR_ACCUMDATA;
-		if (!(strcmp(sr->name, "sr_mpu_iva"))) {
-			sr->senn_avgweight = OMAP3430_SR1_SENNAVGWEIGHT;
-			sr->senp_avgweight = OMAP3430_SR1_SENPAVGWEIGHT;
-		} else {
-			sr->senn_avgweight = OMAP3430_SR2_SENNAVGWEIGHT;
-			sr->senp_avgweight = OMAP3430_SR2_SENPAVGWEIGHT;
-		}
-	}
-}
-
-static void sr_start_vddautocomp(struct omap_sr *sr)
-{
-	if (!sr_class || !(sr_class->enable) || !(sr_class->configure)) {
-		dev_warn(&sr->pdev->dev,
-			"%s: smartreflex class driver not registered\n",
-			__func__);
-		return;
-	}
-
-	if (!sr_class->enable(sr))
-		sr->autocomp_active = true;
-}
-
-static void sr_stop_vddautocomp(struct omap_sr *sr)
-{
-	if (!sr_class || !(sr_class->disable)) {
-		dev_warn(&sr->pdev->dev,
-			"%s: smartreflex class driver not registered\n",
-			__func__);
-		return;
-	}
-
-	if (sr->autocomp_active) {
-		sr_class->disable(sr, 1);
-		sr->autocomp_active = false;
-	}
-}
-
-/*
- * This function handles the intializations which have to be done
- * only when both sr device and class driver regiter has
- * completed. This will be attempted to be called from both sr class
- * driver register and sr device intializtion API's. Only one call
- * will ultimately succeed.
- *
- * Currently this function registers interrupt handler for a particular SR
- * if smartreflex class driver is already registered and has
- * requested for interrupts and the SR interrupt line in present.
- */
-static int sr_late_init(struct omap_sr *sr_info)
-{
-	struct omap_sr_data *pdata = sr_info->pdev->dev.platform_data;
-	struct resource *mem;
-	int ret = 0;
-
-	if (sr_class->notify && sr_class->notify_flags && sr_info->irq) {
-		ret = request_irq(sr_info->irq, sr_interrupt,
-				  0, sr_info->name, sr_info);
-		if (ret)
-			goto error;
-		disable_irq(sr_info->irq);
-	}
-
-	if (pdata && pdata->enable_on_init)
-		sr_start_vddautocomp(sr_info);
-
-	return ret;
-
-error:
-	iounmap(sr_info->base);
-	mem = platform_get_resource(sr_info->pdev, IORESOURCE_MEM, 0);
-	release_mem_region(mem->start, resource_size(mem));
-	list_del(&sr_info->node);
-	dev_err(&sr_info->pdev->dev, "%s: ERROR in registering"
-		"interrupt handler. Smartreflex will"
-		"not function as desired\n", __func__);
-	kfree(sr_info);
-
-	return ret;
-}
-
-static void sr_v1_disable(struct omap_sr *sr)
-{
-	int timeout = 0;
-	int errconf_val = ERRCONFIG_MCUACCUMINTST | ERRCONFIG_MCUVALIDINTST |
-			ERRCONFIG_MCUBOUNDINTST;
-
-	/* Enable MCUDisableAcknowledge interrupt */
-	sr_modify_reg(sr, ERRCONFIG_V1,
-			ERRCONFIG_MCUDISACKINTEN, ERRCONFIG_MCUDISACKINTEN);
-
-	/* SRCONFIG - disable SR */
-	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SRENABLE, 0x0);
-
-	/* Disable all other SR interrupts and clear the status as needed */
-	if (sr_read_reg(sr, ERRCONFIG_V1) & ERRCONFIG_VPBOUNDINTST_V1)
-		errconf_val |= ERRCONFIG_VPBOUNDINTST_V1;
-	sr_modify_reg(sr, ERRCONFIG_V1,
-			(ERRCONFIG_MCUACCUMINTEN | ERRCONFIG_MCUVALIDINTEN |
-			ERRCONFIG_MCUBOUNDINTEN | ERRCONFIG_VPBOUNDINTEN_V1),
-			errconf_val);
-
-	/*
-	 * Wait for SR to be disabled.
-	 * wait until ERRCONFIG.MCUDISACKINTST = 1. Typical latency is 1us.
-	 */
-	sr_test_cond_timeout((sr_read_reg(sr, ERRCONFIG_V1) &
-			     ERRCONFIG_MCUDISACKINTST), SR_DISABLE_TIMEOUT,
-			     timeout);
-
-	if (timeout >= SR_DISABLE_TIMEOUT)
-		dev_warn(&sr->pdev->dev, "%s: Smartreflex disable timedout\n",
-			__func__);
-
-	/* Disable MCUDisableAcknowledge interrupt & clear pending interrupt */
-	sr_modify_reg(sr, ERRCONFIG_V1, ERRCONFIG_MCUDISACKINTEN,
-			ERRCONFIG_MCUDISACKINTST);
-}
-
-static void sr_v2_disable(struct omap_sr *sr)
-{
-	int timeout = 0;
-
-	/* Enable MCUDisableAcknowledge interrupt */
-	sr_write_reg(sr, IRQENABLE_SET, IRQENABLE_MCUDISABLEACKINT);
-
-	/* SRCONFIG - disable SR */
-	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SRENABLE, 0x0);
-
-	/*
-	 * Disable all other SR interrupts and clear the status
-	 * write to status register ONLY on need basis - only if status
-	 * is set.
-	 */
-	if (sr_read_reg(sr, ERRCONFIG_V2) & ERRCONFIG_VPBOUNDINTST_V2)
-		sr_modify_reg(sr, ERRCONFIG_V2, ERRCONFIG_VPBOUNDINTEN_V2,
-			ERRCONFIG_VPBOUNDINTST_V2);
-	else
-		sr_modify_reg(sr, ERRCONFIG_V2, ERRCONFIG_VPBOUNDINTEN_V2,
-				0x0);
-	sr_write_reg(sr, IRQENABLE_CLR, (IRQENABLE_MCUACCUMINT |
-			IRQENABLE_MCUVALIDINT |
-			IRQENABLE_MCUBOUNDSINT));
-	sr_write_reg(sr, IRQSTATUS, (IRQSTATUS_MCUACCUMINT |
-			IRQSTATUS_MCVALIDINT |
-			IRQSTATUS_MCBOUNDSINT));
-
-	/*
-	 * Wait for SR to be disabled.
-	 * wait until IRQSTATUS.MCUDISACKINTST = 1. Typical latency is 1us.
-	 */
-	sr_test_cond_timeout((sr_read_reg(sr, IRQSTATUS) &
-			     IRQSTATUS_MCUDISABLEACKINT), SR_DISABLE_TIMEOUT,
-			     timeout);
-
-	if (timeout >= SR_DISABLE_TIMEOUT)
-		dev_warn(&sr->pdev->dev, "%s: Smartreflex disable timedout\n",
-			__func__);
-
-	/* Disable MCUDisableAcknowledge interrupt & clear pending interrupt */
-	sr_write_reg(sr, IRQENABLE_CLR, IRQENABLE_MCUDISABLEACKINT);
-	sr_write_reg(sr, IRQSTATUS, IRQSTATUS_MCUDISABLEACKINT);
-}
-
-static struct omap_sr_nvalue_table *sr_retrieve_nvalue_row(
-				struct omap_sr *sr,
-				unsigned long volt_nominal)
-{
-	int i;
-
-	if (!sr->nvalue_table) {
-		dev_warn(&sr->pdev->dev, "%s: Missing ntarget value table\n",
-			__func__);
-		return NULL;
-	}
-
-	for (i = 0; i < sr->nvalue_count; i++) {
-		if (sr->nvalue_table[i].volt_nominal == volt_nominal)
-			return &sr->nvalue_table[i];
-	}
-
-	return NULL;
-}
-
-/* Public Functions */
-
-/**
- * sr_configure_errgen() - Configures the smrtreflex to perform AVS using the
- *			 error generator module.
- * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
- *
- * This API is to be called from the smartreflex class driver to
- * configure the error generator module inside the smartreflex module.
- * SR settings if using the ERROR module inside Smartreflex.
- * SR CLASS 3 by default uses only the ERROR module where as
- * SR CLASS 2 can choose between ERROR module and MINMAXAVG
- * module. Returns 0 on success and error value in case of failure.
- */
-int sr_configure_errgen(struct voltagedomain *voltdm)
-{
-	u32 sr_config, sr_errconfig, errconfig_offs;
-	u32 vpboundint_en, vpboundint_st;
-	u32 senp_en = 0, senn_en = 0;
-	u8 senp_shift, senn_shift;
-	struct omap_sr *sr = _sr_lookup(voltdm);
-
-	if (IS_ERR(sr)) {
-		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
-		return PTR_ERR(sr);
-	}
-
-	if (!sr->clk_length)
-		sr_set_clk_length(sr);
-
-	senp_en = sr->senp_mod;
-	senn_en = sr->senn_mod;
-
-	sr_config = (sr->clk_length << SRCONFIG_SRCLKLENGTH_SHIFT) |
-		SRCONFIG_SENENABLE | SRCONFIG_ERRGEN_EN;
-
-	switch (sr->ip_type) {
-	case SR_TYPE_V1:
-		sr_config |= SRCONFIG_DELAYCTRL;
-		senn_shift = SRCONFIG_SENNENABLE_V1_SHIFT;
-		senp_shift = SRCONFIG_SENPENABLE_V1_SHIFT;
-		errconfig_offs = ERRCONFIG_V1;
-		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V1;
-		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V1;
-		break;
-	case SR_TYPE_V2:
-		senn_shift = SRCONFIG_SENNENABLE_V2_SHIFT;
-		senp_shift = SRCONFIG_SENPENABLE_V2_SHIFT;
-		errconfig_offs = ERRCONFIG_V2;
-		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V2;
-		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V2;
-		break;
-	default:
-		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex"
-			"module without specifying the ip\n", __func__);
-		return -EINVAL;
-	}
-
-	sr_config |= ((senn_en << senn_shift) | (senp_en << senp_shift));
-	sr_write_reg(sr, SRCONFIG, sr_config);
-	sr_errconfig = (sr->err_weight << ERRCONFIG_ERRWEIGHT_SHIFT) |
-		(sr->err_maxlimit << ERRCONFIG_ERRMAXLIMIT_SHIFT) |
-		(sr->err_minlimit <<  ERRCONFIG_ERRMINLIMIT_SHIFT);
-	sr_modify_reg(sr, errconfig_offs, (SR_ERRWEIGHT_MASK |
-		SR_ERRMAXLIMIT_MASK | SR_ERRMINLIMIT_MASK),
-		sr_errconfig);
-
-	/* Enabling the interrupts if the ERROR module is used */
-	sr_modify_reg(sr, errconfig_offs, (vpboundint_en | vpboundint_st),
-		      vpboundint_en);
-
-	return 0;
-}
-
-/**
- * sr_disable_errgen() - Disables SmartReflex AVS module's errgen component
- * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
- *
- * This API is to be called from the smartreflex class driver to
- * disable the error generator module inside the smartreflex module.
- *
- * Returns 0 on success and error value in case of failure.
- */
-int sr_disable_errgen(struct voltagedomain *voltdm)
-{
-	u32 errconfig_offs;
-	u32 vpboundint_en, vpboundint_st;
-	struct omap_sr *sr = _sr_lookup(voltdm);
-
-	if (IS_ERR(sr)) {
-		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
-		return PTR_ERR(sr);
-	}
-
-	switch (sr->ip_type) {
-	case SR_TYPE_V1:
-		errconfig_offs = ERRCONFIG_V1;
-		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V1;
-		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V1;
-		break;
-	case SR_TYPE_V2:
-		errconfig_offs = ERRCONFIG_V2;
-		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V2;
-		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V2;
-		break;
-	default:
-		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex"
-			"module without specifying the ip\n", __func__);
-		return -EINVAL;
-	}
-
-	/* Disable the interrupts of ERROR module */
-	sr_modify_reg(sr, errconfig_offs, vpboundint_en | vpboundint_st, 0);
-
-	/* Disable the Sensor and errorgen */
-	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SENENABLE | SRCONFIG_ERRGEN_EN, 0);
-
-	return 0;
-}
-
-/**
- * sr_configure_minmax() - Configures the smrtreflex to perform AVS using the
- *			 minmaxavg module.
- * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
- *
- * This API is to be called from the smartreflex class driver to
- * configure the minmaxavg module inside the smartreflex module.
- * SR settings if using the ERROR module inside Smartreflex.
- * SR CLASS 3 by default uses only the ERROR module where as
- * SR CLASS 2 can choose between ERROR module and MINMAXAVG
- * module. Returns 0 on success and error value in case of failure.
- */
-int sr_configure_minmax(struct voltagedomain *voltdm)
-{
-	u32 sr_config, sr_avgwt;
-	u32 senp_en = 0, senn_en = 0;
-	u8 senp_shift, senn_shift;
-	struct omap_sr *sr = _sr_lookup(voltdm);
-
-	if (IS_ERR(sr)) {
-		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
-		return PTR_ERR(sr);
-	}
-
-	if (!sr->clk_length)
-		sr_set_clk_length(sr);
-
-	senp_en = sr->senp_mod;
-	senn_en = sr->senn_mod;
-
-	sr_config = (sr->clk_length << SRCONFIG_SRCLKLENGTH_SHIFT) |
-		SRCONFIG_SENENABLE |
-		(sr->accum_data << SRCONFIG_ACCUMDATA_SHIFT);
-
-	switch (sr->ip_type) {
-	case SR_TYPE_V1:
-		sr_config |= SRCONFIG_DELAYCTRL;
-		senn_shift = SRCONFIG_SENNENABLE_V1_SHIFT;
-		senp_shift = SRCONFIG_SENPENABLE_V1_SHIFT;
-		break;
-	case SR_TYPE_V2:
-		senn_shift = SRCONFIG_SENNENABLE_V2_SHIFT;
-		senp_shift = SRCONFIG_SENPENABLE_V2_SHIFT;
-		break;
-	default:
-		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex"
-			"module without specifying the ip\n", __func__);
-		return -EINVAL;
-	}
-
-	sr_config |= ((senn_en << senn_shift) | (senp_en << senp_shift));
-	sr_write_reg(sr, SRCONFIG, sr_config);
-	sr_avgwt = (sr->senp_avgweight << AVGWEIGHT_SENPAVGWEIGHT_SHIFT) |
-		(sr->senn_avgweight << AVGWEIGHT_SENNAVGWEIGHT_SHIFT);
-	sr_write_reg(sr, AVGWEIGHT, sr_avgwt);
-
-	/*
-	 * Enabling the interrupts if MINMAXAVG module is used.
-	 * TODO: check if all the interrupts are mandatory
-	 */
-	switch (sr->ip_type) {
-	case SR_TYPE_V1:
-		sr_modify_reg(sr, ERRCONFIG_V1,
-			(ERRCONFIG_MCUACCUMINTEN | ERRCONFIG_MCUVALIDINTEN |
-			ERRCONFIG_MCUBOUNDINTEN),
-			(ERRCONFIG_MCUACCUMINTEN | ERRCONFIG_MCUACCUMINTST |
-			 ERRCONFIG_MCUVALIDINTEN | ERRCONFIG_MCUVALIDINTST |
-			 ERRCONFIG_MCUBOUNDINTEN | ERRCONFIG_MCUBOUNDINTST));
-		break;
-	case SR_TYPE_V2:
-		sr_write_reg(sr, IRQSTATUS,
-			IRQSTATUS_MCUACCUMINT | IRQSTATUS_MCVALIDINT |
-			IRQSTATUS_MCBOUNDSINT | IRQSTATUS_MCUDISABLEACKINT);
-		sr_write_reg(sr, IRQENABLE_SET,
-			IRQENABLE_MCUACCUMINT | IRQENABLE_MCUVALIDINT |
-			IRQENABLE_MCUBOUNDSINT | IRQENABLE_MCUDISABLEACKINT);
-		break;
-	default:
-		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex"
-			"module without specifying the ip\n", __func__);
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
-/**
- * sr_enable() - Enables the smartreflex module.
- * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
- * @volt:	The voltage at which the Voltage domain associated with
- *		the smartreflex module is operating at.
- *		This is required only to program the correct Ntarget value.
- *
- * This API is to be called from the smartreflex class driver to
- * enable a smartreflex module. Returns 0 on success. Returns error
- * value if the voltage passed is wrong or if ntarget value is wrong.
- */
-int sr_enable(struct voltagedomain *voltdm, unsigned long volt)
-{
-	struct omap_sr *sr = _sr_lookup(voltdm);
-	struct omap_sr_nvalue_table *nvalue_row;
-	int ret;
-
-	if (IS_ERR(sr)) {
-		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
-		return PTR_ERR(sr);
-	}
-
-	nvalue_row = sr_retrieve_nvalue_row(sr, volt);
-	if (!nvalue_row) {
-		dev_warn(&sr->pdev->dev, "%s: failure getting SR data for this voltage %ld\n",
-			 __func__, volt);
-		return -ENODATA;
-	}
-
-
-	/* errminlimit is opp dependent and hence linked to voltage */
-	sr->err_minlimit = nvalue_row->errminlimit;
-
-	pm_runtime_get_sync(&sr->pdev->dev);
-
-	/* Check if SR is already enabled. If yes do nothing */
-	if (sr_read_reg(sr, SRCONFIG) & SRCONFIG_SRENABLE)
-		return 0;
-
-	/* Configure SR */
-	ret = sr_class->configure(sr);
-	if (ret)
-		return ret;
-
-	sr_write_reg(sr, NVALUERECIPROCAL, nvalue_row->nvalue);
-
-	/* SRCONFIG - enable SR */
-	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SRENABLE, SRCONFIG_SRENABLE);
-	return 0;
-}
-
-/**
- * sr_disable() - Disables the smartreflex module.
- * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
- *
- * This API is to be called from the smartreflex class driver to
- * disable a smartreflex module.
- */
-void sr_disable(struct voltagedomain *voltdm)
-{
-	struct omap_sr *sr = _sr_lookup(voltdm);
-
-	if (IS_ERR(sr)) {
-		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
-		return;
-	}
-
-	/* Check if SR clocks are already disabled. If yes do nothing */
-	if (pm_runtime_suspended(&sr->pdev->dev))
-		return;
-
-	/*
-	 * Disable SR if only it is indeed enabled. Else just
-	 * disable the clocks.
-	 */
-	if (sr_read_reg(sr, SRCONFIG) & SRCONFIG_SRENABLE) {
-		switch (sr->ip_type) {
-		case SR_TYPE_V1:
-			sr_v1_disable(sr);
-			break;
-		case SR_TYPE_V2:
-			sr_v2_disable(sr);
-			break;
-		default:
-			dev_err(&sr->pdev->dev, "UNKNOWN IP type %d\n",
-				sr->ip_type);
-		}
-	}
-
-	pm_runtime_put_sync_suspend(&sr->pdev->dev);
-}
-
-/**
- * sr_register_class() - API to register a smartreflex class parameters.
- * @class_data:	The structure containing various sr class specific data.
- *
- * This API is to be called by the smartreflex class driver to register itself
- * with the smartreflex driver during init. Returns 0 on success else the
- * error value.
- */
-int sr_register_class(struct omap_sr_class_data *class_data)
-{
-	struct omap_sr *sr_info;
-
-	if (!class_data) {
-		pr_warning("%s:, Smartreflex class data passed is NULL\n",
-			__func__);
-		return -EINVAL;
-	}
-
-	if (sr_class) {
-		pr_warning("%s: Smartreflex class driver already registered\n",
-			__func__);
-		return -EBUSY;
-	}
-
-	sr_class = class_data;
-
-	/*
-	 * Call into late init to do intializations that require
-	 * both sr driver and sr class driver to be initiallized.
-	 */
-	list_for_each_entry(sr_info, &sr_list, node)
-		sr_late_init(sr_info);
-
-	return 0;
-}
-
-/**
- * omap_sr_enable() -  API to enable SR clocks and to call into the
- *			registered smartreflex class enable API.
- * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
- *
- * This API is to be called from the kernel in order to enable
- * a particular smartreflex module. This API will do the initial
- * configurations to turn on the smartreflex module and in turn call
- * into the registered smartreflex class enable API.
- */
-void omap_sr_enable(struct voltagedomain *voltdm)
-{
-	struct omap_sr *sr = _sr_lookup(voltdm);
-
-	if (IS_ERR(sr)) {
-		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
-		return;
-	}
-
-	if (!sr->autocomp_active)
-		return;
-
-	if (!sr_class || !(sr_class->enable) || !(sr_class->configure)) {
-		dev_warn(&sr->pdev->dev, "%s: smartreflex class driver not"
-			"registered\n", __func__);
-		return;
-	}
-
-	sr_class->enable(sr);
-}
-
-/**
- * omap_sr_disable() - API to disable SR without resetting the voltage
- *			processor voltage
- * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
- *
- * This API is to be called from the kernel in order to disable
- * a particular smartreflex module. This API will in turn call
- * into the registered smartreflex class disable API. This API will tell
- * the smartreflex class disable not to reset the VP voltage after
- * disabling smartreflex.
- */
-void omap_sr_disable(struct voltagedomain *voltdm)
-{
-	struct omap_sr *sr = _sr_lookup(voltdm);
-
-	if (IS_ERR(sr)) {
-		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
-		return;
-	}
-
-	if (!sr->autocomp_active)
-		return;
-
-	if (!sr_class || !(sr_class->disable)) {
-		dev_warn(&sr->pdev->dev, "%s: smartreflex class driver not"
-			"registered\n", __func__);
-		return;
-	}
-
-	sr_class->disable(sr, 0);
-}
-
-/**
- * omap_sr_disable_reset_volt() - API to disable SR and reset the
- *				voltage processor voltage
- * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
- *
- * This API is to be called from the kernel in order to disable
- * a particular smartreflex module. This API will in turn call
- * into the registered smartreflex class disable API. This API will tell
- * the smartreflex class disable to reset the VP voltage after
- * disabling smartreflex.
- */
-void omap_sr_disable_reset_volt(struct voltagedomain *voltdm)
-{
-	struct omap_sr *sr = _sr_lookup(voltdm);
-
-	if (IS_ERR(sr)) {
-		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
-		return;
-	}
-
-	if (!sr->autocomp_active)
-		return;
-
-	if (!sr_class || !(sr_class->disable)) {
-		dev_warn(&sr->pdev->dev, "%s: smartreflex class driver not"
-			"registered\n", __func__);
-		return;
-	}
-
-	sr_class->disable(sr, 1);
-}
-
-/**
- * omap_sr_register_pmic() - API to register pmic specific info.
- * @pmic_data:	The structure containing pmic specific data.
- *
- * This API is to be called from the PMIC specific code to register with
- * smartreflex driver pmic specific info. Currently the only info required
- * is the smartreflex init on the PMIC side.
- */
-void omap_sr_register_pmic(struct omap_sr_pmic_data *pmic_data)
-{
-	if (!pmic_data) {
-		pr_warning("%s: Trying to register NULL PMIC data structure"
-			"with smartreflex\n", __func__);
-		return;
-	}
-
-	sr_pmic_data = pmic_data;
-}
-
-/* PM Debug FS entries to enable and disable smartreflex. */
-static int omap_sr_autocomp_show(void *data, u64 *val)
-{
-	struct omap_sr *sr_info = data;
-
-	if (!sr_info) {
-		pr_warning("%s: omap_sr struct not found\n", __func__);
-		return -EINVAL;
-	}
-
-	*val = sr_info->autocomp_active;
-
-	return 0;
-}
-
-static int omap_sr_autocomp_store(void *data, u64 val)
-{
-	struct omap_sr *sr_info = data;
-
-	if (!sr_info) {
-		pr_warning("%s: omap_sr struct not found\n", __func__);
-		return -EINVAL;
-	}
-
-	/* Sanity check */
-	if (val > 1) {
-		pr_warning("%s: Invalid argument %lld\n", __func__, val);
-		return -EINVAL;
-	}
-
-	/* control enable/disable only if there is a delta in value */
-	if (sr_info->autocomp_active != val) {
-		if (!val)
-			sr_stop_vddautocomp(sr_info);
-		else
-			sr_start_vddautocomp(sr_info);
-	}
-
-	return 0;
-}
-
-DEFINE_SIMPLE_ATTRIBUTE(pm_sr_fops, omap_sr_autocomp_show,
-			omap_sr_autocomp_store, "%llu\n");
-
-static int __init omap_sr_probe(struct platform_device *pdev)
-{
-	struct omap_sr *sr_info;
-	struct omap_sr_data *pdata = pdev->dev.platform_data;
-	struct resource *mem, *irq;
-	struct dentry *nvalue_dir;
-	int i, ret = 0;
-
-	sr_info = kzalloc(sizeof(struct omap_sr), GFP_KERNEL);
-	if (!sr_info) {
-		dev_err(&pdev->dev, "%s: unable to allocate sr_info\n",
-			__func__);
-		return -ENOMEM;
-	}
-
-	platform_set_drvdata(pdev, sr_info);
-
-	if (!pdata) {
-		dev_err(&pdev->dev, "%s: platform data missing\n", __func__);
-		ret = -EINVAL;
-		goto err_free_devinfo;
-	}
-
-	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!mem) {
-		dev_err(&pdev->dev, "%s: no mem resource\n", __func__);
-		ret = -ENODEV;
-		goto err_free_devinfo;
-	}
-
-	mem = request_mem_region(mem->start, resource_size(mem),
-					dev_name(&pdev->dev));
-	if (!mem) {
-		dev_err(&pdev->dev, "%s: no mem region\n", __func__);
-		ret = -EBUSY;
-		goto err_free_devinfo;
-	}
-
-	irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-
-	pm_runtime_enable(&pdev->dev);
-	pm_runtime_irq_safe(&pdev->dev);
-
-	sr_info->name = kasprintf(GFP_KERNEL, "sr_%s", pdata->name);
-	if (!sr_info->name) {
-		dev_err(&pdev->dev, "%s: Unable to alloc SR instance name\n",
-			__func__);
-		ret = -ENOMEM;
-		goto err_release_region;
-	}
-
-	sr_info->pdev = pdev;
-	sr_info->srid = pdev->id;
-	sr_info->voltdm = pdata->voltdm;
-	sr_info->nvalue_table = pdata->nvalue_table;
-	sr_info->nvalue_count = pdata->nvalue_count;
-	sr_info->senn_mod = pdata->senn_mod;
-	sr_info->senp_mod = pdata->senp_mod;
-	sr_info->autocomp_active = false;
-	sr_info->ip_type = pdata->ip_type;
-	sr_info->base = ioremap(mem->start, resource_size(mem));
-	if (!sr_info->base) {
-		dev_err(&pdev->dev, "%s: ioremap fail\n", __func__);
-		ret = -ENOMEM;
-		goto err_release_region;
-	}
-
-	if (irq)
-		sr_info->irq = irq->start;
-
-	sr_set_clk_length(sr_info);
-	sr_set_regfields(sr_info);
-
-	list_add(&sr_info->node, &sr_list);
-
-	/*
-	 * Call into late init to do intializations that require
-	 * both sr driver and sr class driver to be initiallized.
-	 */
-	if (sr_class) {
-		ret = sr_late_init(sr_info);
-		if (ret) {
-			pr_warning("%s: Error in SR late init\n", __func__);
-			goto err_iounmap;
-		}
-	}
-
-	dev_info(&pdev->dev, "%s: SmartReflex driver initialized\n", __func__);
-	if (!sr_dbg_dir) {
-		sr_dbg_dir = debugfs_create_dir("smartreflex", NULL);
-		if (IS_ERR_OR_NULL(sr_dbg_dir)) {
-			ret = PTR_ERR(sr_dbg_dir);
-			pr_err("%s:sr debugfs dir creation failed(%d)\n",
-				__func__, ret);
-			goto err_iounmap;
-		}
-	}
-
-	sr_info->dbg_dir = debugfs_create_dir(sr_info->name, sr_dbg_dir);
-	if (IS_ERR_OR_NULL(sr_info->dbg_dir)) {
-		dev_err(&pdev->dev, "%s: Unable to create debugfs directory\n",
-			__func__);
-		ret = PTR_ERR(sr_info->dbg_dir);
-		goto err_free_name;
-	}
-
-	(void) debugfs_create_file("autocomp", S_IRUGO | S_IWUSR,
-			sr_info->dbg_dir, (void *)sr_info, &pm_sr_fops);
-	(void) debugfs_create_x32("errweight", S_IRUGO, sr_info->dbg_dir,
-			&sr_info->err_weight);
-	(void) debugfs_create_x32("errmaxlimit", S_IRUGO, sr_info->dbg_dir,
-			&sr_info->err_maxlimit);
-
-	nvalue_dir = debugfs_create_dir("nvalue", sr_info->dbg_dir);
-	if (IS_ERR_OR_NULL(nvalue_dir)) {
-		dev_err(&pdev->dev, "%s: Unable to create debugfs directory"
-			"for n-values\n", __func__);
-		ret = PTR_ERR(nvalue_dir);
-		goto err_debugfs;
-	}
-
-	if (sr_info->nvalue_count == 0 || !sr_info->nvalue_table) {
-		dev_warn(&pdev->dev, "%s: %s: No Voltage table for the corresponding vdd. Cannot create debugfs entries for n-values\n",
-			 __func__, sr_info->name);
-		ret = -ENODATA;
-		goto err_debugfs;
-	}
-
-	for (i = 0; i < sr_info->nvalue_count; i++) {
-		char name[NVALUE_NAME_LEN + 1];
-
-		snprintf(name, sizeof(name), "volt_%lu",
-			 sr_info->nvalue_table[i].volt_nominal);
-		(void) debugfs_create_x32(name, S_IRUGO | S_IWUSR, nvalue_dir,
-				&(sr_info->nvalue_table[i].nvalue));
-		snprintf(name, sizeof(name), "errminlimit_%lu",
-			 sr_info->nvalue_table[i].volt_nominal);
-		(void) debugfs_create_x32(name, S_IRUGO | S_IWUSR, nvalue_dir,
-				&(sr_info->nvalue_table[i].errminlimit));
-	}
-
-	return ret;
-
-err_debugfs:
-	debugfs_remove_recursive(sr_info->dbg_dir);
-err_free_name:
-	kfree(sr_info->name);
-err_iounmap:
-	list_del(&sr_info->node);
-	iounmap(sr_info->base);
-err_release_region:
-	release_mem_region(mem->start, resource_size(mem));
-err_free_devinfo:
-	kfree(sr_info);
-
-	return ret;
-}
-
-static int __devexit omap_sr_remove(struct platform_device *pdev)
-{
-	struct omap_sr_data *pdata = pdev->dev.platform_data;
-	struct omap_sr *sr_info;
-	struct resource *mem;
-
-	if (!pdata) {
-		dev_err(&pdev->dev, "%s: platform data missing\n", __func__);
-		return -EINVAL;
-	}
-
-	sr_info = _sr_lookup(pdata->voltdm);
-	if (IS_ERR(sr_info)) {
-		dev_warn(&pdev->dev, "%s: omap_sr struct not found\n",
-			__func__);
-		return PTR_ERR(sr_info);
-	}
-
-	if (sr_info->autocomp_active)
-		sr_stop_vddautocomp(sr_info);
-	if (sr_info->dbg_dir)
-		debugfs_remove_recursive(sr_info->dbg_dir);
-
-	list_del(&sr_info->node);
-	iounmap(sr_info->base);
-	kfree(sr_info->name);
-	kfree(sr_info);
-	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	release_mem_region(mem->start, resource_size(mem));
-
-	return 0;
-}
-
-static void __devexit omap_sr_shutdown(struct platform_device *pdev)
-{
-	struct omap_sr_data *pdata = pdev->dev.platform_data;
-	struct omap_sr *sr_info;
-
-	if (!pdata) {
-		dev_err(&pdev->dev, "%s: platform data missing\n", __func__);
-		return;
-	}
-
-	sr_info = _sr_lookup(pdata->voltdm);
-	if (IS_ERR(sr_info)) {
-		dev_warn(&pdev->dev, "%s: omap_sr struct not found\n",
-			__func__);
-		return;
-	}
-
-	if (sr_info->autocomp_active)
-		sr_stop_vddautocomp(sr_info);
-
-	return;
-}
-
-static struct platform_driver smartreflex_driver = {
-	.remove         = __devexit_p(omap_sr_remove),
-	.shutdown	= __devexit_p(omap_sr_shutdown),
-	.driver		= {
-		.name	= "smartreflex",
-	},
-};
-
-static int __init sr_init(void)
-{
-	int ret = 0;
-
-	/*
-	 * sr_init is a late init. If by then a pmic specific API is not
-	 * registered either there is no need for anything to be done on
-	 * the PMIC side or somebody has forgotten to register a PMIC
-	 * handler. Warn for the second condition.
-	 */
-	if (sr_pmic_data && sr_pmic_data->sr_pmic_init)
-		sr_pmic_data->sr_pmic_init();
-	else
-		pr_warning("%s: No PMIC hook to init smartreflex\n", __func__);
-
-	ret = platform_driver_probe(&smartreflex_driver, omap_sr_probe);
-	if (ret) {
-		pr_err("%s: platform driver register failed for SR\n",
-			__func__);
-		return ret;
-	}
-
-	return 0;
-}
-late_initcall(sr_init);
-
-static void __exit sr_exit(void)
-{
-	platform_driver_unregister(&smartreflex_driver);
-}
-module_exit(sr_exit);
-
-MODULE_DESCRIPTION("OMAP Smartreflex Driver");
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("platform:" DRIVER_NAME);
-MODULE_AUTHOR("Texas Instruments Inc");
diff --git a/arch/arm/mach-omap2/smartreflex.h b/arch/arm/mach-omap2/smartreflex.h
deleted file mode 100644
index 754f6aa..0000000
--- a/arch/arm/mach-omap2/smartreflex.h
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * OMAP Smartreflex Defines and Routines
- *
- * Author: Thara Gopinath	<thara@ti.com>
- *
- * Copyright (C) 2010 Texas Instruments, Inc.
- * Thara Gopinath <thara@ti.com>
- *
- * Copyright (C) 2008 Nokia Corporation
- * Kalle Jokiniemi
- *
- * Copyright (C) 2007 Texas Instruments, Inc.
- * Lesly A M <x0080970@ti.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#ifndef __DRIVERS_POWER_AVS_SMARTREFLEX_H
-#define __DRIVERS_POWER_AVS_SMARTREFLEX_H
-
-#include <linux/platform_device.h>
-#include <linux/delay.h>
-#include <linux/power/smartreflex.h>
-
-#include <plat/voltage.h>
-
-/*
- * Different Smartreflex IPs version. The v1 is the 65nm version used in
- * OMAP3430. The v2 is the update for the 45nm version of the IP
- * used in OMAP3630 and OMAP4430
- */
-#define SR_TYPE_V1	1
-#define SR_TYPE_V2	2
-
-/* SMART REFLEX REG ADDRESS OFFSET */
-#define SRCONFIG		0x00
-#define SRSTATUS		0x04
-#define SENVAL			0x08
-#define SENMIN			0x0C
-#define SENMAX			0x10
-#define SENAVG			0x14
-#define AVGWEIGHT		0x18
-#define NVALUERECIPROCAL	0x1c
-#define SENERROR_V1		0x20
-#define ERRCONFIG_V1		0x24
-#define IRQ_EOI			0x20
-#define IRQSTATUS_RAW		0x24
-#define IRQSTATUS		0x28
-#define IRQENABLE_SET		0x2C
-#define IRQENABLE_CLR		0x30
-#define SENERROR_V2		0x34
-#define ERRCONFIG_V2		0x38
-
-/* Bit/Shift Positions */
-
-/* SRCONFIG */
-#define SRCONFIG_ACCUMDATA_SHIFT	22
-#define SRCONFIG_SRCLKLENGTH_SHIFT	12
-#define SRCONFIG_SENNENABLE_V1_SHIFT	5
-#define SRCONFIG_SENPENABLE_V1_SHIFT	3
-#define SRCONFIG_SENNENABLE_V2_SHIFT	1
-#define SRCONFIG_SENPENABLE_V2_SHIFT	0
-#define SRCONFIG_CLKCTRL_SHIFT		0
-
-#define SRCONFIG_ACCUMDATA_MASK		(0x3ff << 22)
-
-#define SRCONFIG_SRENABLE		BIT(11)
-#define SRCONFIG_SENENABLE		BIT(10)
-#define SRCONFIG_ERRGEN_EN		BIT(9)
-#define SRCONFIG_MINMAXAVG_EN		BIT(8)
-#define SRCONFIG_DELAYCTRL		BIT(2)
-
-/* AVGWEIGHT */
-#define AVGWEIGHT_SENPAVGWEIGHT_SHIFT	2
-#define AVGWEIGHT_SENNAVGWEIGHT_SHIFT	0
-
-/* NVALUERECIPROCAL */
-#define NVALUERECIPROCAL_SENPGAIN_SHIFT	20
-#define NVALUERECIPROCAL_SENNGAIN_SHIFT	16
-#define NVALUERECIPROCAL_RNSENP_SHIFT	8
-#define NVALUERECIPROCAL_RNSENN_SHIFT	0
-
-/* ERRCONFIG */
-#define ERRCONFIG_ERRWEIGHT_SHIFT	16
-#define ERRCONFIG_ERRMAXLIMIT_SHIFT	8
-#define ERRCONFIG_ERRMINLIMIT_SHIFT	0
-
-#define SR_ERRWEIGHT_MASK		(0x07 << 16)
-#define SR_ERRMAXLIMIT_MASK		(0xff << 8)
-#define SR_ERRMINLIMIT_MASK		(0xff << 0)
-
-#define ERRCONFIG_VPBOUNDINTEN_V1	BIT(31)
-#define ERRCONFIG_VPBOUNDINTST_V1	BIT(30)
-#define	ERRCONFIG_MCUACCUMINTEN		BIT(29)
-#define ERRCONFIG_MCUACCUMINTST		BIT(28)
-#define	ERRCONFIG_MCUVALIDINTEN		BIT(27)
-#define ERRCONFIG_MCUVALIDINTST		BIT(26)
-#define ERRCONFIG_MCUBOUNDINTEN		BIT(25)
-#define	ERRCONFIG_MCUBOUNDINTST		BIT(24)
-#define	ERRCONFIG_MCUDISACKINTEN	BIT(23)
-#define ERRCONFIG_VPBOUNDINTST_V2	BIT(23)
-#define ERRCONFIG_MCUDISACKINTST	BIT(22)
-#define ERRCONFIG_VPBOUNDINTEN_V2	BIT(22)
-
-#define ERRCONFIG_STATUS_V1_MASK	(ERRCONFIG_VPBOUNDINTST_V1 | \
-					ERRCONFIG_MCUACCUMINTST | \
-					ERRCONFIG_MCUVALIDINTST | \
-					ERRCONFIG_MCUBOUNDINTST | \
-					ERRCONFIG_MCUDISACKINTST)
-/* IRQSTATUS */
-#define IRQSTATUS_MCUACCUMINT		BIT(3)
-#define IRQSTATUS_MCVALIDINT		BIT(2)
-#define IRQSTATUS_MCBOUNDSINT		BIT(1)
-#define IRQSTATUS_MCUDISABLEACKINT	BIT(0)
-
-/* IRQENABLE_SET and IRQENABLE_CLEAR */
-#define IRQENABLE_MCUACCUMINT		BIT(3)
-#define IRQENABLE_MCUVALIDINT		BIT(2)
-#define IRQENABLE_MCUBOUNDSINT		BIT(1)
-#define IRQENABLE_MCUDISABLEACKINT	BIT(0)
-
-/* Common Bit values */
-
-#define SRCLKLENGTH_12MHZ_SYSCLK	0x3c
-#define SRCLKLENGTH_13MHZ_SYSCLK	0x41
-#define SRCLKLENGTH_19MHZ_SYSCLK	0x60
-#define SRCLKLENGTH_26MHZ_SYSCLK	0x82
-#define SRCLKLENGTH_38MHZ_SYSCLK	0xC0
-
-/*
- * 3430 specific values. Maybe these should be passed from board file or
- * pmic structures.
- */
-#define OMAP3430_SR_ACCUMDATA		0x1f4
-
-#define OMAP3430_SR1_SENPAVGWEIGHT	0x03
-#define OMAP3430_SR1_SENNAVGWEIGHT	0x03
-
-#define OMAP3430_SR2_SENPAVGWEIGHT	0x01
-#define OMAP3430_SR2_SENNAVGWEIGHT	0x01
-
-#define OMAP3430_SR_ERRWEIGHT		0x04
-#define OMAP3430_SR_ERRMAXLIMIT		0x02
-
-/**
- * test_cond_timeout - busy-loop, testing a condition
- * @cond: condition to test until it evaluates to true
- * @timeout: maximum number of microseconds in the timeout
- * @index: loop index (integer)
- *
- * Loop waiting for @cond to become true or until at least @timeout
- * microseconds have passed.  To use, define some integer @index in the
- * calling code.  After running, if @index == @timeout, then the loop has
- * timed out.
- *
- * Copied from omap_test_timeout
- */
-#define sr_test_cond_timeout(cond, timeout, index)		\
-({								\
-	for (index = 0; index < timeout; index++) {		\
-		if (cond)					\
-			break;					\
-		udelay(1);					\
-	}							\
-})
-
-/**
- * struct omap_sr_pmic_data - Strucutre to be populated by pmic code to pass
- *				pmic specific info to smartreflex driver
- *
- * @sr_pmic_init:	API to initialize smartreflex on the PMIC side.
- */
-struct omap_sr_pmic_data {
-	void (*sr_pmic_init) (void);
-};
-
-
-#ifdef CONFIG_POWER_AVS_OMAP
-/*
- * The smart reflex driver supports CLASS1 CLASS2 and CLASS3 SR.
- * The smartreflex class driver should pass the class type.
- * Should be used to populate the class_type field of the
- * omap_smartreflex_class_data structure.
- */
-#define SR_CLASS1	0x1
-#define SR_CLASS2	0x2
-#define SR_CLASS3	0x3
-
-/**
- * struct omap_sr_class_data - Smartreflex class driver info
- *
- * @enable:		API to enable a particular class smaartreflex.
- * @disable:		API to disable a particular class smartreflex.
- * @configure:		API to configure a particular class smartreflex.
- * @notify:		API to notify the class driver about an event in SR.
- *			Not needed for class3.
- * @notify_flags:	specify the events to be notified to the class driver
- * @class_type:		specify which smartreflex class.
- *			Can be used by the SR driver to take any class
- *			based decisions.
- */
-struct omap_sr_class_data {
-	int (*enable)(struct omap_sr *sr);
-	int (*disable)(struct omap_sr *sr, int is_volt_reset);
-	int (*configure)(struct omap_sr *sr);
-	int (*notify)(struct omap_sr *sr, u32 status);
-	u8 notify_flags;
-	u8 class_type;
-};
-
-/* Smartreflex module enable/disable interface */
-void omap_sr_enable(struct voltagedomain *voltdm);
-void omap_sr_disable(struct voltagedomain *voltdm);
-void omap_sr_disable_reset_volt(struct voltagedomain *voltdm);
-
-/* API to register the pmic specific data with the smartreflex driver. */
-void omap_sr_register_pmic(struct omap_sr_pmic_data *pmic_data);
-
-/* Smartreflex driver hooks to be called from Smartreflex class driver */
-int sr_enable(struct voltagedomain *voltdm, unsigned long volt);
-void sr_disable(struct voltagedomain *voltdm);
-int sr_configure_errgen(struct voltagedomain *voltdm);
-int sr_disable_errgen(struct voltagedomain *voltdm);
-int sr_configure_minmax(struct voltagedomain *voltdm);
-
-/* API to register the smartreflex class driver with the smartreflex driver */
-int sr_register_class(struct omap_sr_class_data *class_data);
-#else
-static inline void omap_sr_enable(struct voltagedomain *voltdm) {}
-static inline void omap_sr_disable(struct voltagedomain *voltdm) {}
-static inline void omap_sr_disable_reset_volt(
-		struct voltagedomain *voltdm) {}
-static inline void omap_sr_register_pmic(
-		struct omap_sr_pmic_data *pmic_data) {}
-#endif
-#endif
diff --git a/arch/arm/plat-omap/Kconfig b/arch/arm/plat-omap/Kconfig
index 6ec9237..85f70e6 100644
--- a/arch/arm/plat-omap/Kconfig
+++ b/arch/arm/plat-omap/Kconfig
@@ -44,24 +44,9 @@ config OMAP_DEBUG_LEDS
 	depends on OMAP_DEBUG_DEVICES
 	default y if LEDS_CLASS
 
-menuconfig POWER_AVS
-	tristate "Adaptive Voltage Scaling class support"
-	help
-	  AVS is a power management technique which finely controls the
-	  operating voltage of a device in order to optimize (i.e. reduce)
-	  its power consumption.
-	  At a given operating point the voltage is adapted depending on
-	  static factors (chip manufacturing process) and dynamic factors
-	  (temperature depending performance).
-	  AVS is also called SmartReflex on OMAP devices.
-
-	  Say Y here to enable Adaptive Voltage Scaling class support.
-
-if POWER_AVS
-
 config POWER_AVS_OMAP
 	bool "AVS support for the OMAP IP versions 1&2"
-	depends on (ARCH_OMAP3 || ARCH_OMAP4) && PM
+	depends on POWER_AVS && (ARCH_OMAP3 || ARCH_OMAP4) && PM
 	help
 	  Say Y to enable AVS support on OMAP containing the version 1 or
 	  version 2 of the SmartReflex IP.
@@ -88,8 +73,6 @@ config POWER_AVS_OMAP_CLASS3
 	  Class 3 implementation of Smartreflex employs continuous hardware
 	  voltage calibration.
 
-endif # POWER_AVS
-
 config OMAP_RESET_CLOCKS
 	bool "Reset unused clocks during boot"
 	depends on ARCH_OMAP
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 3a8daf8..06f991e 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -275,3 +275,5 @@ config CHARGER_MAX8998
 	  platform data of MAX8998/LP3974 PMICs.
 
 endif # POWER_SUPPLY
+
+source "drivers/power/avs/Kconfig"
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index e429008..e4a8fd2 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -41,3 +41,5 @@ obj-$(CONFIG_CHARGER_GPIO)	+= gpio-charger.o
 obj-$(CONFIG_CHARGER_MANAGER)	+= charger-manager.o
 obj-$(CONFIG_CHARGER_MAX8997)	+= max8997_charger.o
 obj-$(CONFIG_CHARGER_MAX8998)	+= max8998_charger.o
+
+obj-$(CONFIG_POWER_AVS)		+= avs/
diff --git a/drivers/power/avs/Kconfig b/drivers/power/avs/Kconfig
new file mode 100644
index 0000000..18493f7
--- /dev/null
+++ b/drivers/power/avs/Kconfig
@@ -0,0 +1,12 @@
+menuconfig POWER_AVS
+	tristate "Adaptive Voltage Scaling class support"
+	help
+	  AVS is a power management technique which finely controls the
+	  operating voltage of a device in order to optimize (i.e. reduce)
+	  its power consumption.
+	  At a given operating point the voltage is adapted depending on
+	  static factors (chip manufacturing process) and dynamic factors
+	  (temperature depending performance).
+	  AVS is also called SmartReflex on OMAP devices.
+
+	  Say Y here to enable Adaptive Voltage Scaling class support.
diff --git a/drivers/power/avs/Makefile b/drivers/power/avs/Makefile
new file mode 100644
index 0000000..ac72ec5
--- /dev/null
+++ b/drivers/power/avs/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_POWER_AVS_OMAP)		+= smartreflex.o
+obj-$(CONFIG_POWER_AVS_OMAP_CLASS3)	+= smartreflex-class3.o
diff --git a/drivers/power/avs/smartreflex-class3.c b/drivers/power/avs/smartreflex-class3.c
new file mode 100644
index 0000000..413a07b
--- /dev/null
+++ b/drivers/power/avs/smartreflex-class3.c
@@ -0,0 +1,61 @@
+/*
+ * Smart reflex Class 3 specific implementations
+ *
+ * Author: Thara Gopinath       <thara@ti.com>
+ *
+ * Copyright (C) 2010 Texas Instruments, Inc.
+ * Thara Gopinath <thara@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "smartreflex.h"
+#include <plat/voltage.h>
+
+static int sr_class3_enable(struct omap_sr *sr)
+{
+	unsigned long volt = voltdm_get_voltage(sr->voltdm);
+
+	if (!volt) {
+		pr_warning("%s: Curr voltage unknown. Cannot enable %s\n",
+				__func__, sr->name);
+		return -ENODATA;
+	}
+
+	omap_vp_enable(sr->voltdm);
+	return sr_enable(sr->voltdm, volt);
+}
+
+static int sr_class3_disable(struct omap_sr *sr, int is_volt_reset)
+{
+	sr_disable_errgen(sr->voltdm);
+	omap_vp_disable(sr->voltdm);
+	sr_disable(sr->voltdm);
+	if (is_volt_reset)
+		voltdm_reset(sr->voltdm);
+
+	return 0;
+}
+
+static int sr_class3_configure(struct omap_sr *sr)
+{
+	return sr_configure_errgen(sr->voltdm);
+}
+
+/* SR class3 structure */
+static struct omap_sr_class_data class3_data = {
+	.enable = sr_class3_enable,
+	.disable = sr_class3_disable,
+	.configure = sr_class3_configure,
+	.class_type = SR_CLASS3,
+};
+
+/* Smartreflex Class3 init API to be called from board file */
+static int __init sr_class3_init(void)
+{
+	pr_info("SmartReflex Class3 initialized\n");
+	return sr_register_class(&class3_data);
+}
+late_initcall(sr_class3_init);
diff --git a/drivers/power/avs/smartreflex.c b/drivers/power/avs/smartreflex.c
new file mode 100644
index 0000000..d3973cb
--- /dev/null
+++ b/drivers/power/avs/smartreflex.c
@@ -0,0 +1,1118 @@
+/*
+ * OMAP SmartReflex Voltage Control
+ *
+ * Author: Thara Gopinath	<thara@ti.com>
+ *
+ * Copyright (C) 2010 Texas Instruments, Inc.
+ * Thara Gopinath <thara@ti.com>
+ *
+ * Copyright (C) 2008 Nokia Corporation
+ * Kalle Jokiniemi
+ *
+ * Copyright (C) 2007 Texas Instruments, Inc.
+ * Lesly A M <x0080970@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/debugfs.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/pm_runtime.h>
+#include <linux/power/smartreflex.h>
+
+#include "smartreflex.h"
+
+#define SMARTREFLEX_NAME_LEN	16
+#define NVALUE_NAME_LEN		40
+#define SR_DISABLE_TIMEOUT	200
+
+/* sr_list contains all the instances of smartreflex module */
+static LIST_HEAD(sr_list);
+
+static struct omap_sr_class_data *sr_class;
+static struct omap_sr_pmic_data *sr_pmic_data;
+static struct dentry		*sr_dbg_dir;
+
+static inline void sr_write_reg(struct omap_sr *sr, unsigned offset, u32 value)
+{
+	__raw_writel(value, (sr->base + offset));
+}
+
+static inline void sr_modify_reg(struct omap_sr *sr, unsigned offset, u32 mask,
+					u32 value)
+{
+	u32 reg_val;
+
+	/*
+	 * Smartreflex error config register is special as it contains
+	 * certain status bits which if written a 1 into means a clear
+	 * of those bits. So in order to make sure no accidental write of
+	 * 1 happens to those status bits, do a clear of them in the read
+	 * value. This mean this API doesn't rewrite values in these bits
+	 * if they are currently set, but does allow the caller to write
+	 * those bits.
+	 */
+	if (sr->ip_type == SR_TYPE_V1 && offset == ERRCONFIG_V1)
+		mask |= ERRCONFIG_STATUS_V1_MASK;
+	else if (sr->ip_type == SR_TYPE_V2 && offset == ERRCONFIG_V2)
+		mask |= ERRCONFIG_VPBOUNDINTST_V2;
+
+	reg_val = __raw_readl(sr->base + offset);
+	reg_val &= ~mask;
+
+	value &= mask;
+
+	reg_val |= value;
+
+	__raw_writel(reg_val, (sr->base + offset));
+}
+
+static inline u32 sr_read_reg(struct omap_sr *sr, unsigned offset)
+{
+	return __raw_readl(sr->base + offset);
+}
+
+static struct omap_sr *_sr_lookup(struct voltagedomain *voltdm)
+{
+	struct omap_sr *sr_info;
+
+	if (!voltdm) {
+		pr_err("%s: Null voltage domain passed!\n", __func__);
+		return ERR_PTR(-EINVAL);
+	}
+
+	list_for_each_entry(sr_info, &sr_list, node) {
+		if (voltdm == sr_info->voltdm)
+			return sr_info;
+	}
+
+	return ERR_PTR(-ENODATA);
+}
+
+static irqreturn_t sr_interrupt(int irq, void *data)
+{
+	struct omap_sr *sr_info = data;
+	u32 status = 0;
+
+	switch (sr_info->ip_type) {
+	case SR_TYPE_V1:
+		/* Read the status bits */
+		status = sr_read_reg(sr_info, ERRCONFIG_V1);
+
+		/* Clear them by writing back */
+		sr_write_reg(sr_info, ERRCONFIG_V1, status);
+		break;
+	case SR_TYPE_V2:
+		/* Read the status bits */
+		status = sr_read_reg(sr_info, IRQSTATUS);
+
+		/* Clear them by writing back */
+		sr_write_reg(sr_info, IRQSTATUS, status);
+		break;
+	default:
+		dev_err(&sr_info->pdev->dev, "UNKNOWN IP type %d\n",
+			sr_info->ip_type);
+		return IRQ_NONE;
+	}
+
+	if (sr_class->notify)
+		sr_class->notify(sr_info, status);
+
+	return IRQ_HANDLED;
+}
+
+static void sr_set_clk_length(struct omap_sr *sr)
+{
+	struct clk *sys_ck;
+	u32 sys_clk_speed;
+
+	if (cpu_is_omap34xx())
+		sys_ck = clk_get(NULL, "sys_ck");
+	else
+		sys_ck = clk_get(NULL, "sys_clkin_ck");
+
+	if (IS_ERR(sys_ck)) {
+		dev_err(&sr->pdev->dev, "%s: unable to get sys clk\n",
+			__func__);
+		return;
+	}
+
+	sys_clk_speed = clk_get_rate(sys_ck);
+	clk_put(sys_ck);
+
+	switch (sys_clk_speed) {
+	case 12000000:
+		sr->clk_length = SRCLKLENGTH_12MHZ_SYSCLK;
+		break;
+	case 13000000:
+		sr->clk_length = SRCLKLENGTH_13MHZ_SYSCLK;
+		break;
+	case 19200000:
+		sr->clk_length = SRCLKLENGTH_19MHZ_SYSCLK;
+		break;
+	case 26000000:
+		sr->clk_length = SRCLKLENGTH_26MHZ_SYSCLK;
+		break;
+	case 38400000:
+		sr->clk_length = SRCLKLENGTH_38MHZ_SYSCLK;
+		break;
+	default:
+		dev_err(&sr->pdev->dev, "%s: Invalid sysclk value: %d\n",
+			__func__, sys_clk_speed);
+		break;
+	}
+}
+
+static void sr_set_regfields(struct omap_sr *sr)
+{
+	/*
+	 * For time being these values are defined in smartreflex.h
+	 * and populated during init. May be they can be moved to board
+	 * file or pmic specific data structure. In that case these structure
+	 * fields will have to be populated using the pdata or pmic structure.
+	 */
+	if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
+		sr->err_weight = OMAP3430_SR_ERRWEIGHT;
+		sr->err_maxlimit = OMAP3430_SR_ERRMAXLIMIT;
+		sr->accum_data = OMAP3430_SR_ACCUMDATA;
+		if (!(strcmp(sr->name, "sr_mpu_iva"))) {
+			sr->senn_avgweight = OMAP3430_SR1_SENNAVGWEIGHT;
+			sr->senp_avgweight = OMAP3430_SR1_SENPAVGWEIGHT;
+		} else {
+			sr->senn_avgweight = OMAP3430_SR2_SENNAVGWEIGHT;
+			sr->senp_avgweight = OMAP3430_SR2_SENPAVGWEIGHT;
+		}
+	}
+}
+
+static void sr_start_vddautocomp(struct omap_sr *sr)
+{
+	if (!sr_class || !(sr_class->enable) || !(sr_class->configure)) {
+		dev_warn(&sr->pdev->dev,
+			"%s: smartreflex class driver not registered\n",
+			__func__);
+		return;
+	}
+
+	if (!sr_class->enable(sr))
+		sr->autocomp_active = true;
+}
+
+static void sr_stop_vddautocomp(struct omap_sr *sr)
+{
+	if (!sr_class || !(sr_class->disable)) {
+		dev_warn(&sr->pdev->dev,
+			"%s: smartreflex class driver not registered\n",
+			__func__);
+		return;
+	}
+
+	if (sr->autocomp_active) {
+		sr_class->disable(sr, 1);
+		sr->autocomp_active = false;
+	}
+}
+
+/*
+ * This function handles the intializations which have to be done
+ * only when both sr device and class driver regiter has
+ * completed. This will be attempted to be called from both sr class
+ * driver register and sr device intializtion API's. Only one call
+ * will ultimately succeed.
+ *
+ * Currently this function registers interrupt handler for a particular SR
+ * if smartreflex class driver is already registered and has
+ * requested for interrupts and the SR interrupt line in present.
+ */
+static int sr_late_init(struct omap_sr *sr_info)
+{
+	struct omap_sr_data *pdata = sr_info->pdev->dev.platform_data;
+	struct resource *mem;
+	int ret = 0;
+
+	if (sr_class->notify && sr_class->notify_flags && sr_info->irq) {
+		ret = request_irq(sr_info->irq, sr_interrupt,
+				  0, sr_info->name, sr_info);
+		if (ret)
+			goto error;
+		disable_irq(sr_info->irq);
+	}
+
+	if (pdata && pdata->enable_on_init)
+		sr_start_vddautocomp(sr_info);
+
+	return ret;
+
+error:
+	iounmap(sr_info->base);
+	mem = platform_get_resource(sr_info->pdev, IORESOURCE_MEM, 0);
+	release_mem_region(mem->start, resource_size(mem));
+	list_del(&sr_info->node);
+	dev_err(&sr_info->pdev->dev, "%s: ERROR in registering"
+		"interrupt handler. Smartreflex will"
+		"not function as desired\n", __func__);
+	kfree(sr_info);
+
+	return ret;
+}
+
+static void sr_v1_disable(struct omap_sr *sr)
+{
+	int timeout = 0;
+	int errconf_val = ERRCONFIG_MCUACCUMINTST | ERRCONFIG_MCUVALIDINTST |
+			ERRCONFIG_MCUBOUNDINTST;
+
+	/* Enable MCUDisableAcknowledge interrupt */
+	sr_modify_reg(sr, ERRCONFIG_V1,
+			ERRCONFIG_MCUDISACKINTEN, ERRCONFIG_MCUDISACKINTEN);
+
+	/* SRCONFIG - disable SR */
+	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SRENABLE, 0x0);
+
+	/* Disable all other SR interrupts and clear the status as needed */
+	if (sr_read_reg(sr, ERRCONFIG_V1) & ERRCONFIG_VPBOUNDINTST_V1)
+		errconf_val |= ERRCONFIG_VPBOUNDINTST_V1;
+	sr_modify_reg(sr, ERRCONFIG_V1,
+			(ERRCONFIG_MCUACCUMINTEN | ERRCONFIG_MCUVALIDINTEN |
+			ERRCONFIG_MCUBOUNDINTEN | ERRCONFIG_VPBOUNDINTEN_V1),
+			errconf_val);
+
+	/*
+	 * Wait for SR to be disabled.
+	 * wait until ERRCONFIG.MCUDISACKINTST = 1. Typical latency is 1us.
+	 */
+	sr_test_cond_timeout((sr_read_reg(sr, ERRCONFIG_V1) &
+			     ERRCONFIG_MCUDISACKINTST), SR_DISABLE_TIMEOUT,
+			     timeout);
+
+	if (timeout >= SR_DISABLE_TIMEOUT)
+		dev_warn(&sr->pdev->dev, "%s: Smartreflex disable timedout\n",
+			__func__);
+
+	/* Disable MCUDisableAcknowledge interrupt & clear pending interrupt */
+	sr_modify_reg(sr, ERRCONFIG_V1, ERRCONFIG_MCUDISACKINTEN,
+			ERRCONFIG_MCUDISACKINTST);
+}
+
+static void sr_v2_disable(struct omap_sr *sr)
+{
+	int timeout = 0;
+
+	/* Enable MCUDisableAcknowledge interrupt */
+	sr_write_reg(sr, IRQENABLE_SET, IRQENABLE_MCUDISABLEACKINT);
+
+	/* SRCONFIG - disable SR */
+	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SRENABLE, 0x0);
+
+	/*
+	 * Disable all other SR interrupts and clear the status
+	 * write to status register ONLY on need basis - only if status
+	 * is set.
+	 */
+	if (sr_read_reg(sr, ERRCONFIG_V2) & ERRCONFIG_VPBOUNDINTST_V2)
+		sr_modify_reg(sr, ERRCONFIG_V2, ERRCONFIG_VPBOUNDINTEN_V2,
+			ERRCONFIG_VPBOUNDINTST_V2);
+	else
+		sr_modify_reg(sr, ERRCONFIG_V2, ERRCONFIG_VPBOUNDINTEN_V2,
+				0x0);
+	sr_write_reg(sr, IRQENABLE_CLR, (IRQENABLE_MCUACCUMINT |
+			IRQENABLE_MCUVALIDINT |
+			IRQENABLE_MCUBOUNDSINT));
+	sr_write_reg(sr, IRQSTATUS, (IRQSTATUS_MCUACCUMINT |
+			IRQSTATUS_MCVALIDINT |
+			IRQSTATUS_MCBOUNDSINT));
+
+	/*
+	 * Wait for SR to be disabled.
+	 * wait until IRQSTATUS.MCUDISACKINTST = 1. Typical latency is 1us.
+	 */
+	sr_test_cond_timeout((sr_read_reg(sr, IRQSTATUS) &
+			     IRQSTATUS_MCUDISABLEACKINT), SR_DISABLE_TIMEOUT,
+			     timeout);
+
+	if (timeout >= SR_DISABLE_TIMEOUT)
+		dev_warn(&sr->pdev->dev, "%s: Smartreflex disable timedout\n",
+			__func__);
+
+	/* Disable MCUDisableAcknowledge interrupt & clear pending interrupt */
+	sr_write_reg(sr, IRQENABLE_CLR, IRQENABLE_MCUDISABLEACKINT);
+	sr_write_reg(sr, IRQSTATUS, IRQSTATUS_MCUDISABLEACKINT);
+}
+
+static struct omap_sr_nvalue_table *sr_retrieve_nvalue_row(
+				struct omap_sr *sr,
+				unsigned long volt_nominal)
+{
+	int i;
+
+	if (!sr->nvalue_table) {
+		dev_warn(&sr->pdev->dev, "%s: Missing ntarget value table\n",
+			__func__);
+		return NULL;
+	}
+
+	for (i = 0; i < sr->nvalue_count; i++) {
+		if (sr->nvalue_table[i].volt_nominal == volt_nominal)
+			return &sr->nvalue_table[i];
+	}
+
+	return NULL;
+}
+
+/* Public Functions */
+
+/**
+ * sr_configure_errgen() - Configures the smrtreflex to perform AVS using the
+ *			 error generator module.
+ * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
+ *
+ * This API is to be called from the smartreflex class driver to
+ * configure the error generator module inside the smartreflex module.
+ * SR settings if using the ERROR module inside Smartreflex.
+ * SR CLASS 3 by default uses only the ERROR module where as
+ * SR CLASS 2 can choose between ERROR module and MINMAXAVG
+ * module. Returns 0 on success and error value in case of failure.
+ */
+int sr_configure_errgen(struct voltagedomain *voltdm)
+{
+	u32 sr_config, sr_errconfig, errconfig_offs;
+	u32 vpboundint_en, vpboundint_st;
+	u32 senp_en = 0, senn_en = 0;
+	u8 senp_shift, senn_shift;
+	struct omap_sr *sr = _sr_lookup(voltdm);
+
+	if (IS_ERR(sr)) {
+		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
+		return PTR_ERR(sr);
+	}
+
+	if (!sr->clk_length)
+		sr_set_clk_length(sr);
+
+	senp_en = sr->senp_mod;
+	senn_en = sr->senn_mod;
+
+	sr_config = (sr->clk_length << SRCONFIG_SRCLKLENGTH_SHIFT) |
+		SRCONFIG_SENENABLE | SRCONFIG_ERRGEN_EN;
+
+	switch (sr->ip_type) {
+	case SR_TYPE_V1:
+		sr_config |= SRCONFIG_DELAYCTRL;
+		senn_shift = SRCONFIG_SENNENABLE_V1_SHIFT;
+		senp_shift = SRCONFIG_SENPENABLE_V1_SHIFT;
+		errconfig_offs = ERRCONFIG_V1;
+		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V1;
+		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V1;
+		break;
+	case SR_TYPE_V2:
+		senn_shift = SRCONFIG_SENNENABLE_V2_SHIFT;
+		senp_shift = SRCONFIG_SENPENABLE_V2_SHIFT;
+		errconfig_offs = ERRCONFIG_V2;
+		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V2;
+		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V2;
+		break;
+	default:
+		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex"
+			"module without specifying the ip\n", __func__);
+		return -EINVAL;
+	}
+
+	sr_config |= ((senn_en << senn_shift) | (senp_en << senp_shift));
+	sr_write_reg(sr, SRCONFIG, sr_config);
+	sr_errconfig = (sr->err_weight << ERRCONFIG_ERRWEIGHT_SHIFT) |
+		(sr->err_maxlimit << ERRCONFIG_ERRMAXLIMIT_SHIFT) |
+		(sr->err_minlimit <<  ERRCONFIG_ERRMINLIMIT_SHIFT);
+	sr_modify_reg(sr, errconfig_offs, (SR_ERRWEIGHT_MASK |
+		SR_ERRMAXLIMIT_MASK | SR_ERRMINLIMIT_MASK),
+		sr_errconfig);
+
+	/* Enabling the interrupts if the ERROR module is used */
+	sr_modify_reg(sr, errconfig_offs, (vpboundint_en | vpboundint_st),
+		      vpboundint_en);
+
+	return 0;
+}
+
+/**
+ * sr_disable_errgen() - Disables SmartReflex AVS module's errgen component
+ * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
+ *
+ * This API is to be called from the smartreflex class driver to
+ * disable the error generator module inside the smartreflex module.
+ *
+ * Returns 0 on success and error value in case of failure.
+ */
+int sr_disable_errgen(struct voltagedomain *voltdm)
+{
+	u32 errconfig_offs;
+	u32 vpboundint_en, vpboundint_st;
+	struct omap_sr *sr = _sr_lookup(voltdm);
+
+	if (IS_ERR(sr)) {
+		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
+		return PTR_ERR(sr);
+	}
+
+	switch (sr->ip_type) {
+	case SR_TYPE_V1:
+		errconfig_offs = ERRCONFIG_V1;
+		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V1;
+		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V1;
+		break;
+	case SR_TYPE_V2:
+		errconfig_offs = ERRCONFIG_V2;
+		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V2;
+		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V2;
+		break;
+	default:
+		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex"
+			"module without specifying the ip\n", __func__);
+		return -EINVAL;
+	}
+
+	/* Disable the interrupts of ERROR module */
+	sr_modify_reg(sr, errconfig_offs, vpboundint_en | vpboundint_st, 0);
+
+	/* Disable the Sensor and errorgen */
+	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SENENABLE | SRCONFIG_ERRGEN_EN, 0);
+
+	return 0;
+}
+
+/**
+ * sr_configure_minmax() - Configures the smrtreflex to perform AVS using the
+ *			 minmaxavg module.
+ * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
+ *
+ * This API is to be called from the smartreflex class driver to
+ * configure the minmaxavg module inside the smartreflex module.
+ * SR settings if using the ERROR module inside Smartreflex.
+ * SR CLASS 3 by default uses only the ERROR module where as
+ * SR CLASS 2 can choose between ERROR module and MINMAXAVG
+ * module. Returns 0 on success and error value in case of failure.
+ */
+int sr_configure_minmax(struct voltagedomain *voltdm)
+{
+	u32 sr_config, sr_avgwt;
+	u32 senp_en = 0, senn_en = 0;
+	u8 senp_shift, senn_shift;
+	struct omap_sr *sr = _sr_lookup(voltdm);
+
+	if (IS_ERR(sr)) {
+		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
+		return PTR_ERR(sr);
+	}
+
+	if (!sr->clk_length)
+		sr_set_clk_length(sr);
+
+	senp_en = sr->senp_mod;
+	senn_en = sr->senn_mod;
+
+	sr_config = (sr->clk_length << SRCONFIG_SRCLKLENGTH_SHIFT) |
+		SRCONFIG_SENENABLE |
+		(sr->accum_data << SRCONFIG_ACCUMDATA_SHIFT);
+
+	switch (sr->ip_type) {
+	case SR_TYPE_V1:
+		sr_config |= SRCONFIG_DELAYCTRL;
+		senn_shift = SRCONFIG_SENNENABLE_V1_SHIFT;
+		senp_shift = SRCONFIG_SENPENABLE_V1_SHIFT;
+		break;
+	case SR_TYPE_V2:
+		senn_shift = SRCONFIG_SENNENABLE_V2_SHIFT;
+		senp_shift = SRCONFIG_SENPENABLE_V2_SHIFT;
+		break;
+	default:
+		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex"
+			"module without specifying the ip\n", __func__);
+		return -EINVAL;
+	}
+
+	sr_config |= ((senn_en << senn_shift) | (senp_en << senp_shift));
+	sr_write_reg(sr, SRCONFIG, sr_config);
+	sr_avgwt = (sr->senp_avgweight << AVGWEIGHT_SENPAVGWEIGHT_SHIFT) |
+		(sr->senn_avgweight << AVGWEIGHT_SENNAVGWEIGHT_SHIFT);
+	sr_write_reg(sr, AVGWEIGHT, sr_avgwt);
+
+	/*
+	 * Enabling the interrupts if MINMAXAVG module is used.
+	 * TODO: check if all the interrupts are mandatory
+	 */
+	switch (sr->ip_type) {
+	case SR_TYPE_V1:
+		sr_modify_reg(sr, ERRCONFIG_V1,
+			(ERRCONFIG_MCUACCUMINTEN | ERRCONFIG_MCUVALIDINTEN |
+			ERRCONFIG_MCUBOUNDINTEN),
+			(ERRCONFIG_MCUACCUMINTEN | ERRCONFIG_MCUACCUMINTST |
+			 ERRCONFIG_MCUVALIDINTEN | ERRCONFIG_MCUVALIDINTST |
+			 ERRCONFIG_MCUBOUNDINTEN | ERRCONFIG_MCUBOUNDINTST));
+		break;
+	case SR_TYPE_V2:
+		sr_write_reg(sr, IRQSTATUS,
+			IRQSTATUS_MCUACCUMINT | IRQSTATUS_MCVALIDINT |
+			IRQSTATUS_MCBOUNDSINT | IRQSTATUS_MCUDISABLEACKINT);
+		sr_write_reg(sr, IRQENABLE_SET,
+			IRQENABLE_MCUACCUMINT | IRQENABLE_MCUVALIDINT |
+			IRQENABLE_MCUBOUNDSINT | IRQENABLE_MCUDISABLEACKINT);
+		break;
+	default:
+		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex"
+			"module without specifying the ip\n", __func__);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/**
+ * sr_enable() - Enables the smartreflex module.
+ * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
+ * @volt:	The voltage at which the Voltage domain associated with
+ *		the smartreflex module is operating at.
+ *		This is required only to program the correct Ntarget value.
+ *
+ * This API is to be called from the smartreflex class driver to
+ * enable a smartreflex module. Returns 0 on success. Returns error
+ * value if the voltage passed is wrong or if ntarget value is wrong.
+ */
+int sr_enable(struct voltagedomain *voltdm, unsigned long volt)
+{
+	struct omap_sr *sr = _sr_lookup(voltdm);
+	struct omap_sr_nvalue_table *nvalue_row;
+	int ret;
+
+	if (IS_ERR(sr)) {
+		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
+		return PTR_ERR(sr);
+	}
+
+	nvalue_row = sr_retrieve_nvalue_row(sr, volt);
+	if (!nvalue_row) {
+		dev_warn(&sr->pdev->dev, "%s: failure getting SR data for this voltage %ld\n",
+			 __func__, volt);
+		return -ENODATA;
+	}
+
+
+	/* errminlimit is opp dependent and hence linked to voltage */
+	sr->err_minlimit = nvalue_row->errminlimit;
+
+	pm_runtime_get_sync(&sr->pdev->dev);
+
+	/* Check if SR is already enabled. If yes do nothing */
+	if (sr_read_reg(sr, SRCONFIG) & SRCONFIG_SRENABLE)
+		return 0;
+
+	/* Configure SR */
+	ret = sr_class->configure(sr);
+	if (ret)
+		return ret;
+
+	sr_write_reg(sr, NVALUERECIPROCAL, nvalue_row->nvalue);
+
+	/* SRCONFIG - enable SR */
+	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SRENABLE, SRCONFIG_SRENABLE);
+	return 0;
+}
+
+/**
+ * sr_disable() - Disables the smartreflex module.
+ * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
+ *
+ * This API is to be called from the smartreflex class driver to
+ * disable a smartreflex module.
+ */
+void sr_disable(struct voltagedomain *voltdm)
+{
+	struct omap_sr *sr = _sr_lookup(voltdm);
+
+	if (IS_ERR(sr)) {
+		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
+		return;
+	}
+
+	/* Check if SR clocks are already disabled. If yes do nothing */
+	if (pm_runtime_suspended(&sr->pdev->dev))
+		return;
+
+	/*
+	 * Disable SR if only it is indeed enabled. Else just
+	 * disable the clocks.
+	 */
+	if (sr_read_reg(sr, SRCONFIG) & SRCONFIG_SRENABLE) {
+		switch (sr->ip_type) {
+		case SR_TYPE_V1:
+			sr_v1_disable(sr);
+			break;
+		case SR_TYPE_V2:
+			sr_v2_disable(sr);
+			break;
+		default:
+			dev_err(&sr->pdev->dev, "UNKNOWN IP type %d\n",
+				sr->ip_type);
+		}
+	}
+
+	pm_runtime_put_sync_suspend(&sr->pdev->dev);
+}
+
+/**
+ * sr_register_class() - API to register a smartreflex class parameters.
+ * @class_data:	The structure containing various sr class specific data.
+ *
+ * This API is to be called by the smartreflex class driver to register itself
+ * with the smartreflex driver during init. Returns 0 on success else the
+ * error value.
+ */
+int sr_register_class(struct omap_sr_class_data *class_data)
+{
+	struct omap_sr *sr_info;
+
+	if (!class_data) {
+		pr_warning("%s:, Smartreflex class data passed is NULL\n",
+			__func__);
+		return -EINVAL;
+	}
+
+	if (sr_class) {
+		pr_warning("%s: Smartreflex class driver already registered\n",
+			__func__);
+		return -EBUSY;
+	}
+
+	sr_class = class_data;
+
+	/*
+	 * Call into late init to do intializations that require
+	 * both sr driver and sr class driver to be initiallized.
+	 */
+	list_for_each_entry(sr_info, &sr_list, node)
+		sr_late_init(sr_info);
+
+	return 0;
+}
+
+/**
+ * omap_sr_enable() -  API to enable SR clocks and to call into the
+ *			registered smartreflex class enable API.
+ * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
+ *
+ * This API is to be called from the kernel in order to enable
+ * a particular smartreflex module. This API will do the initial
+ * configurations to turn on the smartreflex module and in turn call
+ * into the registered smartreflex class enable API.
+ */
+void omap_sr_enable(struct voltagedomain *voltdm)
+{
+	struct omap_sr *sr = _sr_lookup(voltdm);
+
+	if (IS_ERR(sr)) {
+		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
+		return;
+	}
+
+	if (!sr->autocomp_active)
+		return;
+
+	if (!sr_class || !(sr_class->enable) || !(sr_class->configure)) {
+		dev_warn(&sr->pdev->dev, "%s: smartreflex class driver not"
+			"registered\n", __func__);
+		return;
+	}
+
+	sr_class->enable(sr);
+}
+
+/**
+ * omap_sr_disable() - API to disable SR without resetting the voltage
+ *			processor voltage
+ * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
+ *
+ * This API is to be called from the kernel in order to disable
+ * a particular smartreflex module. This API will in turn call
+ * into the registered smartreflex class disable API. This API will tell
+ * the smartreflex class disable not to reset the VP voltage after
+ * disabling smartreflex.
+ */
+void omap_sr_disable(struct voltagedomain *voltdm)
+{
+	struct omap_sr *sr = _sr_lookup(voltdm);
+
+	if (IS_ERR(sr)) {
+		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
+		return;
+	}
+
+	if (!sr->autocomp_active)
+		return;
+
+	if (!sr_class || !(sr_class->disable)) {
+		dev_warn(&sr->pdev->dev, "%s: smartreflex class driver not"
+			"registered\n", __func__);
+		return;
+	}
+
+	sr_class->disable(sr, 0);
+}
+
+/**
+ * omap_sr_disable_reset_volt() - API to disable SR and reset the
+ *				voltage processor voltage
+ * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
+ *
+ * This API is to be called from the kernel in order to disable
+ * a particular smartreflex module. This API will in turn call
+ * into the registered smartreflex class disable API. This API will tell
+ * the smartreflex class disable to reset the VP voltage after
+ * disabling smartreflex.
+ */
+void omap_sr_disable_reset_volt(struct voltagedomain *voltdm)
+{
+	struct omap_sr *sr = _sr_lookup(voltdm);
+
+	if (IS_ERR(sr)) {
+		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
+		return;
+	}
+
+	if (!sr->autocomp_active)
+		return;
+
+	if (!sr_class || !(sr_class->disable)) {
+		dev_warn(&sr->pdev->dev, "%s: smartreflex class driver not"
+			"registered\n", __func__);
+		return;
+	}
+
+	sr_class->disable(sr, 1);
+}
+
+/**
+ * omap_sr_register_pmic() - API to register pmic specific info.
+ * @pmic_data:	The structure containing pmic specific data.
+ *
+ * This API is to be called from the PMIC specific code to register with
+ * smartreflex driver pmic specific info. Currently the only info required
+ * is the smartreflex init on the PMIC side.
+ */
+void omap_sr_register_pmic(struct omap_sr_pmic_data *pmic_data)
+{
+	if (!pmic_data) {
+		pr_warning("%s: Trying to register NULL PMIC data structure"
+			"with smartreflex\n", __func__);
+		return;
+	}
+
+	sr_pmic_data = pmic_data;
+}
+
+/* PM Debug FS entries to enable and disable smartreflex. */
+static int omap_sr_autocomp_show(void *data, u64 *val)
+{
+	struct omap_sr *sr_info = data;
+
+	if (!sr_info) {
+		pr_warning("%s: omap_sr struct not found\n", __func__);
+		return -EINVAL;
+	}
+
+	*val = sr_info->autocomp_active;
+
+	return 0;
+}
+
+static int omap_sr_autocomp_store(void *data, u64 val)
+{
+	struct omap_sr *sr_info = data;
+
+	if (!sr_info) {
+		pr_warning("%s: omap_sr struct not found\n", __func__);
+		return -EINVAL;
+	}
+
+	/* Sanity check */
+	if (val > 1) {
+		pr_warning("%s: Invalid argument %lld\n", __func__, val);
+		return -EINVAL;
+	}
+
+	/* control enable/disable only if there is a delta in value */
+	if (sr_info->autocomp_active != val) {
+		if (!val)
+			sr_stop_vddautocomp(sr_info);
+		else
+			sr_start_vddautocomp(sr_info);
+	}
+
+	return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(pm_sr_fops, omap_sr_autocomp_show,
+			omap_sr_autocomp_store, "%llu\n");
+
+static int __init omap_sr_probe(struct platform_device *pdev)
+{
+	struct omap_sr *sr_info;
+	struct omap_sr_data *pdata = pdev->dev.platform_data;
+	struct resource *mem, *irq;
+	struct dentry *nvalue_dir;
+	int i, ret = 0;
+
+	sr_info = kzalloc(sizeof(struct omap_sr), GFP_KERNEL);
+	if (!sr_info) {
+		dev_err(&pdev->dev, "%s: unable to allocate sr_info\n",
+			__func__);
+		return -ENOMEM;
+	}
+
+	platform_set_drvdata(pdev, sr_info);
+
+	if (!pdata) {
+		dev_err(&pdev->dev, "%s: platform data missing\n", __func__);
+		ret = -EINVAL;
+		goto err_free_devinfo;
+	}
+
+	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!mem) {
+		dev_err(&pdev->dev, "%s: no mem resource\n", __func__);
+		ret = -ENODEV;
+		goto err_free_devinfo;
+	}
+
+	mem = request_mem_region(mem->start, resource_size(mem),
+					dev_name(&pdev->dev));
+	if (!mem) {
+		dev_err(&pdev->dev, "%s: no mem region\n", __func__);
+		ret = -EBUSY;
+		goto err_free_devinfo;
+	}
+
+	irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+
+	pm_runtime_enable(&pdev->dev);
+	pm_runtime_irq_safe(&pdev->dev);
+
+	sr_info->name = kasprintf(GFP_KERNEL, "sr_%s", pdata->name);
+	if (!sr_info->name) {
+		dev_err(&pdev->dev, "%s: Unable to alloc SR instance name\n",
+			__func__);
+		ret = -ENOMEM;
+		goto err_release_region;
+	}
+
+	sr_info->pdev = pdev;
+	sr_info->srid = pdev->id;
+	sr_info->voltdm = pdata->voltdm;
+	sr_info->nvalue_table = pdata->nvalue_table;
+	sr_info->nvalue_count = pdata->nvalue_count;
+	sr_info->senn_mod = pdata->senn_mod;
+	sr_info->senp_mod = pdata->senp_mod;
+	sr_info->autocomp_active = false;
+	sr_info->ip_type = pdata->ip_type;
+	sr_info->base = ioremap(mem->start, resource_size(mem));
+	if (!sr_info->base) {
+		dev_err(&pdev->dev, "%s: ioremap fail\n", __func__);
+		ret = -ENOMEM;
+		goto err_release_region;
+	}
+
+	if (irq)
+		sr_info->irq = irq->start;
+
+	sr_set_clk_length(sr_info);
+	sr_set_regfields(sr_info);
+
+	list_add(&sr_info->node, &sr_list);
+
+	/*
+	 * Call into late init to do intializations that require
+	 * both sr driver and sr class driver to be initiallized.
+	 */
+	if (sr_class) {
+		ret = sr_late_init(sr_info);
+		if (ret) {
+			pr_warning("%s: Error in SR late init\n", __func__);
+			goto err_iounmap;
+		}
+	}
+
+	dev_info(&pdev->dev, "%s: SmartReflex driver initialized\n", __func__);
+	if (!sr_dbg_dir) {
+		sr_dbg_dir = debugfs_create_dir("smartreflex", NULL);
+		if (IS_ERR_OR_NULL(sr_dbg_dir)) {
+			ret = PTR_ERR(sr_dbg_dir);
+			pr_err("%s:sr debugfs dir creation failed(%d)\n",
+				__func__, ret);
+			goto err_iounmap;
+		}
+	}
+
+	sr_info->dbg_dir = debugfs_create_dir(sr_info->name, sr_dbg_dir);
+	if (IS_ERR_OR_NULL(sr_info->dbg_dir)) {
+		dev_err(&pdev->dev, "%s: Unable to create debugfs directory\n",
+			__func__);
+		ret = PTR_ERR(sr_info->dbg_dir);
+		goto err_free_name;
+	}
+
+	(void) debugfs_create_file("autocomp", S_IRUGO | S_IWUSR,
+			sr_info->dbg_dir, (void *)sr_info, &pm_sr_fops);
+	(void) debugfs_create_x32("errweight", S_IRUGO, sr_info->dbg_dir,
+			&sr_info->err_weight);
+	(void) debugfs_create_x32("errmaxlimit", S_IRUGO, sr_info->dbg_dir,
+			&sr_info->err_maxlimit);
+
+	nvalue_dir = debugfs_create_dir("nvalue", sr_info->dbg_dir);
+	if (IS_ERR_OR_NULL(nvalue_dir)) {
+		dev_err(&pdev->dev, "%s: Unable to create debugfs directory"
+			"for n-values\n", __func__);
+		ret = PTR_ERR(nvalue_dir);
+		goto err_debugfs;
+	}
+
+	if (sr_info->nvalue_count == 0 || !sr_info->nvalue_table) {
+		dev_warn(&pdev->dev, "%s: %s: No Voltage table for the corresponding vdd. Cannot create debugfs entries for n-values\n",
+			 __func__, sr_info->name);
+		ret = -ENODATA;
+		goto err_debugfs;
+	}
+
+	for (i = 0; i < sr_info->nvalue_count; i++) {
+		char name[NVALUE_NAME_LEN + 1];
+
+		snprintf(name, sizeof(name), "volt_%lu",
+			 sr_info->nvalue_table[i].volt_nominal);
+		(void) debugfs_create_x32(name, S_IRUGO | S_IWUSR, nvalue_dir,
+				&(sr_info->nvalue_table[i].nvalue));
+		snprintf(name, sizeof(name), "errminlimit_%lu",
+			 sr_info->nvalue_table[i].volt_nominal);
+		(void) debugfs_create_x32(name, S_IRUGO | S_IWUSR, nvalue_dir,
+				&(sr_info->nvalue_table[i].errminlimit));
+	}
+
+	return ret;
+
+err_debugfs:
+	debugfs_remove_recursive(sr_info->dbg_dir);
+err_free_name:
+	kfree(sr_info->name);
+err_iounmap:
+	list_del(&sr_info->node);
+	iounmap(sr_info->base);
+err_release_region:
+	release_mem_region(mem->start, resource_size(mem));
+err_free_devinfo:
+	kfree(sr_info);
+
+	return ret;
+}
+
+static int __devexit omap_sr_remove(struct platform_device *pdev)
+{
+	struct omap_sr_data *pdata = pdev->dev.platform_data;
+	struct omap_sr *sr_info;
+	struct resource *mem;
+
+	if (!pdata) {
+		dev_err(&pdev->dev, "%s: platform data missing\n", __func__);
+		return -EINVAL;
+	}
+
+	sr_info = _sr_lookup(pdata->voltdm);
+	if (IS_ERR(sr_info)) {
+		dev_warn(&pdev->dev, "%s: omap_sr struct not found\n",
+			__func__);
+		return PTR_ERR(sr_info);
+	}
+
+	if (sr_info->autocomp_active)
+		sr_stop_vddautocomp(sr_info);
+	if (sr_info->dbg_dir)
+		debugfs_remove_recursive(sr_info->dbg_dir);
+
+	list_del(&sr_info->node);
+	iounmap(sr_info->base);
+	kfree(sr_info->name);
+	kfree(sr_info);
+	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	release_mem_region(mem->start, resource_size(mem));
+
+	return 0;
+}
+
+static void __devexit omap_sr_shutdown(struct platform_device *pdev)
+{
+	struct omap_sr_data *pdata = pdev->dev.platform_data;
+	struct omap_sr *sr_info;
+
+	if (!pdata) {
+		dev_err(&pdev->dev, "%s: platform data missing\n", __func__);
+		return;
+	}
+
+	sr_info = _sr_lookup(pdata->voltdm);
+	if (IS_ERR(sr_info)) {
+		dev_warn(&pdev->dev, "%s: omap_sr struct not found\n",
+			__func__);
+		return;
+	}
+
+	if (sr_info->autocomp_active)
+		sr_stop_vddautocomp(sr_info);
+
+	return;
+}
+
+static struct platform_driver smartreflex_driver = {
+	.remove         = __devexit_p(omap_sr_remove),
+	.shutdown	= __devexit_p(omap_sr_shutdown),
+	.driver		= {
+		.name	= "smartreflex",
+	},
+};
+
+static int __init sr_init(void)
+{
+	int ret = 0;
+
+	/*
+	 * sr_init is a late init. If by then a pmic specific API is not
+	 * registered either there is no need for anything to be done on
+	 * the PMIC side or somebody has forgotten to register a PMIC
+	 * handler. Warn for the second condition.
+	 */
+	if (sr_pmic_data && sr_pmic_data->sr_pmic_init)
+		sr_pmic_data->sr_pmic_init();
+	else
+		pr_warning("%s: No PMIC hook to init smartreflex\n", __func__);
+
+	ret = platform_driver_probe(&smartreflex_driver, omap_sr_probe);
+	if (ret) {
+		pr_err("%s: platform driver register failed for SR\n",
+			__func__);
+		return ret;
+	}
+
+	return 0;
+}
+late_initcall(sr_init);
+
+static void __exit sr_exit(void)
+{
+	platform_driver_unregister(&smartreflex_driver);
+}
+module_exit(sr_exit);
+
+MODULE_DESCRIPTION("OMAP Smartreflex Driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" DRIVER_NAME);
+MODULE_AUTHOR("Texas Instruments Inc");
diff --git a/drivers/power/avs/smartreflex.h b/drivers/power/avs/smartreflex.h
new file mode 100644
index 0000000..754f6aa
--- /dev/null
+++ b/drivers/power/avs/smartreflex.h
@@ -0,0 +1,238 @@
+/*
+ * OMAP Smartreflex Defines and Routines
+ *
+ * Author: Thara Gopinath	<thara@ti.com>
+ *
+ * Copyright (C) 2010 Texas Instruments, Inc.
+ * Thara Gopinath <thara@ti.com>
+ *
+ * Copyright (C) 2008 Nokia Corporation
+ * Kalle Jokiniemi
+ *
+ * Copyright (C) 2007 Texas Instruments, Inc.
+ * Lesly A M <x0080970@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __DRIVERS_POWER_AVS_SMARTREFLEX_H
+#define __DRIVERS_POWER_AVS_SMARTREFLEX_H
+
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/power/smartreflex.h>
+
+#include <plat/voltage.h>
+
+/*
+ * Different Smartreflex IPs version. The v1 is the 65nm version used in
+ * OMAP3430. The v2 is the update for the 45nm version of the IP
+ * used in OMAP3630 and OMAP4430
+ */
+#define SR_TYPE_V1	1
+#define SR_TYPE_V2	2
+
+/* SMART REFLEX REG ADDRESS OFFSET */
+#define SRCONFIG		0x00
+#define SRSTATUS		0x04
+#define SENVAL			0x08
+#define SENMIN			0x0C
+#define SENMAX			0x10
+#define SENAVG			0x14
+#define AVGWEIGHT		0x18
+#define NVALUERECIPROCAL	0x1c
+#define SENERROR_V1		0x20
+#define ERRCONFIG_V1		0x24
+#define IRQ_EOI			0x20
+#define IRQSTATUS_RAW		0x24
+#define IRQSTATUS		0x28
+#define IRQENABLE_SET		0x2C
+#define IRQENABLE_CLR		0x30
+#define SENERROR_V2		0x34
+#define ERRCONFIG_V2		0x38
+
+/* Bit/Shift Positions */
+
+/* SRCONFIG */
+#define SRCONFIG_ACCUMDATA_SHIFT	22
+#define SRCONFIG_SRCLKLENGTH_SHIFT	12
+#define SRCONFIG_SENNENABLE_V1_SHIFT	5
+#define SRCONFIG_SENPENABLE_V1_SHIFT	3
+#define SRCONFIG_SENNENABLE_V2_SHIFT	1
+#define SRCONFIG_SENPENABLE_V2_SHIFT	0
+#define SRCONFIG_CLKCTRL_SHIFT		0
+
+#define SRCONFIG_ACCUMDATA_MASK		(0x3ff << 22)
+
+#define SRCONFIG_SRENABLE		BIT(11)
+#define SRCONFIG_SENENABLE		BIT(10)
+#define SRCONFIG_ERRGEN_EN		BIT(9)
+#define SRCONFIG_MINMAXAVG_EN		BIT(8)
+#define SRCONFIG_DELAYCTRL		BIT(2)
+
+/* AVGWEIGHT */
+#define AVGWEIGHT_SENPAVGWEIGHT_SHIFT	2
+#define AVGWEIGHT_SENNAVGWEIGHT_SHIFT	0
+
+/* NVALUERECIPROCAL */
+#define NVALUERECIPROCAL_SENPGAIN_SHIFT	20
+#define NVALUERECIPROCAL_SENNGAIN_SHIFT	16
+#define NVALUERECIPROCAL_RNSENP_SHIFT	8
+#define NVALUERECIPROCAL_RNSENN_SHIFT	0
+
+/* ERRCONFIG */
+#define ERRCONFIG_ERRWEIGHT_SHIFT	16
+#define ERRCONFIG_ERRMAXLIMIT_SHIFT	8
+#define ERRCONFIG_ERRMINLIMIT_SHIFT	0
+
+#define SR_ERRWEIGHT_MASK		(0x07 << 16)
+#define SR_ERRMAXLIMIT_MASK		(0xff << 8)
+#define SR_ERRMINLIMIT_MASK		(0xff << 0)
+
+#define ERRCONFIG_VPBOUNDINTEN_V1	BIT(31)
+#define ERRCONFIG_VPBOUNDINTST_V1	BIT(30)
+#define	ERRCONFIG_MCUACCUMINTEN		BIT(29)
+#define ERRCONFIG_MCUACCUMINTST		BIT(28)
+#define	ERRCONFIG_MCUVALIDINTEN		BIT(27)
+#define ERRCONFIG_MCUVALIDINTST		BIT(26)
+#define ERRCONFIG_MCUBOUNDINTEN		BIT(25)
+#define	ERRCONFIG_MCUBOUNDINTST		BIT(24)
+#define	ERRCONFIG_MCUDISACKINTEN	BIT(23)
+#define ERRCONFIG_VPBOUNDINTST_V2	BIT(23)
+#define ERRCONFIG_MCUDISACKINTST	BIT(22)
+#define ERRCONFIG_VPBOUNDINTEN_V2	BIT(22)
+
+#define ERRCONFIG_STATUS_V1_MASK	(ERRCONFIG_VPBOUNDINTST_V1 | \
+					ERRCONFIG_MCUACCUMINTST | \
+					ERRCONFIG_MCUVALIDINTST | \
+					ERRCONFIG_MCUBOUNDINTST | \
+					ERRCONFIG_MCUDISACKINTST)
+/* IRQSTATUS */
+#define IRQSTATUS_MCUACCUMINT		BIT(3)
+#define IRQSTATUS_MCVALIDINT		BIT(2)
+#define IRQSTATUS_MCBOUNDSINT		BIT(1)
+#define IRQSTATUS_MCUDISABLEACKINT	BIT(0)
+
+/* IRQENABLE_SET and IRQENABLE_CLEAR */
+#define IRQENABLE_MCUACCUMINT		BIT(3)
+#define IRQENABLE_MCUVALIDINT		BIT(2)
+#define IRQENABLE_MCUBOUNDSINT		BIT(1)
+#define IRQENABLE_MCUDISABLEACKINT	BIT(0)
+
+/* Common Bit values */
+
+#define SRCLKLENGTH_12MHZ_SYSCLK	0x3c
+#define SRCLKLENGTH_13MHZ_SYSCLK	0x41
+#define SRCLKLENGTH_19MHZ_SYSCLK	0x60
+#define SRCLKLENGTH_26MHZ_SYSCLK	0x82
+#define SRCLKLENGTH_38MHZ_SYSCLK	0xC0
+
+/*
+ * 3430 specific values. Maybe these should be passed from board file or
+ * pmic structures.
+ */
+#define OMAP3430_SR_ACCUMDATA		0x1f4
+
+#define OMAP3430_SR1_SENPAVGWEIGHT	0x03
+#define OMAP3430_SR1_SENNAVGWEIGHT	0x03
+
+#define OMAP3430_SR2_SENPAVGWEIGHT	0x01
+#define OMAP3430_SR2_SENNAVGWEIGHT	0x01
+
+#define OMAP3430_SR_ERRWEIGHT		0x04
+#define OMAP3430_SR_ERRMAXLIMIT		0x02
+
+/**
+ * test_cond_timeout - busy-loop, testing a condition
+ * @cond: condition to test until it evaluates to true
+ * @timeout: maximum number of microseconds in the timeout
+ * @index: loop index (integer)
+ *
+ * Loop waiting for @cond to become true or until at least @timeout
+ * microseconds have passed.  To use, define some integer @index in the
+ * calling code.  After running, if @index == @timeout, then the loop has
+ * timed out.
+ *
+ * Copied from omap_test_timeout
+ */
+#define sr_test_cond_timeout(cond, timeout, index)		\
+({								\
+	for (index = 0; index < timeout; index++) {		\
+		if (cond)					\
+			break;					\
+		udelay(1);					\
+	}							\
+})
+
+/**
+ * struct omap_sr_pmic_data - Strucutre to be populated by pmic code to pass
+ *				pmic specific info to smartreflex driver
+ *
+ * @sr_pmic_init:	API to initialize smartreflex on the PMIC side.
+ */
+struct omap_sr_pmic_data {
+	void (*sr_pmic_init) (void);
+};
+
+
+#ifdef CONFIG_POWER_AVS_OMAP
+/*
+ * The smart reflex driver supports CLASS1 CLASS2 and CLASS3 SR.
+ * The smartreflex class driver should pass the class type.
+ * Should be used to populate the class_type field of the
+ * omap_smartreflex_class_data structure.
+ */
+#define SR_CLASS1	0x1
+#define SR_CLASS2	0x2
+#define SR_CLASS3	0x3
+
+/**
+ * struct omap_sr_class_data - Smartreflex class driver info
+ *
+ * @enable:		API to enable a particular class smaartreflex.
+ * @disable:		API to disable a particular class smartreflex.
+ * @configure:		API to configure a particular class smartreflex.
+ * @notify:		API to notify the class driver about an event in SR.
+ *			Not needed for class3.
+ * @notify_flags:	specify the events to be notified to the class driver
+ * @class_type:		specify which smartreflex class.
+ *			Can be used by the SR driver to take any class
+ *			based decisions.
+ */
+struct omap_sr_class_data {
+	int (*enable)(struct omap_sr *sr);
+	int (*disable)(struct omap_sr *sr, int is_volt_reset);
+	int (*configure)(struct omap_sr *sr);
+	int (*notify)(struct omap_sr *sr, u32 status);
+	u8 notify_flags;
+	u8 class_type;
+};
+
+/* Smartreflex module enable/disable interface */
+void omap_sr_enable(struct voltagedomain *voltdm);
+void omap_sr_disable(struct voltagedomain *voltdm);
+void omap_sr_disable_reset_volt(struct voltagedomain *voltdm);
+
+/* API to register the pmic specific data with the smartreflex driver. */
+void omap_sr_register_pmic(struct omap_sr_pmic_data *pmic_data);
+
+/* Smartreflex driver hooks to be called from Smartreflex class driver */
+int sr_enable(struct voltagedomain *voltdm, unsigned long volt);
+void sr_disable(struct voltagedomain *voltdm);
+int sr_configure_errgen(struct voltagedomain *voltdm);
+int sr_disable_errgen(struct voltagedomain *voltdm);
+int sr_configure_minmax(struct voltagedomain *voltdm);
+
+/* API to register the smartreflex class driver with the smartreflex driver */
+int sr_register_class(struct omap_sr_class_data *class_data);
+#else
+static inline void omap_sr_enable(struct voltagedomain *voltdm) {}
+static inline void omap_sr_disable(struct voltagedomain *voltdm) {}
+static inline void omap_sr_disable_reset_volt(
+		struct voltagedomain *voltdm) {}
+static inline void omap_sr_register_pmic(
+		struct omap_sr_pmic_data *pmic_data) {}
+#endif
+#endif
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: [PATCH v2 0/9] PM: Create the AVS class of drivers
  2012-03-19 16:12 [PATCH v2 0/9] PM: Create the AVS class of drivers jean.pihet
                   ` (8 preceding siblings ...)
  2012-03-19 16:12 ` [PATCH 9/9] ARM: OMAP: SmartReflex: Move smartreflex driver to drivers/ jean.pihet
@ 2012-04-03 11:14 ` Jean Pihet
  2012-04-18  8:04 ` Jean Pihet
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 31+ messages in thread
From: Jean Pihet @ 2012-04-03 11:14 UTC (permalink / raw)
  To: linux-omap, linux-arm-kernel, Kevin Hilman, Rafael J. Wysocki,
	LKML, Tony Lindgren
  Cc: Jean Pihet

Hi Tony, Rafael,

Here is a gentle ping on this series.
Do you think this can go in the next rc?

Regards,
Jean

On Mon, Mar 19, 2012 at 5:12 PM,  <jean.pihet@newoldbits.com> wrote:
> From: Jean Pihet <j-pihet@ti.com>
>
> AVS is a power management technique which controls the operating
> voltage of a device in order to optimize (i.e. reduce) its power
> consumption. The voltage is adapted depending on static factors
> (chip manufacturing process) and dynamic factors (temperature
> depending performance).
> AVS is also called SmartReflex on OMAP devices.
>
> To that end, create the AVS framework in drivers/power/avs and
> move the OMAP SmartReflex code to the new directory.
>
> In preparation to the move of the OMAP code the following changes have been
> made:
> - split the include files into generic and platform specific code,
> - fill in platform data from the device initialization code and pass
>  it to the driver,
> - create CONFIG_AVS* config options accordingly.
>
> The platform integration data for SmartReflex is passed from hwmod
> and the voltage layer to the driver using pdata.
>
>
> Tested on OMAP3 Beagleboard using omap2plus_defconfig with the
> CONFIG_POWER_AVS* options set.
> Based on master branch of the l-o git tree (3.3.0-rc6) [1], commit
> 85244e0edd240da2004bb2ab7cbcbc67a336f20d.
>
> [1] git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap.git
>
>
> History:
> v2: rework after the comments on MLs
>  . Keep the OMAP Kconfig options in the arch dir (Rafael),
>  . Move the shared header file from plat-omap to
>    include/linux/power/ (Tony)
>
> v1: initial revision
>
>
> Jean Pihet (9):
>  ARM: OMAP3+: voltage: export functions to plat/voltage.h
>  ARM: OMAP2+: SmartReflex: move the driver specific macros in
>    include/linux/power
>  ARM: OMAP3+: SmartReflex: class drivers should use struct omap_sr *
>  ARM: OMAP2+: smartreflex: Use the names from hwmod data instead of
>    voltage domains.
>  ARM: OMAP3: hwmod: rename the smartreflex entries
>  ARM: OMAP2+: SmartReflex: introduce a busy loop condition test macro
>  ARM: OMAP2+: SmartReflex: Use per-OPP data structure
>  ARM: OMAP2+: SmartReflex: add POWER_AVS Kconfig options
>  ARM: OMAP: SmartReflex: Move smartreflex driver to drivers/
>
>  arch/arm/mach-omap2/Makefile               |    4 +-
>  arch/arm/mach-omap2/omap_hwmod_3xxx_data.c |   12 +-
>  arch/arm/mach-omap2/omap_hwmod_44xx_data.c |    3 +-
>  arch/arm/mach-omap2/pm.h                   |    2 +-
>  arch/arm/mach-omap2/smartreflex-class3.c   |   60 --
>  arch/arm/mach-omap2/smartreflex.c          | 1165 ----------------------------
>  arch/arm/mach-omap2/smartreflex.h          |  256 ------
>  arch/arm/mach-omap2/sr_device.c            |   38 +-
>  arch/arm/mach-omap2/voltage.h              |    1 -
>  arch/arm/mach-omap2/vp.h                   |    2 -
>  arch/arm/plat-omap/Kconfig                 |   30 +-
>  arch/arm/plat-omap/include/plat/voltage.h  |    3 +
>  drivers/power/Kconfig                      |    2 +
>  drivers/power/Makefile                     |    2 +
>  drivers/power/avs/Kconfig                  |   12 +
>  drivers/power/avs/Makefile                 |    2 +
>  drivers/power/avs/smartreflex-class3.c     |   61 ++
>  drivers/power/avs/smartreflex.c            | 1118 ++++++++++++++++++++++++++
>  drivers/power/avs/smartreflex.h            |  238 ++++++
>  include/linux/power/smartreflex.h          |   97 +++
>  20 files changed, 1590 insertions(+), 1518 deletions(-)
>  delete mode 100644 arch/arm/mach-omap2/smartreflex-class3.c
>  delete mode 100644 arch/arm/mach-omap2/smartreflex.c
>  delete mode 100644 arch/arm/mach-omap2/smartreflex.h
>  create mode 100644 drivers/power/avs/Kconfig
>  create mode 100644 drivers/power/avs/Makefile
>  create mode 100644 drivers/power/avs/smartreflex-class3.c
>  create mode 100644 drivers/power/avs/smartreflex.c
>  create mode 100644 drivers/power/avs/smartreflex.h
>  create mode 100644 include/linux/power/smartreflex.h
>
> --
> 1.7.5.4
>

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 2/9] ARM: OMAP2+: SmartReflex: move the driver specific macros in include/linux/power
  2012-03-19 16:12 ` [PATCH 2/9] ARM: OMAP2+: SmartReflex: move the driver specific macros in include/linux/power jean.pihet
@ 2012-04-04 19:10   ` Trilok Soni
  2012-04-04 19:41     ` Cousson, Benoit
  0 siblings, 1 reply; 31+ messages in thread
From: Trilok Soni @ 2012-04-04 19:10 UTC (permalink / raw)
  To: jean.pihet
  Cc: linux-omap, linux-arm-kernel, Kevin Hilman, Rafael J. Wysocki,
	LKML, Jean Pihet

Hi Jean,

On 3/19/2012 9:42 PM, jean.pihet@newoldbits.com wrote:
> From: Jean Pihet<j-pihet@ti.com>
>
> Move the driver specific macros from the smartreflex header file
> (arch/arm/mach-omap2/smartreflex.h) in a new header file
> include/linux/power/smartreflex.h.
>
> This change makes the SmartReflex implementation ready for the move
> to drivers/.

I wonder why someone would need a new directory under drivers/power 
where the code is not about introducing new and generic AVS framework
but it is all about OMAP specific code. What if tomorrow new generic
AVS framework comes from different chip vendor? I am sure this kind
of technology would be common in newer embedded chips.

---Trilok Soni

-- 
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 2/9] ARM: OMAP2+: SmartReflex: move the driver specific macros in include/linux/power
  2012-04-04 19:10   ` Trilok Soni
@ 2012-04-04 19:41     ` Cousson, Benoit
  2012-04-05  6:53       ` Trilok Soni
  0 siblings, 1 reply; 31+ messages in thread
From: Cousson, Benoit @ 2012-04-04 19:41 UTC (permalink / raw)
  To: Trilok Soni
  Cc: jean.pihet, linux-omap, linux-arm-kernel, Kevin Hilman,
	Rafael J. Wysocki, LKML, Jean Pihet

On 4/4/2012 9:10 PM, Trilok Soni wrote:
> Hi Jean,
>
> On 3/19/2012 9:42 PM, jean.pihet@newoldbits.com wrote:
>> From: Jean Pihet<j-pihet@ti.com>
>>
>> Move the driver specific macros from the smartreflex header file
>> (arch/arm/mach-omap2/smartreflex.h) in a new header file
>> include/linux/power/smartreflex.h.
>>
>> This change makes the SmartReflex implementation ready for the move
>> to drivers/.
>
> I wonder why someone would need a new directory under drivers/power
> where the code is not about introducing new and generic AVS framework
> but it is all about OMAP specific code.

The main motivation is that it's a driver and thus does not have 
anything to do inside mach-omap2.

Where will you put that otherwise?

> What if tomorrow new generic
> AVS framework comes from different chip vendor? I am sure this kind
> of technology would be common in newer embedded chips.

Probably, but this is hard to know with only one implementation so far 
in the kernel.
I guess when someone else will start pushing some new AVS driver inside 
the AVS directory, we might realize that there is enough common part to 
create a frwmk.

IIRC, David Brownell was referring to the rule of three for such case. 
Meaning that it worth having a generic fmwk when at least three 
different drivers are doing the same kind of things.

Regards,
Benoit

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 2/9] ARM: OMAP2+: SmartReflex: move the driver specific macros in include/linux/power
  2012-04-04 19:41     ` Cousson, Benoit
@ 2012-04-05  6:53       ` Trilok Soni
  2012-04-05  8:59         ` Jean Pihet
  0 siblings, 1 reply; 31+ messages in thread
From: Trilok Soni @ 2012-04-05  6:53 UTC (permalink / raw)
  To: Cousson, Benoit
  Cc: Kevin Hilman, jean.pihet, LKML, Rafael J. Wysocki, linux-omap,
	Jean Pihet, linux-arm-kernel, gregkh

Hi Benoit,

>
> The main motivation is that it's a driver and thus does not have
> anything to do inside mach-omap2.

Right, I understood that. mach-omap2 is not suitable for full fledged 
drivers.

>
> Where will you put that otherwise?

Couple of suggestions:

drivers/platform/omap/avs?
drivers/misc/omap/avs?

I prefer first one.

>
> IIRC, David Brownell was referring to the rule of three for such case.
> Meaning that it worth having a generic fmwk when at least three
> different drivers are doing the same kind of things.

Yes, I remember that rule, but that's not stopping us to create a fwk, 
may be others will rise once they see the framework and contribute
if their h/w architecture requirements are not addressed?

---Trilok Soni

-- 
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 2/9] ARM: OMAP2+: SmartReflex: move the driver specific macros in include/linux/power
  2012-04-05  6:53       ` Trilok Soni
@ 2012-04-05  8:59         ` Jean Pihet
  2012-04-05  9:35           ` Trilok Soni
  0 siblings, 1 reply; 31+ messages in thread
From: Jean Pihet @ 2012-04-05  8:59 UTC (permalink / raw)
  To: Trilok Soni
  Cc: Cousson, Benoit, Kevin Hilman, LKML, Rafael J. Wysocki,
	linux-omap, Jean Pihet, linux-arm-kernel, gregkh

Hi!

On Thu, Apr 5, 2012 at 8:53 AM, Trilok Soni <tsoni@codeaurora.org> wrote:
> Hi Benoit,
>
>
>>
>> The main motivation is that it's a driver and thus does not have
>> anything to do inside mach-omap2.
>
>
> Right, I understood that. mach-omap2 is not suitable for full fledged
> drivers.

The initial motivation is to provide a generic framework for this type
of drivers, by cleaning up the current OMAP code and by providing as
much generic code as possible.

Cf. the patch sets I submitted before this very one:
- the SR code clean-up [1], which is needed to make the code ready for
the integration of new features,
- the SR class support [2], which is needed for new SR classes to be
implemented.

>From the maintainer point of view it made more sense to move the code
before cleaning it up and so it should happen before [1] and [2].
The result is that [1] and [2] will need to be rebased when the move
is accepted and merged in.

[1] http://marc.info/?l=linux-omap&m=133055488908132&w=2
[2] http://marc.info/?l=linux-omap&m=133163445926544&w=2

>>
>> Where will you put that otherwise?
>
>
> Couple of suggestions:
>
> drivers/platform/omap/avs?
> drivers/misc/omap/avs?
>
> I prefer first one.
Those paths are for OMAP specific code and not for a generic framework.

>>
>> IIRC, David Brownell was referring to the rule of three for such case.
>> Meaning that it worth having a generic fmwk when at least three
>> different drivers are doing the same kind of things.

Do OMAP v1 and OMAP v2 implementations count as 2 drivers? ;-)
More seriously, the OMAP code for SmartReflex is far from complete in
mainline. There is a plan to provide the following features:
- OMAP v1 IP,
- OMAP v2 IP,
- class 1.5,
- class 3,
- class 3.5,
- and more support for the upcoming chipsets.

Also I am sure that other vendors could step in and have their
platform specific code converted to the new fwk as well.

>
>
> Yes, I remember that rule, but that's not stopping us to create a fwk, may
> be others will rise once they see the framework and contribute
> if their h/w architecture requirements are not addressed?
>

Thanks,
Jean

>
> ---Trilok Soni
>
> --
> --
> Sent by a consultant of the Qualcomm Innovation Center, Inc.
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 2/9] ARM: OMAP2+: SmartReflex: move the driver specific macros in include/linux/power
  2012-04-05  8:59         ` Jean Pihet
@ 2012-04-05  9:35           ` Trilok Soni
  2012-04-19 13:54             ` Arnd Bergmann
  0 siblings, 1 reply; 31+ messages in thread
From: Trilok Soni @ 2012-04-05  9:35 UTC (permalink / raw)
  To: Jean Pihet
  Cc: Cousson, Benoit, Kevin Hilman, LKML, Rafael J. Wysocki,
	linux-omap, Jean Pihet, linux-arm-kernel, gregkh

Hi Jean,

>
> The initial motivation is to provide a generic framework for this type
> of drivers, by cleaning up the current OMAP code and by providing as
> much generic code as possible.
>
> Cf. the patch sets I submitted before this very one:
> - the SR code clean-up [1], which is needed to make the code ready for
> the integration of new features,
> - the SR class support [2], which is needed for new SR classes to be
> implemented.
>
>  From the maintainer point of view it made more sense to move the code
> before cleaning it up and so it should happen before [1] and [2].
> The result is that [1] and [2] will need to be rebased when the move
> is accepted and merged in.
>
> [1] http://marc.info/?l=linux-omap&m=133055488908132&w=2
> [2] http://marc.info/?l=linux-omap&m=133163445926544&w=2

I am going through your patches and including some wiki pages. I 
understand the SR can be connected in two ways - intelligent and dumb :)
For intelligent I mean you just configure SR and it will and program 
PMIC, whereas in dumb scenarios application processor gets the 
notification and then it goes and writes into PMIC based on some 
floor/ceiling values. In the first case not much of apps. s/w but in the 
later case whole lot.

>
>>>
>>> Where will you put that otherwise?
>>
>>
>> Couple of suggestions:
>>
>> drivers/platform/omap/avs?
>> drivers/misc/omap/avs?
>>
>> I prefer first one.
> Those paths are for OMAP specific code and not for a generic framework.
>
>>>
>>> IIRC, David Brownell was referring to the rule of three for such case.
>>> Meaning that it worth having a generic fmwk when at least three
>>> different drivers are doing the same kind of things.
>
> Do OMAP v1 and OMAP v2 implementations count as 2 drivers? ;-)
> More seriously, the OMAP code for SmartReflex is far from complete in
> mainline. There is a plan to provide the following features:
> - OMAP v1 IP,
> - OMAP v2 IP,
> - class 1.5,
> - class 3,
> - class 3.5,
> - and more support for the upcoming chipsets.

I don't understand much of these versions right now, but hopefully after 
going through all these docs. My only contention point is to not create 
any directory into the drivers/power, unless it is generic fwk and then 
build up "client" drivers on top of it. Meanwhile we could move this 
driver into above options as I have suggested.

---Trilok Soni

-- 
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH v2 0/9] PM: Create the AVS class of drivers
  2012-03-19 16:12 [PATCH v2 0/9] PM: Create the AVS class of drivers jean.pihet
                   ` (9 preceding siblings ...)
  2012-04-03 11:14 ` [PATCH v2 0/9] PM: Create the AVS class of drivers Jean Pihet
@ 2012-04-18  8:04 ` Jean Pihet
  2012-04-19  0:08   ` Greg KH
  2012-04-18 18:29 ` Kevin Hilman
  2012-04-18 18:30 ` Kevin Hilman
  12 siblings, 1 reply; 31+ messages in thread
From: Jean Pihet @ 2012-04-18  8:04 UTC (permalink / raw)
  To: akpm, gregkh, linux-omap, linux-arm-kernel, Kevin Hilman,
	Rafael J. Wysocki, LKML, Tony Lindgren, KEERTHY J
  Cc: Jean Pihet

Hi Andrew, Greg,

Can you please look at this patch set?
The idea is to create a framework and drivers for the AVS class of
devices. This patch set implements the first step by moving the
existing code to drivers/power/avs. Next steps will be to implement
class support and notifications, add more classes of operations for
OMAP chips, etc.

Keerthy J is taking over the ownership of this code and will continue
the development further.

What do you think?

Regards,
Jean

On Mon, Mar 19, 2012 at 5:12 PM,  <jean.pihet@newoldbits.com> wrote:
> From: Jean Pihet <j-pihet@ti.com>
>
> AVS is a power management technique which controls the operating
> voltage of a device in order to optimize (i.e. reduce) its power
> consumption. The voltage is adapted depending on static factors
> (chip manufacturing process) and dynamic factors (temperature
> depending performance).
> AVS is also called SmartReflex on OMAP devices.
>
> To that end, create the AVS framework in drivers/power/avs and
> move the OMAP SmartReflex code to the new directory.
>
> In preparation to the move of the OMAP code the following changes have been
> made:
> - split the include files into generic and platform specific code,
> - fill in platform data from the device initialization code and pass
>  it to the driver,
> - create CONFIG_AVS* config options accordingly.
>
> The platform integration data for SmartReflex is passed from hwmod
> and the voltage layer to the driver using pdata.
>
>
> Tested on OMAP3 Beagleboard using omap2plus_defconfig with the
> CONFIG_POWER_AVS* options set.
> Based on master branch of the l-o git tree (3.3.0-rc6) [1], commit
> 85244e0edd240da2004bb2ab7cbcbc67a336f20d.
>
> [1] git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap.git
>
>
> History:
> v2: rework after the comments on MLs
>  . Keep the OMAP Kconfig options in the arch dir (Rafael),
>  . Move the shared header file from plat-omap to
>    include/linux/power/ (Tony)
>
> v1: initial revision
>
>
> Jean Pihet (9):
>  ARM: OMAP3+: voltage: export functions to plat/voltage.h
>  ARM: OMAP2+: SmartReflex: move the driver specific macros in
>    include/linux/power
>  ARM: OMAP3+: SmartReflex: class drivers should use struct omap_sr *
>  ARM: OMAP2+: smartreflex: Use the names from hwmod data instead of
>    voltage domains.
>  ARM: OMAP3: hwmod: rename the smartreflex entries
>  ARM: OMAP2+: SmartReflex: introduce a busy loop condition test macro
>  ARM: OMAP2+: SmartReflex: Use per-OPP data structure
>  ARM: OMAP2+: SmartReflex: add POWER_AVS Kconfig options
>  ARM: OMAP: SmartReflex: Move smartreflex driver to drivers/
>
>  arch/arm/mach-omap2/Makefile               |    4 +-
>  arch/arm/mach-omap2/omap_hwmod_3xxx_data.c |   12 +-
>  arch/arm/mach-omap2/omap_hwmod_44xx_data.c |    3 +-
>  arch/arm/mach-omap2/pm.h                   |    2 +-
>  arch/arm/mach-omap2/smartreflex-class3.c   |   60 --
>  arch/arm/mach-omap2/smartreflex.c          | 1165 ----------------------------
>  arch/arm/mach-omap2/smartreflex.h          |  256 ------
>  arch/arm/mach-omap2/sr_device.c            |   38 +-
>  arch/arm/mach-omap2/voltage.h              |    1 -
>  arch/arm/mach-omap2/vp.h                   |    2 -
>  arch/arm/plat-omap/Kconfig                 |   30 +-
>  arch/arm/plat-omap/include/plat/voltage.h  |    3 +
>  drivers/power/Kconfig                      |    2 +
>  drivers/power/Makefile                     |    2 +
>  drivers/power/avs/Kconfig                  |   12 +
>  drivers/power/avs/Makefile                 |    2 +
>  drivers/power/avs/smartreflex-class3.c     |   61 ++
>  drivers/power/avs/smartreflex.c            | 1118 ++++++++++++++++++++++++++
>  drivers/power/avs/smartreflex.h            |  238 ++++++
>  include/linux/power/smartreflex.h          |   97 +++
>  20 files changed, 1590 insertions(+), 1518 deletions(-)
>  delete mode 100644 arch/arm/mach-omap2/smartreflex-class3.c
>  delete mode 100644 arch/arm/mach-omap2/smartreflex.c
>  delete mode 100644 arch/arm/mach-omap2/smartreflex.h
>  create mode 100644 drivers/power/avs/Kconfig
>  create mode 100644 drivers/power/avs/Makefile
>  create mode 100644 drivers/power/avs/smartreflex-class3.c
>  create mode 100644 drivers/power/avs/smartreflex.c
>  create mode 100644 drivers/power/avs/smartreflex.h
>  create mode 100644 include/linux/power/smartreflex.h
>
> --
> 1.7.5.4
>

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 1/9] ARM: OMAP3+: voltage: export functions to plat/voltage.h
  2012-03-19 16:12 ` [PATCH 1/9] ARM: OMAP3+: voltage: export functions to plat/voltage.h jean.pihet
@ 2012-04-18 17:27   ` Kevin Hilman
  2012-04-18 20:36     ` Jean Pihet
  0 siblings, 1 reply; 31+ messages in thread
From: Kevin Hilman @ 2012-04-18 17:27 UTC (permalink / raw)
  To: jean.pihet
  Cc: linux-omap, linux-arm-kernel, Rafael J. Wysocki, LKML, Jean Pihet

Hi Jean,

jean.pihet@newoldbits.com writes:

> From: Jean Pihet <j-pihet@ti.com>
>
> Move some functions from mach-omap2/ dir to the plat/ dir.
> The SmartReflex class driver is a user of the basic voltage domains
> functions (enable, disable, reset).
>
> Signed-off-by: Jean Pihet <j-pihet@ti.com>
> Cc: Kevin Hilman <khilman@ti.com>

Rather than expose the VP functions directly, how about adding a new API
at the voltdm layer to start/stop AVS.  Maybe something like:

  voltdm_avs_start(struct voltagedomain *voltdm)
  voltdm_avs_stop(struct voltagedomain *voltdm)

These will internally just call VP enable/disable for now, but we may
have more to add to these in the future to support other SR classes.

Kevin

> ---
>  arch/arm/mach-omap2/smartreflex-class3.c  |    1 +
>  arch/arm/mach-omap2/smartreflex.h         |    2 +-
>  arch/arm/mach-omap2/voltage.h             |    1 -
>  arch/arm/mach-omap2/vp.h                  |    2 --
>  arch/arm/plat-omap/include/plat/voltage.h |    3 +++
>  5 files changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/arch/arm/mach-omap2/smartreflex-class3.c b/arch/arm/mach-omap2/smartreflex-class3.c
> index 955566e..e12c51e 100644
> --- a/arch/arm/mach-omap2/smartreflex-class3.c
> +++ b/arch/arm/mach-omap2/smartreflex-class3.c
> @@ -12,6 +12,7 @@
>   */
>  
>  #include "smartreflex.h"
> +#include "voltage.h"
>  
>  static int sr_class3_enable(struct voltagedomain *voltdm)
>  {
> diff --git a/arch/arm/mach-omap2/smartreflex.h b/arch/arm/mach-omap2/smartreflex.h
> index 5809141..c4e8530 100644
> --- a/arch/arm/mach-omap2/smartreflex.h
> +++ b/arch/arm/mach-omap2/smartreflex.h
> @@ -22,7 +22,7 @@
>  
>  #include <linux/platform_device.h>
>  
> -#include "voltage.h"
> +#include <plat/voltage.h>
>  
>  /*
>   * Different Smartreflex IPs version. The v1 is the 65nm version used in
> diff --git a/arch/arm/mach-omap2/voltage.h b/arch/arm/mach-omap2/voltage.h
> index 16a1b09..a81dea8 100644
> --- a/arch/arm/mach-omap2/voltage.h
> +++ b/arch/arm/mach-omap2/voltage.h
> @@ -167,6 +167,5 @@ int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
>  			  int (*fn)(struct voltagedomain *voltdm,
>  				    struct powerdomain *pwrdm));
>  int voltdm_scale(struct voltagedomain *voltdm, unsigned long target_volt);
> -void voltdm_reset(struct voltagedomain *voltdm);
>  unsigned long voltdm_get_voltage(struct voltagedomain *voltdm);
>  #endif
> diff --git a/arch/arm/mach-omap2/vp.h b/arch/arm/mach-omap2/vp.h
> index 7c155d2..837cb8d 100644
> --- a/arch/arm/mach-omap2/vp.h
> +++ b/arch/arm/mach-omap2/vp.h
> @@ -118,8 +118,6 @@ extern struct omap_vp_instance omap4_vp_iva;
>  extern struct omap_vp_instance omap4_vp_core;
>  
>  void omap_vp_init(struct voltagedomain *voltdm);
> -void omap_vp_enable(struct voltagedomain *voltdm);
> -void omap_vp_disable(struct voltagedomain *voltdm);
>  int omap_vp_forceupdate_scale(struct voltagedomain *voltdm,
>  			      unsigned long target_volt);
>  int omap_vp_update_errorgain(struct voltagedomain *voltdm,
> diff --git a/arch/arm/plat-omap/include/plat/voltage.h b/arch/arm/plat-omap/include/plat/voltage.h
> index 0a6a482..1842709 100644
> --- a/arch/arm/plat-omap/include/plat/voltage.h
> +++ b/arch/arm/plat-omap/include/plat/voltage.h
> @@ -16,5 +16,8 @@ struct voltagedomain;
>  struct voltagedomain *voltdm_lookup(const char *name);
>  int voltdm_scale(struct voltagedomain *voltdm, unsigned long target_volt);
>  unsigned long voltdm_get_voltage(struct voltagedomain *voltdm);
> +void voltdm_reset(struct voltagedomain *voltdm);
>  
> +void omap_vp_enable(struct voltagedomain *voltdm);
> +void omap_vp_disable(struct voltagedomain *voltdm);
>  #endif

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 5/9] ARM: OMAP3: hwmod: rename the smartreflex entries
  2012-03-19 16:12 ` [PATCH 5/9] ARM: OMAP3: hwmod: rename the smartreflex entries jean.pihet
@ 2012-04-18 17:33   ` Kevin Hilman
  2012-04-18 20:41     ` Jean Pihet
  0 siblings, 1 reply; 31+ messages in thread
From: Kevin Hilman @ 2012-04-18 17:33 UTC (permalink / raw)
  To: jean.pihet
  Cc: linux-omap, linux-arm-kernel, Rafael J. Wysocki, LKML, Jean Pihet

+Benoit

jean.pihet@newoldbits.com writes:

> From: Jean Pihet <j-pihet@ti.com>
>
> Change the name field value to better reflect the smartreflex
> integration in the system
>
> Signed-off-by: Jean Pihet <j-pihet@ti.com>
> ---
>  arch/arm/mach-omap2/omap_hwmod_3xxx_data.c |    8 ++++----
>  arch/arm/mach-omap2/smartreflex.c          |    2 +-
>  2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
> index d7d4c70..40f57c4 100644
> --- a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
> +++ b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
> @@ -2751,7 +2751,7 @@ static struct omap_hwmod_ocp_if *omap34xx_sr1_slaves[] = {
>  };
>  
>  static struct omap_hwmod omap34xx_sr1_hwmod = {
> -	.name		= "sr1",
> +	.name		= "mpu_iva",

Should this be "smartreflex_mpu_iva"?  

The OMAP4 SR hwmods have a 'smartreflex_' prefix which seems better.

>  	.class		= &omap34xx_smartreflex_hwmod_class,
>  	.main_clk	= "sr1_fck",
>  	.prcm		= {
> @@ -2775,7 +2775,7 @@ static struct omap_hwmod_ocp_if *omap36xx_sr1_slaves[] = {
>  };
>  
>  static struct omap_hwmod omap36xx_sr1_hwmod = {
> -	.name		= "sr1",
> +	.name		= "mpu_iva",
>  	.class		= &omap36xx_smartreflex_hwmod_class,
>  	.main_clk	= "sr1_fck",
>  	.prcm		= {
> @@ -2803,7 +2803,7 @@ static struct omap_hwmod_ocp_if *omap34xx_sr2_slaves[] = {
>  };
>  
>  static struct omap_hwmod omap34xx_sr2_hwmod = {
> -	.name		= "sr2",
> +	.name		= "core",
>  	.class		= &omap34xx_smartreflex_hwmod_class,
>  	.main_clk	= "sr2_fck",
>  	.prcm		= {
> @@ -2827,7 +2827,7 @@ static struct omap_hwmod_ocp_if *omap36xx_sr2_slaves[] = {
>  };
>  
>  static struct omap_hwmod omap36xx_sr2_hwmod = {
> -	.name		= "sr2",
> +	.name		= "core",
>  	.class		= &omap36xx_smartreflex_hwmod_class,
>  	.main_clk	= "sr2_fck",
>  	.prcm		= {
> diff --git a/arch/arm/mach-omap2/smartreflex.c b/arch/arm/mach-omap2/smartreflex.c
> index c18d47d..b2728a5 100644
> --- a/arch/arm/mach-omap2/smartreflex.c
> +++ b/arch/arm/mach-omap2/smartreflex.c
> @@ -184,7 +184,7 @@ static void sr_set_regfields(struct omap_sr *sr)
>  		sr->err_weight = OMAP3430_SR_ERRWEIGHT;
>  		sr->err_maxlimit = OMAP3430_SR_ERRMAXLIMIT;
>  		sr->accum_data = OMAP3430_SR_ACCUMDATA;
> -		if (!(strcmp(sr->name, "sr1"))) {
> +		if (!(strcmp(sr->name, "sr_mpu_iva"))) {

Why the 'sr_' prefix?

>  			sr->senn_avgweight = OMAP3430_SR1_SENNAVGWEIGHT;
>  			sr->senp_avgweight = OMAP3430_SR1_SENPAVGWEIGHT;
>  		} else {

Kevin

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 9/9] ARM: OMAP: SmartReflex: Move smartreflex driver to drivers/
  2012-03-19 16:12 ` [PATCH 9/9] ARM: OMAP: SmartReflex: Move smartreflex driver to drivers/ jean.pihet
@ 2012-04-18 18:17   ` Kevin Hilman
  0 siblings, 0 replies; 31+ messages in thread
From: Kevin Hilman @ 2012-04-18 18:17 UTC (permalink / raw)
  To: jean.pihet
  Cc: linux-omap, linux-arm-kernel, Rafael J. Wysocki, LKML, Jean Pihet

jean.pihet@newoldbits.com writes:

> From: Jean Pihet <j-pihet@ti.com>
>
> After a clean-up of the interfaces the OMAP IP driver and class
> support code is now a generic driver.
> Move it to drivers/power/avs/.
>
> The build is controlled by the following Kconfig options:
>  . CONFIG_POWER_AVS: general knob for Adaptive Voltage Scaling support,
>  . CONFIG_POWER_AVS_OMAP: AVS support on OMAP containing the version 1
>     or version 2 of the SmartReflex IP,
>  . CONFIG_POWER_AVS_OMAP_CLASS3: Class 3 implementation of Smartreflex.
>
> Signed-off-by: Jean Pihet <j-pihet@ti.com>

You might use git-format-patch -M here so it's clear in the diffstat
that this is just a move.

Kevin

> ---
>  arch/arm/mach-omap2/Makefile             |    3 +-
>  arch/arm/mach-omap2/smartreflex-class3.c |   61 --
>  arch/arm/mach-omap2/smartreflex.c        | 1120 ------------------------------
>  arch/arm/mach-omap2/smartreflex.h        |  238 -------
>  arch/arm/plat-omap/Kconfig               |   19 +-
>  drivers/power/Kconfig                    |    2 +
>  drivers/power/Makefile                   |    2 +
>  drivers/power/avs/Kconfig                |   12 +
>  drivers/power/avs/Makefile               |    2 +
>  drivers/power/avs/smartreflex-class3.c   |   61 ++
>  drivers/power/avs/smartreflex.c          | 1118 +++++++++++++++++++++++++++++
>  drivers/power/avs/smartreflex.h          |  238 +++++++
>  12 files changed, 1437 insertions(+), 1439 deletions(-)
>  delete mode 100644 arch/arm/mach-omap2/smartreflex-class3.c
>  delete mode 100644 arch/arm/mach-omap2/smartreflex.c
>  delete mode 100644 arch/arm/mach-omap2/smartreflex.h
>  create mode 100644 drivers/power/avs/Kconfig
>  create mode 100644 drivers/power/avs/Makefile
>  create mode 100644 drivers/power/avs/smartreflex-class3.c
>  create mode 100644 drivers/power/avs/smartreflex.c
>  create mode 100644 drivers/power/avs/smartreflex.h
>
> diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile
> index 30666fd..bb23056 100644
> --- a/arch/arm/mach-omap2/Makefile
> +++ b/arch/arm/mach-omap2/Makefile
> @@ -69,8 +69,7 @@ obj-$(CONFIG_ARCH_OMAP4)		+= pm44xx.o omap-mpuss-lowpower.o \
>  					   cpuidle44xx.o
>  obj-$(CONFIG_PM_DEBUG)			+= pm-debug.o
>  
> -obj-$(CONFIG_POWER_AVS_OMAP)		+= sr_device.o smartreflex.o
> -obj-$(CONFIG_POWER_AVS_OMAP_CLASS3)	+= smartreflex-class3.o
> +obj-$(CONFIG_POWER_AVS_OMAP)		+= sr_device.o
>  
>  AFLAGS_sleep24xx.o			:=-Wa,-march=armv6
>  AFLAGS_sleep34xx.o			:=-Wa,-march=armv7-a$(plus_sec)
> diff --git a/arch/arm/mach-omap2/smartreflex-class3.c b/arch/arm/mach-omap2/smartreflex-class3.c
> deleted file mode 100644
> index f63c950..0000000
> --- a/arch/arm/mach-omap2/smartreflex-class3.c
> +++ /dev/null
> @@ -1,61 +0,0 @@
> -/*
> - * Smart reflex Class 3 specific implementations
> - *
> - * Author: Thara Gopinath       <thara@ti.com>
> - *
> - * Copyright (C) 2010 Texas Instruments, Inc.
> - * Thara Gopinath <thara@ti.com>
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License version 2 as
> - * published by the Free Software Foundation.
> - */
> -
> -#include "smartreflex.h"
> -#include "voltage.h"
> -
> -static int sr_class3_enable(struct omap_sr *sr)
> -{
> -	unsigned long volt = voltdm_get_voltage(sr->voltdm);
> -
> -	if (!volt) {
> -		pr_warning("%s: Curr voltage unknown. Cannot enable %s\n",
> -				__func__, sr->name);
> -		return -ENODATA;
> -	}
> -
> -	omap_vp_enable(sr->voltdm);
> -	return sr_enable(sr->voltdm, volt);
> -}
> -
> -static int sr_class3_disable(struct omap_sr *sr, int is_volt_reset)
> -{
> -	sr_disable_errgen(sr->voltdm);
> -	omap_vp_disable(sr->voltdm);
> -	sr_disable(sr->voltdm);
> -	if (is_volt_reset)
> -		voltdm_reset(sr->voltdm);
> -
> -	return 0;
> -}
> -
> -static int sr_class3_configure(struct omap_sr *sr)
> -{
> -	return sr_configure_errgen(sr->voltdm);
> -}
> -
> -/* SR class3 structure */
> -static struct omap_sr_class_data class3_data = {
> -	.enable = sr_class3_enable,
> -	.disable = sr_class3_disable,
> -	.configure = sr_class3_configure,
> -	.class_type = SR_CLASS3,
> -};
> -
> -/* Smartreflex Class3 init API to be called from board file */
> -static int __init sr_class3_init(void)
> -{
> -	pr_info("SmartReflex Class3 initialized\n");
> -	return sr_register_class(&class3_data);
> -}
> -late_initcall(sr_class3_init);
> diff --git a/arch/arm/mach-omap2/smartreflex.c b/arch/arm/mach-omap2/smartreflex.c
> deleted file mode 100644
> index 71f70ca..0000000
> --- a/arch/arm/mach-omap2/smartreflex.c
> +++ /dev/null
> @@ -1,1120 +0,0 @@
> -/*
> - * OMAP SmartReflex Voltage Control
> - *
> - * Author: Thara Gopinath	<thara@ti.com>
> - *
> - * Copyright (C) 2010 Texas Instruments, Inc.
> - * Thara Gopinath <thara@ti.com>
> - *
> - * Copyright (C) 2008 Nokia Corporation
> - * Kalle Jokiniemi
> - *
> - * Copyright (C) 2007 Texas Instruments, Inc.
> - * Lesly A M <x0080970@ti.com>
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License version 2 as
> - * published by the Free Software Foundation.
> - */
> -
> -#include <linux/module.h>
> -#include <linux/interrupt.h>
> -#include <linux/clk.h>
> -#include <linux/io.h>
> -#include <linux/debugfs.h>
> -#include <linux/delay.h>
> -#include <linux/slab.h>
> -#include <linux/pm_runtime.h>
> -#include <linux/power/smartreflex.h>
> -
> -#include "common.h"
> -#include "pm.h"
> -#include "smartreflex.h"
> -
> -#define SMARTREFLEX_NAME_LEN	16
> -#define NVALUE_NAME_LEN		40
> -#define SR_DISABLE_TIMEOUT	200
> -
> -/* sr_list contains all the instances of smartreflex module */
> -static LIST_HEAD(sr_list);
> -
> -static struct omap_sr_class_data *sr_class;
> -static struct omap_sr_pmic_data *sr_pmic_data;
> -static struct dentry		*sr_dbg_dir;
> -
> -static inline void sr_write_reg(struct omap_sr *sr, unsigned offset, u32 value)
> -{
> -	__raw_writel(value, (sr->base + offset));
> -}
> -
> -static inline void sr_modify_reg(struct omap_sr *sr, unsigned offset, u32 mask,
> -					u32 value)
> -{
> -	u32 reg_val;
> -
> -	/*
> -	 * Smartreflex error config register is special as it contains
> -	 * certain status bits which if written a 1 into means a clear
> -	 * of those bits. So in order to make sure no accidental write of
> -	 * 1 happens to those status bits, do a clear of them in the read
> -	 * value. This mean this API doesn't rewrite values in these bits
> -	 * if they are currently set, but does allow the caller to write
> -	 * those bits.
> -	 */
> -	if (sr->ip_type == SR_TYPE_V1 && offset == ERRCONFIG_V1)
> -		mask |= ERRCONFIG_STATUS_V1_MASK;
> -	else if (sr->ip_type == SR_TYPE_V2 && offset == ERRCONFIG_V2)
> -		mask |= ERRCONFIG_VPBOUNDINTST_V2;
> -
> -	reg_val = __raw_readl(sr->base + offset);
> -	reg_val &= ~mask;
> -
> -	value &= mask;
> -
> -	reg_val |= value;
> -
> -	__raw_writel(reg_val, (sr->base + offset));
> -}
> -
> -static inline u32 sr_read_reg(struct omap_sr *sr, unsigned offset)
> -{
> -	return __raw_readl(sr->base + offset);
> -}
> -
> -static struct omap_sr *_sr_lookup(struct voltagedomain *voltdm)
> -{
> -	struct omap_sr *sr_info;
> -
> -	if (!voltdm) {
> -		pr_err("%s: Null voltage domain passed!\n", __func__);
> -		return ERR_PTR(-EINVAL);
> -	}
> -
> -	list_for_each_entry(sr_info, &sr_list, node) {
> -		if (voltdm == sr_info->voltdm)
> -			return sr_info;
> -	}
> -
> -	return ERR_PTR(-ENODATA);
> -}
> -
> -static irqreturn_t sr_interrupt(int irq, void *data)
> -{
> -	struct omap_sr *sr_info = data;
> -	u32 status = 0;
> -
> -	switch (sr_info->ip_type) {
> -	case SR_TYPE_V1:
> -		/* Read the status bits */
> -		status = sr_read_reg(sr_info, ERRCONFIG_V1);
> -
> -		/* Clear them by writing back */
> -		sr_write_reg(sr_info, ERRCONFIG_V1, status);
> -		break;
> -	case SR_TYPE_V2:
> -		/* Read the status bits */
> -		status = sr_read_reg(sr_info, IRQSTATUS);
> -
> -		/* Clear them by writing back */
> -		sr_write_reg(sr_info, IRQSTATUS, status);
> -		break;
> -	default:
> -		dev_err(&sr_info->pdev->dev, "UNKNOWN IP type %d\n",
> -			sr_info->ip_type);
> -		return IRQ_NONE;
> -	}
> -
> -	if (sr_class->notify)
> -		sr_class->notify(sr_info, status);
> -
> -	return IRQ_HANDLED;
> -}
> -
> -static void sr_set_clk_length(struct omap_sr *sr)
> -{
> -	struct clk *sys_ck;
> -	u32 sys_clk_speed;
> -
> -	if (cpu_is_omap34xx())
> -		sys_ck = clk_get(NULL, "sys_ck");
> -	else
> -		sys_ck = clk_get(NULL, "sys_clkin_ck");
> -
> -	if (IS_ERR(sys_ck)) {
> -		dev_err(&sr->pdev->dev, "%s: unable to get sys clk\n",
> -			__func__);
> -		return;
> -	}
> -
> -	sys_clk_speed = clk_get_rate(sys_ck);
> -	clk_put(sys_ck);
> -
> -	switch (sys_clk_speed) {
> -	case 12000000:
> -		sr->clk_length = SRCLKLENGTH_12MHZ_SYSCLK;
> -		break;
> -	case 13000000:
> -		sr->clk_length = SRCLKLENGTH_13MHZ_SYSCLK;
> -		break;
> -	case 19200000:
> -		sr->clk_length = SRCLKLENGTH_19MHZ_SYSCLK;
> -		break;
> -	case 26000000:
> -		sr->clk_length = SRCLKLENGTH_26MHZ_SYSCLK;
> -		break;
> -	case 38400000:
> -		sr->clk_length = SRCLKLENGTH_38MHZ_SYSCLK;
> -		break;
> -	default:
> -		dev_err(&sr->pdev->dev, "%s: Invalid sysclk value: %d\n",
> -			__func__, sys_clk_speed);
> -		break;
> -	}
> -}
> -
> -static void sr_set_regfields(struct omap_sr *sr)
> -{
> -	/*
> -	 * For time being these values are defined in smartreflex.h
> -	 * and populated during init. May be they can be moved to board
> -	 * file or pmic specific data structure. In that case these structure
> -	 * fields will have to be populated using the pdata or pmic structure.
> -	 */
> -	if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
> -		sr->err_weight = OMAP3430_SR_ERRWEIGHT;
> -		sr->err_maxlimit = OMAP3430_SR_ERRMAXLIMIT;
> -		sr->accum_data = OMAP3430_SR_ACCUMDATA;
> -		if (!(strcmp(sr->name, "sr_mpu_iva"))) {
> -			sr->senn_avgweight = OMAP3430_SR1_SENNAVGWEIGHT;
> -			sr->senp_avgweight = OMAP3430_SR1_SENPAVGWEIGHT;
> -		} else {
> -			sr->senn_avgweight = OMAP3430_SR2_SENNAVGWEIGHT;
> -			sr->senp_avgweight = OMAP3430_SR2_SENPAVGWEIGHT;
> -		}
> -	}
> -}
> -
> -static void sr_start_vddautocomp(struct omap_sr *sr)
> -{
> -	if (!sr_class || !(sr_class->enable) || !(sr_class->configure)) {
> -		dev_warn(&sr->pdev->dev,
> -			"%s: smartreflex class driver not registered\n",
> -			__func__);
> -		return;
> -	}
> -
> -	if (!sr_class->enable(sr))
> -		sr->autocomp_active = true;
> -}
> -
> -static void sr_stop_vddautocomp(struct omap_sr *sr)
> -{
> -	if (!sr_class || !(sr_class->disable)) {
> -		dev_warn(&sr->pdev->dev,
> -			"%s: smartreflex class driver not registered\n",
> -			__func__);
> -		return;
> -	}
> -
> -	if (sr->autocomp_active) {
> -		sr_class->disable(sr, 1);
> -		sr->autocomp_active = false;
> -	}
> -}
> -
> -/*
> - * This function handles the intializations which have to be done
> - * only when both sr device and class driver regiter has
> - * completed. This will be attempted to be called from both sr class
> - * driver register and sr device intializtion API's. Only one call
> - * will ultimately succeed.
> - *
> - * Currently this function registers interrupt handler for a particular SR
> - * if smartreflex class driver is already registered and has
> - * requested for interrupts and the SR interrupt line in present.
> - */
> -static int sr_late_init(struct omap_sr *sr_info)
> -{
> -	struct omap_sr_data *pdata = sr_info->pdev->dev.platform_data;
> -	struct resource *mem;
> -	int ret = 0;
> -
> -	if (sr_class->notify && sr_class->notify_flags && sr_info->irq) {
> -		ret = request_irq(sr_info->irq, sr_interrupt,
> -				  0, sr_info->name, sr_info);
> -		if (ret)
> -			goto error;
> -		disable_irq(sr_info->irq);
> -	}
> -
> -	if (pdata && pdata->enable_on_init)
> -		sr_start_vddautocomp(sr_info);
> -
> -	return ret;
> -
> -error:
> -	iounmap(sr_info->base);
> -	mem = platform_get_resource(sr_info->pdev, IORESOURCE_MEM, 0);
> -	release_mem_region(mem->start, resource_size(mem));
> -	list_del(&sr_info->node);
> -	dev_err(&sr_info->pdev->dev, "%s: ERROR in registering"
> -		"interrupt handler. Smartreflex will"
> -		"not function as desired\n", __func__);
> -	kfree(sr_info);
> -
> -	return ret;
> -}
> -
> -static void sr_v1_disable(struct omap_sr *sr)
> -{
> -	int timeout = 0;
> -	int errconf_val = ERRCONFIG_MCUACCUMINTST | ERRCONFIG_MCUVALIDINTST |
> -			ERRCONFIG_MCUBOUNDINTST;
> -
> -	/* Enable MCUDisableAcknowledge interrupt */
> -	sr_modify_reg(sr, ERRCONFIG_V1,
> -			ERRCONFIG_MCUDISACKINTEN, ERRCONFIG_MCUDISACKINTEN);
> -
> -	/* SRCONFIG - disable SR */
> -	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SRENABLE, 0x0);
> -
> -	/* Disable all other SR interrupts and clear the status as needed */
> -	if (sr_read_reg(sr, ERRCONFIG_V1) & ERRCONFIG_VPBOUNDINTST_V1)
> -		errconf_val |= ERRCONFIG_VPBOUNDINTST_V1;
> -	sr_modify_reg(sr, ERRCONFIG_V1,
> -			(ERRCONFIG_MCUACCUMINTEN | ERRCONFIG_MCUVALIDINTEN |
> -			ERRCONFIG_MCUBOUNDINTEN | ERRCONFIG_VPBOUNDINTEN_V1),
> -			errconf_val);
> -
> -	/*
> -	 * Wait for SR to be disabled.
> -	 * wait until ERRCONFIG.MCUDISACKINTST = 1. Typical latency is 1us.
> -	 */
> -	sr_test_cond_timeout((sr_read_reg(sr, ERRCONFIG_V1) &
> -			     ERRCONFIG_MCUDISACKINTST), SR_DISABLE_TIMEOUT,
> -			     timeout);
> -
> -	if (timeout >= SR_DISABLE_TIMEOUT)
> -		dev_warn(&sr->pdev->dev, "%s: Smartreflex disable timedout\n",
> -			__func__);
> -
> -	/* Disable MCUDisableAcknowledge interrupt & clear pending interrupt */
> -	sr_modify_reg(sr, ERRCONFIG_V1, ERRCONFIG_MCUDISACKINTEN,
> -			ERRCONFIG_MCUDISACKINTST);
> -}
> -
> -static void sr_v2_disable(struct omap_sr *sr)
> -{
> -	int timeout = 0;
> -
> -	/* Enable MCUDisableAcknowledge interrupt */
> -	sr_write_reg(sr, IRQENABLE_SET, IRQENABLE_MCUDISABLEACKINT);
> -
> -	/* SRCONFIG - disable SR */
> -	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SRENABLE, 0x0);
> -
> -	/*
> -	 * Disable all other SR interrupts and clear the status
> -	 * write to status register ONLY on need basis - only if status
> -	 * is set.
> -	 */
> -	if (sr_read_reg(sr, ERRCONFIG_V2) & ERRCONFIG_VPBOUNDINTST_V2)
> -		sr_modify_reg(sr, ERRCONFIG_V2, ERRCONFIG_VPBOUNDINTEN_V2,
> -			ERRCONFIG_VPBOUNDINTST_V2);
> -	else
> -		sr_modify_reg(sr, ERRCONFIG_V2, ERRCONFIG_VPBOUNDINTEN_V2,
> -				0x0);
> -	sr_write_reg(sr, IRQENABLE_CLR, (IRQENABLE_MCUACCUMINT |
> -			IRQENABLE_MCUVALIDINT |
> -			IRQENABLE_MCUBOUNDSINT));
> -	sr_write_reg(sr, IRQSTATUS, (IRQSTATUS_MCUACCUMINT |
> -			IRQSTATUS_MCVALIDINT |
> -			IRQSTATUS_MCBOUNDSINT));
> -
> -	/*
> -	 * Wait for SR to be disabled.
> -	 * wait until IRQSTATUS.MCUDISACKINTST = 1. Typical latency is 1us.
> -	 */
> -	sr_test_cond_timeout((sr_read_reg(sr, IRQSTATUS) &
> -			     IRQSTATUS_MCUDISABLEACKINT), SR_DISABLE_TIMEOUT,
> -			     timeout);
> -
> -	if (timeout >= SR_DISABLE_TIMEOUT)
> -		dev_warn(&sr->pdev->dev, "%s: Smartreflex disable timedout\n",
> -			__func__);
> -
> -	/* Disable MCUDisableAcknowledge interrupt & clear pending interrupt */
> -	sr_write_reg(sr, IRQENABLE_CLR, IRQENABLE_MCUDISABLEACKINT);
> -	sr_write_reg(sr, IRQSTATUS, IRQSTATUS_MCUDISABLEACKINT);
> -}
> -
> -static struct omap_sr_nvalue_table *sr_retrieve_nvalue_row(
> -				struct omap_sr *sr,
> -				unsigned long volt_nominal)
> -{
> -	int i;
> -
> -	if (!sr->nvalue_table) {
> -		dev_warn(&sr->pdev->dev, "%s: Missing ntarget value table\n",
> -			__func__);
> -		return NULL;
> -	}
> -
> -	for (i = 0; i < sr->nvalue_count; i++) {
> -		if (sr->nvalue_table[i].volt_nominal == volt_nominal)
> -			return &sr->nvalue_table[i];
> -	}
> -
> -	return NULL;
> -}
> -
> -/* Public Functions */
> -
> -/**
> - * sr_configure_errgen() - Configures the smrtreflex to perform AVS using the
> - *			 error generator module.
> - * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
> - *
> - * This API is to be called from the smartreflex class driver to
> - * configure the error generator module inside the smartreflex module.
> - * SR settings if using the ERROR module inside Smartreflex.
> - * SR CLASS 3 by default uses only the ERROR module where as
> - * SR CLASS 2 can choose between ERROR module and MINMAXAVG
> - * module. Returns 0 on success and error value in case of failure.
> - */
> -int sr_configure_errgen(struct voltagedomain *voltdm)
> -{
> -	u32 sr_config, sr_errconfig, errconfig_offs;
> -	u32 vpboundint_en, vpboundint_st;
> -	u32 senp_en = 0, senn_en = 0;
> -	u8 senp_shift, senn_shift;
> -	struct omap_sr *sr = _sr_lookup(voltdm);
> -
> -	if (IS_ERR(sr)) {
> -		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
> -		return PTR_ERR(sr);
> -	}
> -
> -	if (!sr->clk_length)
> -		sr_set_clk_length(sr);
> -
> -	senp_en = sr->senp_mod;
> -	senn_en = sr->senn_mod;
> -
> -	sr_config = (sr->clk_length << SRCONFIG_SRCLKLENGTH_SHIFT) |
> -		SRCONFIG_SENENABLE | SRCONFIG_ERRGEN_EN;
> -
> -	switch (sr->ip_type) {
> -	case SR_TYPE_V1:
> -		sr_config |= SRCONFIG_DELAYCTRL;
> -		senn_shift = SRCONFIG_SENNENABLE_V1_SHIFT;
> -		senp_shift = SRCONFIG_SENPENABLE_V1_SHIFT;
> -		errconfig_offs = ERRCONFIG_V1;
> -		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V1;
> -		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V1;
> -		break;
> -	case SR_TYPE_V2:
> -		senn_shift = SRCONFIG_SENNENABLE_V2_SHIFT;
> -		senp_shift = SRCONFIG_SENPENABLE_V2_SHIFT;
> -		errconfig_offs = ERRCONFIG_V2;
> -		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V2;
> -		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V2;
> -		break;
> -	default:
> -		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex"
> -			"module without specifying the ip\n", __func__);
> -		return -EINVAL;
> -	}
> -
> -	sr_config |= ((senn_en << senn_shift) | (senp_en << senp_shift));
> -	sr_write_reg(sr, SRCONFIG, sr_config);
> -	sr_errconfig = (sr->err_weight << ERRCONFIG_ERRWEIGHT_SHIFT) |
> -		(sr->err_maxlimit << ERRCONFIG_ERRMAXLIMIT_SHIFT) |
> -		(sr->err_minlimit <<  ERRCONFIG_ERRMINLIMIT_SHIFT);
> -	sr_modify_reg(sr, errconfig_offs, (SR_ERRWEIGHT_MASK |
> -		SR_ERRMAXLIMIT_MASK | SR_ERRMINLIMIT_MASK),
> -		sr_errconfig);
> -
> -	/* Enabling the interrupts if the ERROR module is used */
> -	sr_modify_reg(sr, errconfig_offs, (vpboundint_en | vpboundint_st),
> -		      vpboundint_en);
> -
> -	return 0;
> -}
> -
> -/**
> - * sr_disable_errgen() - Disables SmartReflex AVS module's errgen component
> - * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
> - *
> - * This API is to be called from the smartreflex class driver to
> - * disable the error generator module inside the smartreflex module.
> - *
> - * Returns 0 on success and error value in case of failure.
> - */
> -int sr_disable_errgen(struct voltagedomain *voltdm)
> -{
> -	u32 errconfig_offs;
> -	u32 vpboundint_en, vpboundint_st;
> -	struct omap_sr *sr = _sr_lookup(voltdm);
> -
> -	if (IS_ERR(sr)) {
> -		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
> -		return PTR_ERR(sr);
> -	}
> -
> -	switch (sr->ip_type) {
> -	case SR_TYPE_V1:
> -		errconfig_offs = ERRCONFIG_V1;
> -		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V1;
> -		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V1;
> -		break;
> -	case SR_TYPE_V2:
> -		errconfig_offs = ERRCONFIG_V2;
> -		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V2;
> -		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V2;
> -		break;
> -	default:
> -		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex"
> -			"module without specifying the ip\n", __func__);
> -		return -EINVAL;
> -	}
> -
> -	/* Disable the interrupts of ERROR module */
> -	sr_modify_reg(sr, errconfig_offs, vpboundint_en | vpboundint_st, 0);
> -
> -	/* Disable the Sensor and errorgen */
> -	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SENENABLE | SRCONFIG_ERRGEN_EN, 0);
> -
> -	return 0;
> -}
> -
> -/**
> - * sr_configure_minmax() - Configures the smrtreflex to perform AVS using the
> - *			 minmaxavg module.
> - * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
> - *
> - * This API is to be called from the smartreflex class driver to
> - * configure the minmaxavg module inside the smartreflex module.
> - * SR settings if using the ERROR module inside Smartreflex.
> - * SR CLASS 3 by default uses only the ERROR module where as
> - * SR CLASS 2 can choose between ERROR module and MINMAXAVG
> - * module. Returns 0 on success and error value in case of failure.
> - */
> -int sr_configure_minmax(struct voltagedomain *voltdm)
> -{
> -	u32 sr_config, sr_avgwt;
> -	u32 senp_en = 0, senn_en = 0;
> -	u8 senp_shift, senn_shift;
> -	struct omap_sr *sr = _sr_lookup(voltdm);
> -
> -	if (IS_ERR(sr)) {
> -		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
> -		return PTR_ERR(sr);
> -	}
> -
> -	if (!sr->clk_length)
> -		sr_set_clk_length(sr);
> -
> -	senp_en = sr->senp_mod;
> -	senn_en = sr->senn_mod;
> -
> -	sr_config = (sr->clk_length << SRCONFIG_SRCLKLENGTH_SHIFT) |
> -		SRCONFIG_SENENABLE |
> -		(sr->accum_data << SRCONFIG_ACCUMDATA_SHIFT);
> -
> -	switch (sr->ip_type) {
> -	case SR_TYPE_V1:
> -		sr_config |= SRCONFIG_DELAYCTRL;
> -		senn_shift = SRCONFIG_SENNENABLE_V1_SHIFT;
> -		senp_shift = SRCONFIG_SENPENABLE_V1_SHIFT;
> -		break;
> -	case SR_TYPE_V2:
> -		senn_shift = SRCONFIG_SENNENABLE_V2_SHIFT;
> -		senp_shift = SRCONFIG_SENPENABLE_V2_SHIFT;
> -		break;
> -	default:
> -		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex"
> -			"module without specifying the ip\n", __func__);
> -		return -EINVAL;
> -	}
> -
> -	sr_config |= ((senn_en << senn_shift) | (senp_en << senp_shift));
> -	sr_write_reg(sr, SRCONFIG, sr_config);
> -	sr_avgwt = (sr->senp_avgweight << AVGWEIGHT_SENPAVGWEIGHT_SHIFT) |
> -		(sr->senn_avgweight << AVGWEIGHT_SENNAVGWEIGHT_SHIFT);
> -	sr_write_reg(sr, AVGWEIGHT, sr_avgwt);
> -
> -	/*
> -	 * Enabling the interrupts if MINMAXAVG module is used.
> -	 * TODO: check if all the interrupts are mandatory
> -	 */
> -	switch (sr->ip_type) {
> -	case SR_TYPE_V1:
> -		sr_modify_reg(sr, ERRCONFIG_V1,
> -			(ERRCONFIG_MCUACCUMINTEN | ERRCONFIG_MCUVALIDINTEN |
> -			ERRCONFIG_MCUBOUNDINTEN),
> -			(ERRCONFIG_MCUACCUMINTEN | ERRCONFIG_MCUACCUMINTST |
> -			 ERRCONFIG_MCUVALIDINTEN | ERRCONFIG_MCUVALIDINTST |
> -			 ERRCONFIG_MCUBOUNDINTEN | ERRCONFIG_MCUBOUNDINTST));
> -		break;
> -	case SR_TYPE_V2:
> -		sr_write_reg(sr, IRQSTATUS,
> -			IRQSTATUS_MCUACCUMINT | IRQSTATUS_MCVALIDINT |
> -			IRQSTATUS_MCBOUNDSINT | IRQSTATUS_MCUDISABLEACKINT);
> -		sr_write_reg(sr, IRQENABLE_SET,
> -			IRQENABLE_MCUACCUMINT | IRQENABLE_MCUVALIDINT |
> -			IRQENABLE_MCUBOUNDSINT | IRQENABLE_MCUDISABLEACKINT);
> -		break;
> -	default:
> -		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex"
> -			"module without specifying the ip\n", __func__);
> -		return -EINVAL;
> -	}
> -
> -	return 0;
> -}
> -
> -/**
> - * sr_enable() - Enables the smartreflex module.
> - * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
> - * @volt:	The voltage at which the Voltage domain associated with
> - *		the smartreflex module is operating at.
> - *		This is required only to program the correct Ntarget value.
> - *
> - * This API is to be called from the smartreflex class driver to
> - * enable a smartreflex module. Returns 0 on success. Returns error
> - * value if the voltage passed is wrong or if ntarget value is wrong.
> - */
> -int sr_enable(struct voltagedomain *voltdm, unsigned long volt)
> -{
> -	struct omap_sr *sr = _sr_lookup(voltdm);
> -	struct omap_sr_nvalue_table *nvalue_row;
> -	int ret;
> -
> -	if (IS_ERR(sr)) {
> -		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
> -		return PTR_ERR(sr);
> -	}
> -
> -	nvalue_row = sr_retrieve_nvalue_row(sr, volt);
> -	if (!nvalue_row) {
> -		dev_warn(&sr->pdev->dev, "%s: failure getting SR data for this voltage %ld\n",
> -			 __func__, volt);
> -		return -ENODATA;
> -	}
> -
> -
> -	/* errminlimit is opp dependent and hence linked to voltage */
> -	sr->err_minlimit = nvalue_row->errminlimit;
> -
> -	pm_runtime_get_sync(&sr->pdev->dev);
> -
> -	/* Check if SR is already enabled. If yes do nothing */
> -	if (sr_read_reg(sr, SRCONFIG) & SRCONFIG_SRENABLE)
> -		return 0;
> -
> -	/* Configure SR */
> -	ret = sr_class->configure(sr);
> -	if (ret)
> -		return ret;
> -
> -	sr_write_reg(sr, NVALUERECIPROCAL, nvalue_row->nvalue);
> -
> -	/* SRCONFIG - enable SR */
> -	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SRENABLE, SRCONFIG_SRENABLE);
> -	return 0;
> -}
> -
> -/**
> - * sr_disable() - Disables the smartreflex module.
> - * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
> - *
> - * This API is to be called from the smartreflex class driver to
> - * disable a smartreflex module.
> - */
> -void sr_disable(struct voltagedomain *voltdm)
> -{
> -	struct omap_sr *sr = _sr_lookup(voltdm);
> -
> -	if (IS_ERR(sr)) {
> -		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
> -		return;
> -	}
> -
> -	/* Check if SR clocks are already disabled. If yes do nothing */
> -	if (pm_runtime_suspended(&sr->pdev->dev))
> -		return;
> -
> -	/*
> -	 * Disable SR if only it is indeed enabled. Else just
> -	 * disable the clocks.
> -	 */
> -	if (sr_read_reg(sr, SRCONFIG) & SRCONFIG_SRENABLE) {
> -		switch (sr->ip_type) {
> -		case SR_TYPE_V1:
> -			sr_v1_disable(sr);
> -			break;
> -		case SR_TYPE_V2:
> -			sr_v2_disable(sr);
> -			break;
> -		default:
> -			dev_err(&sr->pdev->dev, "UNKNOWN IP type %d\n",
> -				sr->ip_type);
> -		}
> -	}
> -
> -	pm_runtime_put_sync_suspend(&sr->pdev->dev);
> -}
> -
> -/**
> - * sr_register_class() - API to register a smartreflex class parameters.
> - * @class_data:	The structure containing various sr class specific data.
> - *
> - * This API is to be called by the smartreflex class driver to register itself
> - * with the smartreflex driver during init. Returns 0 on success else the
> - * error value.
> - */
> -int sr_register_class(struct omap_sr_class_data *class_data)
> -{
> -	struct omap_sr *sr_info;
> -
> -	if (!class_data) {
> -		pr_warning("%s:, Smartreflex class data passed is NULL\n",
> -			__func__);
> -		return -EINVAL;
> -	}
> -
> -	if (sr_class) {
> -		pr_warning("%s: Smartreflex class driver already registered\n",
> -			__func__);
> -		return -EBUSY;
> -	}
> -
> -	sr_class = class_data;
> -
> -	/*
> -	 * Call into late init to do intializations that require
> -	 * both sr driver and sr class driver to be initiallized.
> -	 */
> -	list_for_each_entry(sr_info, &sr_list, node)
> -		sr_late_init(sr_info);
> -
> -	return 0;
> -}
> -
> -/**
> - * omap_sr_enable() -  API to enable SR clocks and to call into the
> - *			registered smartreflex class enable API.
> - * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
> - *
> - * This API is to be called from the kernel in order to enable
> - * a particular smartreflex module. This API will do the initial
> - * configurations to turn on the smartreflex module and in turn call
> - * into the registered smartreflex class enable API.
> - */
> -void omap_sr_enable(struct voltagedomain *voltdm)
> -{
> -	struct omap_sr *sr = _sr_lookup(voltdm);
> -
> -	if (IS_ERR(sr)) {
> -		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
> -		return;
> -	}
> -
> -	if (!sr->autocomp_active)
> -		return;
> -
> -	if (!sr_class || !(sr_class->enable) || !(sr_class->configure)) {
> -		dev_warn(&sr->pdev->dev, "%s: smartreflex class driver not"
> -			"registered\n", __func__);
> -		return;
> -	}
> -
> -	sr_class->enable(sr);
> -}
> -
> -/**
> - * omap_sr_disable() - API to disable SR without resetting the voltage
> - *			processor voltage
> - * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
> - *
> - * This API is to be called from the kernel in order to disable
> - * a particular smartreflex module. This API will in turn call
> - * into the registered smartreflex class disable API. This API will tell
> - * the smartreflex class disable not to reset the VP voltage after
> - * disabling smartreflex.
> - */
> -void omap_sr_disable(struct voltagedomain *voltdm)
> -{
> -	struct omap_sr *sr = _sr_lookup(voltdm);
> -
> -	if (IS_ERR(sr)) {
> -		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
> -		return;
> -	}
> -
> -	if (!sr->autocomp_active)
> -		return;
> -
> -	if (!sr_class || !(sr_class->disable)) {
> -		dev_warn(&sr->pdev->dev, "%s: smartreflex class driver not"
> -			"registered\n", __func__);
> -		return;
> -	}
> -
> -	sr_class->disable(sr, 0);
> -}
> -
> -/**
> - * omap_sr_disable_reset_volt() - API to disable SR and reset the
> - *				voltage processor voltage
> - * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
> - *
> - * This API is to be called from the kernel in order to disable
> - * a particular smartreflex module. This API will in turn call
> - * into the registered smartreflex class disable API. This API will tell
> - * the smartreflex class disable to reset the VP voltage after
> - * disabling smartreflex.
> - */
> -void omap_sr_disable_reset_volt(struct voltagedomain *voltdm)
> -{
> -	struct omap_sr *sr = _sr_lookup(voltdm);
> -
> -	if (IS_ERR(sr)) {
> -		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
> -		return;
> -	}
> -
> -	if (!sr->autocomp_active)
> -		return;
> -
> -	if (!sr_class || !(sr_class->disable)) {
> -		dev_warn(&sr->pdev->dev, "%s: smartreflex class driver not"
> -			"registered\n", __func__);
> -		return;
> -	}
> -
> -	sr_class->disable(sr, 1);
> -}
> -
> -/**
> - * omap_sr_register_pmic() - API to register pmic specific info.
> - * @pmic_data:	The structure containing pmic specific data.
> - *
> - * This API is to be called from the PMIC specific code to register with
> - * smartreflex driver pmic specific info. Currently the only info required
> - * is the smartreflex init on the PMIC side.
> - */
> -void omap_sr_register_pmic(struct omap_sr_pmic_data *pmic_data)
> -{
> -	if (!pmic_data) {
> -		pr_warning("%s: Trying to register NULL PMIC data structure"
> -			"with smartreflex\n", __func__);
> -		return;
> -	}
> -
> -	sr_pmic_data = pmic_data;
> -}
> -
> -/* PM Debug FS entries to enable and disable smartreflex. */
> -static int omap_sr_autocomp_show(void *data, u64 *val)
> -{
> -	struct omap_sr *sr_info = data;
> -
> -	if (!sr_info) {
> -		pr_warning("%s: omap_sr struct not found\n", __func__);
> -		return -EINVAL;
> -	}
> -
> -	*val = sr_info->autocomp_active;
> -
> -	return 0;
> -}
> -
> -static int omap_sr_autocomp_store(void *data, u64 val)
> -{
> -	struct omap_sr *sr_info = data;
> -
> -	if (!sr_info) {
> -		pr_warning("%s: omap_sr struct not found\n", __func__);
> -		return -EINVAL;
> -	}
> -
> -	/* Sanity check */
> -	if (val > 1) {
> -		pr_warning("%s: Invalid argument %lld\n", __func__, val);
> -		return -EINVAL;
> -	}
> -
> -	/* control enable/disable only if there is a delta in value */
> -	if (sr_info->autocomp_active != val) {
> -		if (!val)
> -			sr_stop_vddautocomp(sr_info);
> -		else
> -			sr_start_vddautocomp(sr_info);
> -	}
> -
> -	return 0;
> -}
> -
> -DEFINE_SIMPLE_ATTRIBUTE(pm_sr_fops, omap_sr_autocomp_show,
> -			omap_sr_autocomp_store, "%llu\n");
> -
> -static int __init omap_sr_probe(struct platform_device *pdev)
> -{
> -	struct omap_sr *sr_info;
> -	struct omap_sr_data *pdata = pdev->dev.platform_data;
> -	struct resource *mem, *irq;
> -	struct dentry *nvalue_dir;
> -	int i, ret = 0;
> -
> -	sr_info = kzalloc(sizeof(struct omap_sr), GFP_KERNEL);
> -	if (!sr_info) {
> -		dev_err(&pdev->dev, "%s: unable to allocate sr_info\n",
> -			__func__);
> -		return -ENOMEM;
> -	}
> -
> -	platform_set_drvdata(pdev, sr_info);
> -
> -	if (!pdata) {
> -		dev_err(&pdev->dev, "%s: platform data missing\n", __func__);
> -		ret = -EINVAL;
> -		goto err_free_devinfo;
> -	}
> -
> -	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -	if (!mem) {
> -		dev_err(&pdev->dev, "%s: no mem resource\n", __func__);
> -		ret = -ENODEV;
> -		goto err_free_devinfo;
> -	}
> -
> -	mem = request_mem_region(mem->start, resource_size(mem),
> -					dev_name(&pdev->dev));
> -	if (!mem) {
> -		dev_err(&pdev->dev, "%s: no mem region\n", __func__);
> -		ret = -EBUSY;
> -		goto err_free_devinfo;
> -	}
> -
> -	irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> -
> -	pm_runtime_enable(&pdev->dev);
> -	pm_runtime_irq_safe(&pdev->dev);
> -
> -	sr_info->name = kasprintf(GFP_KERNEL, "sr_%s", pdata->name);
> -	if (!sr_info->name) {
> -		dev_err(&pdev->dev, "%s: Unable to alloc SR instance name\n",
> -			__func__);
> -		ret = -ENOMEM;
> -		goto err_release_region;
> -	}
> -
> -	sr_info->pdev = pdev;
> -	sr_info->srid = pdev->id;
> -	sr_info->voltdm = pdata->voltdm;
> -	sr_info->nvalue_table = pdata->nvalue_table;
> -	sr_info->nvalue_count = pdata->nvalue_count;
> -	sr_info->senn_mod = pdata->senn_mod;
> -	sr_info->senp_mod = pdata->senp_mod;
> -	sr_info->autocomp_active = false;
> -	sr_info->ip_type = pdata->ip_type;
> -	sr_info->base = ioremap(mem->start, resource_size(mem));
> -	if (!sr_info->base) {
> -		dev_err(&pdev->dev, "%s: ioremap fail\n", __func__);
> -		ret = -ENOMEM;
> -		goto err_release_region;
> -	}
> -
> -	if (irq)
> -		sr_info->irq = irq->start;
> -
> -	sr_set_clk_length(sr_info);
> -	sr_set_regfields(sr_info);
> -
> -	list_add(&sr_info->node, &sr_list);
> -
> -	/*
> -	 * Call into late init to do intializations that require
> -	 * both sr driver and sr class driver to be initiallized.
> -	 */
> -	if (sr_class) {
> -		ret = sr_late_init(sr_info);
> -		if (ret) {
> -			pr_warning("%s: Error in SR late init\n", __func__);
> -			goto err_iounmap;
> -		}
> -	}
> -
> -	dev_info(&pdev->dev, "%s: SmartReflex driver initialized\n", __func__);
> -	if (!sr_dbg_dir) {
> -		sr_dbg_dir = debugfs_create_dir("smartreflex", NULL);
> -		if (IS_ERR_OR_NULL(sr_dbg_dir)) {
> -			ret = PTR_ERR(sr_dbg_dir);
> -			pr_err("%s:sr debugfs dir creation failed(%d)\n",
> -				__func__, ret);
> -			goto err_iounmap;
> -		}
> -	}
> -
> -	sr_info->dbg_dir = debugfs_create_dir(sr_info->name, sr_dbg_dir);
> -	if (IS_ERR_OR_NULL(sr_info->dbg_dir)) {
> -		dev_err(&pdev->dev, "%s: Unable to create debugfs directory\n",
> -			__func__);
> -		ret = PTR_ERR(sr_info->dbg_dir);
> -		goto err_free_name;
> -	}
> -
> -	(void) debugfs_create_file("autocomp", S_IRUGO | S_IWUSR,
> -			sr_info->dbg_dir, (void *)sr_info, &pm_sr_fops);
> -	(void) debugfs_create_x32("errweight", S_IRUGO, sr_info->dbg_dir,
> -			&sr_info->err_weight);
> -	(void) debugfs_create_x32("errmaxlimit", S_IRUGO, sr_info->dbg_dir,
> -			&sr_info->err_maxlimit);
> -
> -	nvalue_dir = debugfs_create_dir("nvalue", sr_info->dbg_dir);
> -	if (IS_ERR_OR_NULL(nvalue_dir)) {
> -		dev_err(&pdev->dev, "%s: Unable to create debugfs directory"
> -			"for n-values\n", __func__);
> -		ret = PTR_ERR(nvalue_dir);
> -		goto err_debugfs;
> -	}
> -
> -	if (sr_info->nvalue_count == 0 || !sr_info->nvalue_table) {
> -		dev_warn(&pdev->dev, "%s: %s: No Voltage table for the corresponding vdd. Cannot create debugfs entries for n-values\n",
> -			 __func__, sr_info->name);
> -		ret = -ENODATA;
> -		goto err_debugfs;
> -	}
> -
> -	for (i = 0; i < sr_info->nvalue_count; i++) {
> -		char name[NVALUE_NAME_LEN + 1];
> -
> -		snprintf(name, sizeof(name), "volt_%lu",
> -			 sr_info->nvalue_table[i].volt_nominal);
> -		(void) debugfs_create_x32(name, S_IRUGO | S_IWUSR, nvalue_dir,
> -				&(sr_info->nvalue_table[i].nvalue));
> -		snprintf(name, sizeof(name), "errminlimit_%lu",
> -			 sr_info->nvalue_table[i].volt_nominal);
> -		(void) debugfs_create_x32(name, S_IRUGO | S_IWUSR, nvalue_dir,
> -				&(sr_info->nvalue_table[i].errminlimit));
> -	}
> -
> -	return ret;
> -
> -err_debugfs:
> -	debugfs_remove_recursive(sr_info->dbg_dir);
> -err_free_name:
> -	kfree(sr_info->name);
> -err_iounmap:
> -	list_del(&sr_info->node);
> -	iounmap(sr_info->base);
> -err_release_region:
> -	release_mem_region(mem->start, resource_size(mem));
> -err_free_devinfo:
> -	kfree(sr_info);
> -
> -	return ret;
> -}
> -
> -static int __devexit omap_sr_remove(struct platform_device *pdev)
> -{
> -	struct omap_sr_data *pdata = pdev->dev.platform_data;
> -	struct omap_sr *sr_info;
> -	struct resource *mem;
> -
> -	if (!pdata) {
> -		dev_err(&pdev->dev, "%s: platform data missing\n", __func__);
> -		return -EINVAL;
> -	}
> -
> -	sr_info = _sr_lookup(pdata->voltdm);
> -	if (IS_ERR(sr_info)) {
> -		dev_warn(&pdev->dev, "%s: omap_sr struct not found\n",
> -			__func__);
> -		return PTR_ERR(sr_info);
> -	}
> -
> -	if (sr_info->autocomp_active)
> -		sr_stop_vddautocomp(sr_info);
> -	if (sr_info->dbg_dir)
> -		debugfs_remove_recursive(sr_info->dbg_dir);
> -
> -	list_del(&sr_info->node);
> -	iounmap(sr_info->base);
> -	kfree(sr_info->name);
> -	kfree(sr_info);
> -	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -	release_mem_region(mem->start, resource_size(mem));
> -
> -	return 0;
> -}
> -
> -static void __devexit omap_sr_shutdown(struct platform_device *pdev)
> -{
> -	struct omap_sr_data *pdata = pdev->dev.platform_data;
> -	struct omap_sr *sr_info;
> -
> -	if (!pdata) {
> -		dev_err(&pdev->dev, "%s: platform data missing\n", __func__);
> -		return;
> -	}
> -
> -	sr_info = _sr_lookup(pdata->voltdm);
> -	if (IS_ERR(sr_info)) {
> -		dev_warn(&pdev->dev, "%s: omap_sr struct not found\n",
> -			__func__);
> -		return;
> -	}
> -
> -	if (sr_info->autocomp_active)
> -		sr_stop_vddautocomp(sr_info);
> -
> -	return;
> -}
> -
> -static struct platform_driver smartreflex_driver = {
> -	.remove         = __devexit_p(omap_sr_remove),
> -	.shutdown	= __devexit_p(omap_sr_shutdown),
> -	.driver		= {
> -		.name	= "smartreflex",
> -	},
> -};
> -
> -static int __init sr_init(void)
> -{
> -	int ret = 0;
> -
> -	/*
> -	 * sr_init is a late init. If by then a pmic specific API is not
> -	 * registered either there is no need for anything to be done on
> -	 * the PMIC side or somebody has forgotten to register a PMIC
> -	 * handler. Warn for the second condition.
> -	 */
> -	if (sr_pmic_data && sr_pmic_data->sr_pmic_init)
> -		sr_pmic_data->sr_pmic_init();
> -	else
> -		pr_warning("%s: No PMIC hook to init smartreflex\n", __func__);
> -
> -	ret = platform_driver_probe(&smartreflex_driver, omap_sr_probe);
> -	if (ret) {
> -		pr_err("%s: platform driver register failed for SR\n",
> -			__func__);
> -		return ret;
> -	}
> -
> -	return 0;
> -}
> -late_initcall(sr_init);
> -
> -static void __exit sr_exit(void)
> -{
> -	platform_driver_unregister(&smartreflex_driver);
> -}
> -module_exit(sr_exit);
> -
> -MODULE_DESCRIPTION("OMAP Smartreflex Driver");
> -MODULE_LICENSE("GPL");
> -MODULE_ALIAS("platform:" DRIVER_NAME);
> -MODULE_AUTHOR("Texas Instruments Inc");
> diff --git a/arch/arm/mach-omap2/smartreflex.h b/arch/arm/mach-omap2/smartreflex.h
> deleted file mode 100644
> index 754f6aa..0000000
> --- a/arch/arm/mach-omap2/smartreflex.h
> +++ /dev/null
> @@ -1,238 +0,0 @@
> -/*
> - * OMAP Smartreflex Defines and Routines
> - *
> - * Author: Thara Gopinath	<thara@ti.com>
> - *
> - * Copyright (C) 2010 Texas Instruments, Inc.
> - * Thara Gopinath <thara@ti.com>
> - *
> - * Copyright (C) 2008 Nokia Corporation
> - * Kalle Jokiniemi
> - *
> - * Copyright (C) 2007 Texas Instruments, Inc.
> - * Lesly A M <x0080970@ti.com>
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License version 2 as
> - * published by the Free Software Foundation.
> - */
> -
> -#ifndef __DRIVERS_POWER_AVS_SMARTREFLEX_H
> -#define __DRIVERS_POWER_AVS_SMARTREFLEX_H
> -
> -#include <linux/platform_device.h>
> -#include <linux/delay.h>
> -#include <linux/power/smartreflex.h>
> -
> -#include <plat/voltage.h>
> -
> -/*
> - * Different Smartreflex IPs version. The v1 is the 65nm version used in
> - * OMAP3430. The v2 is the update for the 45nm version of the IP
> - * used in OMAP3630 and OMAP4430
> - */
> -#define SR_TYPE_V1	1
> -#define SR_TYPE_V2	2
> -
> -/* SMART REFLEX REG ADDRESS OFFSET */
> -#define SRCONFIG		0x00
> -#define SRSTATUS		0x04
> -#define SENVAL			0x08
> -#define SENMIN			0x0C
> -#define SENMAX			0x10
> -#define SENAVG			0x14
> -#define AVGWEIGHT		0x18
> -#define NVALUERECIPROCAL	0x1c
> -#define SENERROR_V1		0x20
> -#define ERRCONFIG_V1		0x24
> -#define IRQ_EOI			0x20
> -#define IRQSTATUS_RAW		0x24
> -#define IRQSTATUS		0x28
> -#define IRQENABLE_SET		0x2C
> -#define IRQENABLE_CLR		0x30
> -#define SENERROR_V2		0x34
> -#define ERRCONFIG_V2		0x38
> -
> -/* Bit/Shift Positions */
> -
> -/* SRCONFIG */
> -#define SRCONFIG_ACCUMDATA_SHIFT	22
> -#define SRCONFIG_SRCLKLENGTH_SHIFT	12
> -#define SRCONFIG_SENNENABLE_V1_SHIFT	5
> -#define SRCONFIG_SENPENABLE_V1_SHIFT	3
> -#define SRCONFIG_SENNENABLE_V2_SHIFT	1
> -#define SRCONFIG_SENPENABLE_V2_SHIFT	0
> -#define SRCONFIG_CLKCTRL_SHIFT		0
> -
> -#define SRCONFIG_ACCUMDATA_MASK		(0x3ff << 22)
> -
> -#define SRCONFIG_SRENABLE		BIT(11)
> -#define SRCONFIG_SENENABLE		BIT(10)
> -#define SRCONFIG_ERRGEN_EN		BIT(9)
> -#define SRCONFIG_MINMAXAVG_EN		BIT(8)
> -#define SRCONFIG_DELAYCTRL		BIT(2)
> -
> -/* AVGWEIGHT */
> -#define AVGWEIGHT_SENPAVGWEIGHT_SHIFT	2
> -#define AVGWEIGHT_SENNAVGWEIGHT_SHIFT	0
> -
> -/* NVALUERECIPROCAL */
> -#define NVALUERECIPROCAL_SENPGAIN_SHIFT	20
> -#define NVALUERECIPROCAL_SENNGAIN_SHIFT	16
> -#define NVALUERECIPROCAL_RNSENP_SHIFT	8
> -#define NVALUERECIPROCAL_RNSENN_SHIFT	0
> -
> -/* ERRCONFIG */
> -#define ERRCONFIG_ERRWEIGHT_SHIFT	16
> -#define ERRCONFIG_ERRMAXLIMIT_SHIFT	8
> -#define ERRCONFIG_ERRMINLIMIT_SHIFT	0
> -
> -#define SR_ERRWEIGHT_MASK		(0x07 << 16)
> -#define SR_ERRMAXLIMIT_MASK		(0xff << 8)
> -#define SR_ERRMINLIMIT_MASK		(0xff << 0)
> -
> -#define ERRCONFIG_VPBOUNDINTEN_V1	BIT(31)
> -#define ERRCONFIG_VPBOUNDINTST_V1	BIT(30)
> -#define	ERRCONFIG_MCUACCUMINTEN		BIT(29)
> -#define ERRCONFIG_MCUACCUMINTST		BIT(28)
> -#define	ERRCONFIG_MCUVALIDINTEN		BIT(27)
> -#define ERRCONFIG_MCUVALIDINTST		BIT(26)
> -#define ERRCONFIG_MCUBOUNDINTEN		BIT(25)
> -#define	ERRCONFIG_MCUBOUNDINTST		BIT(24)
> -#define	ERRCONFIG_MCUDISACKINTEN	BIT(23)
> -#define ERRCONFIG_VPBOUNDINTST_V2	BIT(23)
> -#define ERRCONFIG_MCUDISACKINTST	BIT(22)
> -#define ERRCONFIG_VPBOUNDINTEN_V2	BIT(22)
> -
> -#define ERRCONFIG_STATUS_V1_MASK	(ERRCONFIG_VPBOUNDINTST_V1 | \
> -					ERRCONFIG_MCUACCUMINTST | \
> -					ERRCONFIG_MCUVALIDINTST | \
> -					ERRCONFIG_MCUBOUNDINTST | \
> -					ERRCONFIG_MCUDISACKINTST)
> -/* IRQSTATUS */
> -#define IRQSTATUS_MCUACCUMINT		BIT(3)
> -#define IRQSTATUS_MCVALIDINT		BIT(2)
> -#define IRQSTATUS_MCBOUNDSINT		BIT(1)
> -#define IRQSTATUS_MCUDISABLEACKINT	BIT(0)
> -
> -/* IRQENABLE_SET and IRQENABLE_CLEAR */
> -#define IRQENABLE_MCUACCUMINT		BIT(3)
> -#define IRQENABLE_MCUVALIDINT		BIT(2)
> -#define IRQENABLE_MCUBOUNDSINT		BIT(1)
> -#define IRQENABLE_MCUDISABLEACKINT	BIT(0)
> -
> -/* Common Bit values */
> -
> -#define SRCLKLENGTH_12MHZ_SYSCLK	0x3c
> -#define SRCLKLENGTH_13MHZ_SYSCLK	0x41
> -#define SRCLKLENGTH_19MHZ_SYSCLK	0x60
> -#define SRCLKLENGTH_26MHZ_SYSCLK	0x82
> -#define SRCLKLENGTH_38MHZ_SYSCLK	0xC0
> -
> -/*
> - * 3430 specific values. Maybe these should be passed from board file or
> - * pmic structures.
> - */
> -#define OMAP3430_SR_ACCUMDATA		0x1f4
> -
> -#define OMAP3430_SR1_SENPAVGWEIGHT	0x03
> -#define OMAP3430_SR1_SENNAVGWEIGHT	0x03
> -
> -#define OMAP3430_SR2_SENPAVGWEIGHT	0x01
> -#define OMAP3430_SR2_SENNAVGWEIGHT	0x01
> -
> -#define OMAP3430_SR_ERRWEIGHT		0x04
> -#define OMAP3430_SR_ERRMAXLIMIT		0x02
> -
> -/**
> - * test_cond_timeout - busy-loop, testing a condition
> - * @cond: condition to test until it evaluates to true
> - * @timeout: maximum number of microseconds in the timeout
> - * @index: loop index (integer)
> - *
> - * Loop waiting for @cond to become true or until at least @timeout
> - * microseconds have passed.  To use, define some integer @index in the
> - * calling code.  After running, if @index == @timeout, then the loop has
> - * timed out.
> - *
> - * Copied from omap_test_timeout
> - */
> -#define sr_test_cond_timeout(cond, timeout, index)		\
> -({								\
> -	for (index = 0; index < timeout; index++) {		\
> -		if (cond)					\
> -			break;					\
> -		udelay(1);					\
> -	}							\
> -})
> -
> -/**
> - * struct omap_sr_pmic_data - Strucutre to be populated by pmic code to pass
> - *				pmic specific info to smartreflex driver
> - *
> - * @sr_pmic_init:	API to initialize smartreflex on the PMIC side.
> - */
> -struct omap_sr_pmic_data {
> -	void (*sr_pmic_init) (void);
> -};
> -
> -
> -#ifdef CONFIG_POWER_AVS_OMAP
> -/*
> - * The smart reflex driver supports CLASS1 CLASS2 and CLASS3 SR.
> - * The smartreflex class driver should pass the class type.
> - * Should be used to populate the class_type field of the
> - * omap_smartreflex_class_data structure.
> - */
> -#define SR_CLASS1	0x1
> -#define SR_CLASS2	0x2
> -#define SR_CLASS3	0x3
> -
> -/**
> - * struct omap_sr_class_data - Smartreflex class driver info
> - *
> - * @enable:		API to enable a particular class smaartreflex.
> - * @disable:		API to disable a particular class smartreflex.
> - * @configure:		API to configure a particular class smartreflex.
> - * @notify:		API to notify the class driver about an event in SR.
> - *			Not needed for class3.
> - * @notify_flags:	specify the events to be notified to the class driver
> - * @class_type:		specify which smartreflex class.
> - *			Can be used by the SR driver to take any class
> - *			based decisions.
> - */
> -struct omap_sr_class_data {
> -	int (*enable)(struct omap_sr *sr);
> -	int (*disable)(struct omap_sr *sr, int is_volt_reset);
> -	int (*configure)(struct omap_sr *sr);
> -	int (*notify)(struct omap_sr *sr, u32 status);
> -	u8 notify_flags;
> -	u8 class_type;
> -};
> -
> -/* Smartreflex module enable/disable interface */
> -void omap_sr_enable(struct voltagedomain *voltdm);
> -void omap_sr_disable(struct voltagedomain *voltdm);
> -void omap_sr_disable_reset_volt(struct voltagedomain *voltdm);
> -
> -/* API to register the pmic specific data with the smartreflex driver. */
> -void omap_sr_register_pmic(struct omap_sr_pmic_data *pmic_data);
> -
> -/* Smartreflex driver hooks to be called from Smartreflex class driver */
> -int sr_enable(struct voltagedomain *voltdm, unsigned long volt);
> -void sr_disable(struct voltagedomain *voltdm);
> -int sr_configure_errgen(struct voltagedomain *voltdm);
> -int sr_disable_errgen(struct voltagedomain *voltdm);
> -int sr_configure_minmax(struct voltagedomain *voltdm);
> -
> -/* API to register the smartreflex class driver with the smartreflex driver */
> -int sr_register_class(struct omap_sr_class_data *class_data);
> -#else
> -static inline void omap_sr_enable(struct voltagedomain *voltdm) {}
> -static inline void omap_sr_disable(struct voltagedomain *voltdm) {}
> -static inline void omap_sr_disable_reset_volt(
> -		struct voltagedomain *voltdm) {}
> -static inline void omap_sr_register_pmic(
> -		struct omap_sr_pmic_data *pmic_data) {}
> -#endif
> -#endif
> diff --git a/arch/arm/plat-omap/Kconfig b/arch/arm/plat-omap/Kconfig
> index 6ec9237..85f70e6 100644
> --- a/arch/arm/plat-omap/Kconfig
> +++ b/arch/arm/plat-omap/Kconfig
> @@ -44,24 +44,9 @@ config OMAP_DEBUG_LEDS
>  	depends on OMAP_DEBUG_DEVICES
>  	default y if LEDS_CLASS
>  
> -menuconfig POWER_AVS
> -	tristate "Adaptive Voltage Scaling class support"
> -	help
> -	  AVS is a power management technique which finely controls the
> -	  operating voltage of a device in order to optimize (i.e. reduce)
> -	  its power consumption.
> -	  At a given operating point the voltage is adapted depending on
> -	  static factors (chip manufacturing process) and dynamic factors
> -	  (temperature depending performance).
> -	  AVS is also called SmartReflex on OMAP devices.
> -
> -	  Say Y here to enable Adaptive Voltage Scaling class support.
> -
> -if POWER_AVS
> -
>  config POWER_AVS_OMAP
>  	bool "AVS support for the OMAP IP versions 1&2"
> -	depends on (ARCH_OMAP3 || ARCH_OMAP4) && PM
> +	depends on POWER_AVS && (ARCH_OMAP3 || ARCH_OMAP4) && PM
>  	help
>  	  Say Y to enable AVS support on OMAP containing the version 1 or
>  	  version 2 of the SmartReflex IP.
> @@ -88,8 +73,6 @@ config POWER_AVS_OMAP_CLASS3
>  	  Class 3 implementation of Smartreflex employs continuous hardware
>  	  voltage calibration.
>  
> -endif # POWER_AVS
> -
>  config OMAP_RESET_CLOCKS
>  	bool "Reset unused clocks during boot"
>  	depends on ARCH_OMAP
> diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
> index 3a8daf8..06f991e 100644
> --- a/drivers/power/Kconfig
> +++ b/drivers/power/Kconfig
> @@ -275,3 +275,5 @@ config CHARGER_MAX8998
>  	  platform data of MAX8998/LP3974 PMICs.
>  
>  endif # POWER_SUPPLY
> +
> +source "drivers/power/avs/Kconfig"
> diff --git a/drivers/power/Makefile b/drivers/power/Makefile
> index e429008..e4a8fd2 100644
> --- a/drivers/power/Makefile
> +++ b/drivers/power/Makefile
> @@ -41,3 +41,5 @@ obj-$(CONFIG_CHARGER_GPIO)	+= gpio-charger.o
>  obj-$(CONFIG_CHARGER_MANAGER)	+= charger-manager.o
>  obj-$(CONFIG_CHARGER_MAX8997)	+= max8997_charger.o
>  obj-$(CONFIG_CHARGER_MAX8998)	+= max8998_charger.o
> +
> +obj-$(CONFIG_POWER_AVS)		+= avs/
> diff --git a/drivers/power/avs/Kconfig b/drivers/power/avs/Kconfig
> new file mode 100644
> index 0000000..18493f7
> --- /dev/null
> +++ b/drivers/power/avs/Kconfig
> @@ -0,0 +1,12 @@
> +menuconfig POWER_AVS
> +	tristate "Adaptive Voltage Scaling class support"
> +	help
> +	  AVS is a power management technique which finely controls the
> +	  operating voltage of a device in order to optimize (i.e. reduce)
> +	  its power consumption.
> +	  At a given operating point the voltage is adapted depending on
> +	  static factors (chip manufacturing process) and dynamic factors
> +	  (temperature depending performance).
> +	  AVS is also called SmartReflex on OMAP devices.
> +
> +	  Say Y here to enable Adaptive Voltage Scaling class support.
> diff --git a/drivers/power/avs/Makefile b/drivers/power/avs/Makefile
> new file mode 100644
> index 0000000..ac72ec5
> --- /dev/null
> +++ b/drivers/power/avs/Makefile
> @@ -0,0 +1,2 @@
> +obj-$(CONFIG_POWER_AVS_OMAP)		+= smartreflex.o
> +obj-$(CONFIG_POWER_AVS_OMAP_CLASS3)	+= smartreflex-class3.o
> diff --git a/drivers/power/avs/smartreflex-class3.c b/drivers/power/avs/smartreflex-class3.c
> new file mode 100644
> index 0000000..413a07b
> --- /dev/null
> +++ b/drivers/power/avs/smartreflex-class3.c
> @@ -0,0 +1,61 @@
> +/*
> + * Smart reflex Class 3 specific implementations
> + *
> + * Author: Thara Gopinath       <thara@ti.com>
> + *
> + * Copyright (C) 2010 Texas Instruments, Inc.
> + * Thara Gopinath <thara@ti.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#include "smartreflex.h"
> +#include <plat/voltage.h>
> +
> +static int sr_class3_enable(struct omap_sr *sr)
> +{
> +	unsigned long volt = voltdm_get_voltage(sr->voltdm);
> +
> +	if (!volt) {
> +		pr_warning("%s: Curr voltage unknown. Cannot enable %s\n",
> +				__func__, sr->name);
> +		return -ENODATA;
> +	}
> +
> +	omap_vp_enable(sr->voltdm);
> +	return sr_enable(sr->voltdm, volt);
> +}
> +
> +static int sr_class3_disable(struct omap_sr *sr, int is_volt_reset)
> +{
> +	sr_disable_errgen(sr->voltdm);
> +	omap_vp_disable(sr->voltdm);
> +	sr_disable(sr->voltdm);
> +	if (is_volt_reset)
> +		voltdm_reset(sr->voltdm);
> +
> +	return 0;
> +}
> +
> +static int sr_class3_configure(struct omap_sr *sr)
> +{
> +	return sr_configure_errgen(sr->voltdm);
> +}
> +
> +/* SR class3 structure */
> +static struct omap_sr_class_data class3_data = {
> +	.enable = sr_class3_enable,
> +	.disable = sr_class3_disable,
> +	.configure = sr_class3_configure,
> +	.class_type = SR_CLASS3,
> +};
> +
> +/* Smartreflex Class3 init API to be called from board file */
> +static int __init sr_class3_init(void)
> +{
> +	pr_info("SmartReflex Class3 initialized\n");
> +	return sr_register_class(&class3_data);
> +}
> +late_initcall(sr_class3_init);
> diff --git a/drivers/power/avs/smartreflex.c b/drivers/power/avs/smartreflex.c
> new file mode 100644
> index 0000000..d3973cb
> --- /dev/null
> +++ b/drivers/power/avs/smartreflex.c
> @@ -0,0 +1,1118 @@
> +/*
> + * OMAP SmartReflex Voltage Control
> + *
> + * Author: Thara Gopinath	<thara@ti.com>
> + *
> + * Copyright (C) 2010 Texas Instruments, Inc.
> + * Thara Gopinath <thara@ti.com>
> + *
> + * Copyright (C) 2008 Nokia Corporation
> + * Kalle Jokiniemi
> + *
> + * Copyright (C) 2007 Texas Instruments, Inc.
> + * Lesly A M <x0080970@ti.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/interrupt.h>
> +#include <linux/clk.h>
> +#include <linux/io.h>
> +#include <linux/debugfs.h>
> +#include <linux/delay.h>
> +#include <linux/slab.h>
> +#include <linux/pm_runtime.h>
> +#include <linux/power/smartreflex.h>
> +
> +#include "smartreflex.h"
> +
> +#define SMARTREFLEX_NAME_LEN	16
> +#define NVALUE_NAME_LEN		40
> +#define SR_DISABLE_TIMEOUT	200
> +
> +/* sr_list contains all the instances of smartreflex module */
> +static LIST_HEAD(sr_list);
> +
> +static struct omap_sr_class_data *sr_class;
> +static struct omap_sr_pmic_data *sr_pmic_data;
> +static struct dentry		*sr_dbg_dir;
> +
> +static inline void sr_write_reg(struct omap_sr *sr, unsigned offset, u32 value)
> +{
> +	__raw_writel(value, (sr->base + offset));
> +}
> +
> +static inline void sr_modify_reg(struct omap_sr *sr, unsigned offset, u32 mask,
> +					u32 value)
> +{
> +	u32 reg_val;
> +
> +	/*
> +	 * Smartreflex error config register is special as it contains
> +	 * certain status bits which if written a 1 into means a clear
> +	 * of those bits. So in order to make sure no accidental write of
> +	 * 1 happens to those status bits, do a clear of them in the read
> +	 * value. This mean this API doesn't rewrite values in these bits
> +	 * if they are currently set, but does allow the caller to write
> +	 * those bits.
> +	 */
> +	if (sr->ip_type == SR_TYPE_V1 && offset == ERRCONFIG_V1)
> +		mask |= ERRCONFIG_STATUS_V1_MASK;
> +	else if (sr->ip_type == SR_TYPE_V2 && offset == ERRCONFIG_V2)
> +		mask |= ERRCONFIG_VPBOUNDINTST_V2;
> +
> +	reg_val = __raw_readl(sr->base + offset);
> +	reg_val &= ~mask;
> +
> +	value &= mask;
> +
> +	reg_val |= value;
> +
> +	__raw_writel(reg_val, (sr->base + offset));
> +}
> +
> +static inline u32 sr_read_reg(struct omap_sr *sr, unsigned offset)
> +{
> +	return __raw_readl(sr->base + offset);
> +}
> +
> +static struct omap_sr *_sr_lookup(struct voltagedomain *voltdm)
> +{
> +	struct omap_sr *sr_info;
> +
> +	if (!voltdm) {
> +		pr_err("%s: Null voltage domain passed!\n", __func__);
> +		return ERR_PTR(-EINVAL);
> +	}
> +
> +	list_for_each_entry(sr_info, &sr_list, node) {
> +		if (voltdm == sr_info->voltdm)
> +			return sr_info;
> +	}
> +
> +	return ERR_PTR(-ENODATA);
> +}
> +
> +static irqreturn_t sr_interrupt(int irq, void *data)
> +{
> +	struct omap_sr *sr_info = data;
> +	u32 status = 0;
> +
> +	switch (sr_info->ip_type) {
> +	case SR_TYPE_V1:
> +		/* Read the status bits */
> +		status = sr_read_reg(sr_info, ERRCONFIG_V1);
> +
> +		/* Clear them by writing back */
> +		sr_write_reg(sr_info, ERRCONFIG_V1, status);
> +		break;
> +	case SR_TYPE_V2:
> +		/* Read the status bits */
> +		status = sr_read_reg(sr_info, IRQSTATUS);
> +
> +		/* Clear them by writing back */
> +		sr_write_reg(sr_info, IRQSTATUS, status);
> +		break;
> +	default:
> +		dev_err(&sr_info->pdev->dev, "UNKNOWN IP type %d\n",
> +			sr_info->ip_type);
> +		return IRQ_NONE;
> +	}
> +
> +	if (sr_class->notify)
> +		sr_class->notify(sr_info, status);
> +
> +	return IRQ_HANDLED;
> +}
> +
> +static void sr_set_clk_length(struct omap_sr *sr)
> +{
> +	struct clk *sys_ck;
> +	u32 sys_clk_speed;
> +
> +	if (cpu_is_omap34xx())
> +		sys_ck = clk_get(NULL, "sys_ck");
> +	else
> +		sys_ck = clk_get(NULL, "sys_clkin_ck");
> +
> +	if (IS_ERR(sys_ck)) {
> +		dev_err(&sr->pdev->dev, "%s: unable to get sys clk\n",
> +			__func__);
> +		return;
> +	}
> +
> +	sys_clk_speed = clk_get_rate(sys_ck);
> +	clk_put(sys_ck);
> +
> +	switch (sys_clk_speed) {
> +	case 12000000:
> +		sr->clk_length = SRCLKLENGTH_12MHZ_SYSCLK;
> +		break;
> +	case 13000000:
> +		sr->clk_length = SRCLKLENGTH_13MHZ_SYSCLK;
> +		break;
> +	case 19200000:
> +		sr->clk_length = SRCLKLENGTH_19MHZ_SYSCLK;
> +		break;
> +	case 26000000:
> +		sr->clk_length = SRCLKLENGTH_26MHZ_SYSCLK;
> +		break;
> +	case 38400000:
> +		sr->clk_length = SRCLKLENGTH_38MHZ_SYSCLK;
> +		break;
> +	default:
> +		dev_err(&sr->pdev->dev, "%s: Invalid sysclk value: %d\n",
> +			__func__, sys_clk_speed);
> +		break;
> +	}
> +}
> +
> +static void sr_set_regfields(struct omap_sr *sr)
> +{
> +	/*
> +	 * For time being these values are defined in smartreflex.h
> +	 * and populated during init. May be they can be moved to board
> +	 * file or pmic specific data structure. In that case these structure
> +	 * fields will have to be populated using the pdata or pmic structure.
> +	 */
> +	if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
> +		sr->err_weight = OMAP3430_SR_ERRWEIGHT;
> +		sr->err_maxlimit = OMAP3430_SR_ERRMAXLIMIT;
> +		sr->accum_data = OMAP3430_SR_ACCUMDATA;
> +		if (!(strcmp(sr->name, "sr_mpu_iva"))) {
> +			sr->senn_avgweight = OMAP3430_SR1_SENNAVGWEIGHT;
> +			sr->senp_avgweight = OMAP3430_SR1_SENPAVGWEIGHT;
> +		} else {
> +			sr->senn_avgweight = OMAP3430_SR2_SENNAVGWEIGHT;
> +			sr->senp_avgweight = OMAP3430_SR2_SENPAVGWEIGHT;
> +		}
> +	}
> +}
> +
> +static void sr_start_vddautocomp(struct omap_sr *sr)
> +{
> +	if (!sr_class || !(sr_class->enable) || !(sr_class->configure)) {
> +		dev_warn(&sr->pdev->dev,
> +			"%s: smartreflex class driver not registered\n",
> +			__func__);
> +		return;
> +	}
> +
> +	if (!sr_class->enable(sr))
> +		sr->autocomp_active = true;
> +}
> +
> +static void sr_stop_vddautocomp(struct omap_sr *sr)
> +{
> +	if (!sr_class || !(sr_class->disable)) {
> +		dev_warn(&sr->pdev->dev,
> +			"%s: smartreflex class driver not registered\n",
> +			__func__);
> +		return;
> +	}
> +
> +	if (sr->autocomp_active) {
> +		sr_class->disable(sr, 1);
> +		sr->autocomp_active = false;
> +	}
> +}
> +
> +/*
> + * This function handles the intializations which have to be done
> + * only when both sr device and class driver regiter has
> + * completed. This will be attempted to be called from both sr class
> + * driver register and sr device intializtion API's. Only one call
> + * will ultimately succeed.
> + *
> + * Currently this function registers interrupt handler for a particular SR
> + * if smartreflex class driver is already registered and has
> + * requested for interrupts and the SR interrupt line in present.
> + */
> +static int sr_late_init(struct omap_sr *sr_info)
> +{
> +	struct omap_sr_data *pdata = sr_info->pdev->dev.platform_data;
> +	struct resource *mem;
> +	int ret = 0;
> +
> +	if (sr_class->notify && sr_class->notify_flags && sr_info->irq) {
> +		ret = request_irq(sr_info->irq, sr_interrupt,
> +				  0, sr_info->name, sr_info);
> +		if (ret)
> +			goto error;
> +		disable_irq(sr_info->irq);
> +	}
> +
> +	if (pdata && pdata->enable_on_init)
> +		sr_start_vddautocomp(sr_info);
> +
> +	return ret;
> +
> +error:
> +	iounmap(sr_info->base);
> +	mem = platform_get_resource(sr_info->pdev, IORESOURCE_MEM, 0);
> +	release_mem_region(mem->start, resource_size(mem));
> +	list_del(&sr_info->node);
> +	dev_err(&sr_info->pdev->dev, "%s: ERROR in registering"
> +		"interrupt handler. Smartreflex will"
> +		"not function as desired\n", __func__);
> +	kfree(sr_info);
> +
> +	return ret;
> +}
> +
> +static void sr_v1_disable(struct omap_sr *sr)
> +{
> +	int timeout = 0;
> +	int errconf_val = ERRCONFIG_MCUACCUMINTST | ERRCONFIG_MCUVALIDINTST |
> +			ERRCONFIG_MCUBOUNDINTST;
> +
> +	/* Enable MCUDisableAcknowledge interrupt */
> +	sr_modify_reg(sr, ERRCONFIG_V1,
> +			ERRCONFIG_MCUDISACKINTEN, ERRCONFIG_MCUDISACKINTEN);
> +
> +	/* SRCONFIG - disable SR */
> +	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SRENABLE, 0x0);
> +
> +	/* Disable all other SR interrupts and clear the status as needed */
> +	if (sr_read_reg(sr, ERRCONFIG_V1) & ERRCONFIG_VPBOUNDINTST_V1)
> +		errconf_val |= ERRCONFIG_VPBOUNDINTST_V1;
> +	sr_modify_reg(sr, ERRCONFIG_V1,
> +			(ERRCONFIG_MCUACCUMINTEN | ERRCONFIG_MCUVALIDINTEN |
> +			ERRCONFIG_MCUBOUNDINTEN | ERRCONFIG_VPBOUNDINTEN_V1),
> +			errconf_val);
> +
> +	/*
> +	 * Wait for SR to be disabled.
> +	 * wait until ERRCONFIG.MCUDISACKINTST = 1. Typical latency is 1us.
> +	 */
> +	sr_test_cond_timeout((sr_read_reg(sr, ERRCONFIG_V1) &
> +			     ERRCONFIG_MCUDISACKINTST), SR_DISABLE_TIMEOUT,
> +			     timeout);
> +
> +	if (timeout >= SR_DISABLE_TIMEOUT)
> +		dev_warn(&sr->pdev->dev, "%s: Smartreflex disable timedout\n",
> +			__func__);
> +
> +	/* Disable MCUDisableAcknowledge interrupt & clear pending interrupt */
> +	sr_modify_reg(sr, ERRCONFIG_V1, ERRCONFIG_MCUDISACKINTEN,
> +			ERRCONFIG_MCUDISACKINTST);
> +}
> +
> +static void sr_v2_disable(struct omap_sr *sr)
> +{
> +	int timeout = 0;
> +
> +	/* Enable MCUDisableAcknowledge interrupt */
> +	sr_write_reg(sr, IRQENABLE_SET, IRQENABLE_MCUDISABLEACKINT);
> +
> +	/* SRCONFIG - disable SR */
> +	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SRENABLE, 0x0);
> +
> +	/*
> +	 * Disable all other SR interrupts and clear the status
> +	 * write to status register ONLY on need basis - only if status
> +	 * is set.
> +	 */
> +	if (sr_read_reg(sr, ERRCONFIG_V2) & ERRCONFIG_VPBOUNDINTST_V2)
> +		sr_modify_reg(sr, ERRCONFIG_V2, ERRCONFIG_VPBOUNDINTEN_V2,
> +			ERRCONFIG_VPBOUNDINTST_V2);
> +	else
> +		sr_modify_reg(sr, ERRCONFIG_V2, ERRCONFIG_VPBOUNDINTEN_V2,
> +				0x0);
> +	sr_write_reg(sr, IRQENABLE_CLR, (IRQENABLE_MCUACCUMINT |
> +			IRQENABLE_MCUVALIDINT |
> +			IRQENABLE_MCUBOUNDSINT));
> +	sr_write_reg(sr, IRQSTATUS, (IRQSTATUS_MCUACCUMINT |
> +			IRQSTATUS_MCVALIDINT |
> +			IRQSTATUS_MCBOUNDSINT));
> +
> +	/*
> +	 * Wait for SR to be disabled.
> +	 * wait until IRQSTATUS.MCUDISACKINTST = 1. Typical latency is 1us.
> +	 */
> +	sr_test_cond_timeout((sr_read_reg(sr, IRQSTATUS) &
> +			     IRQSTATUS_MCUDISABLEACKINT), SR_DISABLE_TIMEOUT,
> +			     timeout);
> +
> +	if (timeout >= SR_DISABLE_TIMEOUT)
> +		dev_warn(&sr->pdev->dev, "%s: Smartreflex disable timedout\n",
> +			__func__);
> +
> +	/* Disable MCUDisableAcknowledge interrupt & clear pending interrupt */
> +	sr_write_reg(sr, IRQENABLE_CLR, IRQENABLE_MCUDISABLEACKINT);
> +	sr_write_reg(sr, IRQSTATUS, IRQSTATUS_MCUDISABLEACKINT);
> +}
> +
> +static struct omap_sr_nvalue_table *sr_retrieve_nvalue_row(
> +				struct omap_sr *sr,
> +				unsigned long volt_nominal)
> +{
> +	int i;
> +
> +	if (!sr->nvalue_table) {
> +		dev_warn(&sr->pdev->dev, "%s: Missing ntarget value table\n",
> +			__func__);
> +		return NULL;
> +	}
> +
> +	for (i = 0; i < sr->nvalue_count; i++) {
> +		if (sr->nvalue_table[i].volt_nominal == volt_nominal)
> +			return &sr->nvalue_table[i];
> +	}
> +
> +	return NULL;
> +}
> +
> +/* Public Functions */
> +
> +/**
> + * sr_configure_errgen() - Configures the smrtreflex to perform AVS using the
> + *			 error generator module.
> + * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
> + *
> + * This API is to be called from the smartreflex class driver to
> + * configure the error generator module inside the smartreflex module.
> + * SR settings if using the ERROR module inside Smartreflex.
> + * SR CLASS 3 by default uses only the ERROR module where as
> + * SR CLASS 2 can choose between ERROR module and MINMAXAVG
> + * module. Returns 0 on success and error value in case of failure.
> + */
> +int sr_configure_errgen(struct voltagedomain *voltdm)
> +{
> +	u32 sr_config, sr_errconfig, errconfig_offs;
> +	u32 vpboundint_en, vpboundint_st;
> +	u32 senp_en = 0, senn_en = 0;
> +	u8 senp_shift, senn_shift;
> +	struct omap_sr *sr = _sr_lookup(voltdm);
> +
> +	if (IS_ERR(sr)) {
> +		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
> +		return PTR_ERR(sr);
> +	}
> +
> +	if (!sr->clk_length)
> +		sr_set_clk_length(sr);
> +
> +	senp_en = sr->senp_mod;
> +	senn_en = sr->senn_mod;
> +
> +	sr_config = (sr->clk_length << SRCONFIG_SRCLKLENGTH_SHIFT) |
> +		SRCONFIG_SENENABLE | SRCONFIG_ERRGEN_EN;
> +
> +	switch (sr->ip_type) {
> +	case SR_TYPE_V1:
> +		sr_config |= SRCONFIG_DELAYCTRL;
> +		senn_shift = SRCONFIG_SENNENABLE_V1_SHIFT;
> +		senp_shift = SRCONFIG_SENPENABLE_V1_SHIFT;
> +		errconfig_offs = ERRCONFIG_V1;
> +		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V1;
> +		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V1;
> +		break;
> +	case SR_TYPE_V2:
> +		senn_shift = SRCONFIG_SENNENABLE_V2_SHIFT;
> +		senp_shift = SRCONFIG_SENPENABLE_V2_SHIFT;
> +		errconfig_offs = ERRCONFIG_V2;
> +		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V2;
> +		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V2;
> +		break;
> +	default:
> +		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex"
> +			"module without specifying the ip\n", __func__);
> +		return -EINVAL;
> +	}
> +
> +	sr_config |= ((senn_en << senn_shift) | (senp_en << senp_shift));
> +	sr_write_reg(sr, SRCONFIG, sr_config);
> +	sr_errconfig = (sr->err_weight << ERRCONFIG_ERRWEIGHT_SHIFT) |
> +		(sr->err_maxlimit << ERRCONFIG_ERRMAXLIMIT_SHIFT) |
> +		(sr->err_minlimit <<  ERRCONFIG_ERRMINLIMIT_SHIFT);
> +	sr_modify_reg(sr, errconfig_offs, (SR_ERRWEIGHT_MASK |
> +		SR_ERRMAXLIMIT_MASK | SR_ERRMINLIMIT_MASK),
> +		sr_errconfig);
> +
> +	/* Enabling the interrupts if the ERROR module is used */
> +	sr_modify_reg(sr, errconfig_offs, (vpboundint_en | vpboundint_st),
> +		      vpboundint_en);
> +
> +	return 0;
> +}
> +
> +/**
> + * sr_disable_errgen() - Disables SmartReflex AVS module's errgen component
> + * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
> + *
> + * This API is to be called from the smartreflex class driver to
> + * disable the error generator module inside the smartreflex module.
> + *
> + * Returns 0 on success and error value in case of failure.
> + */
> +int sr_disable_errgen(struct voltagedomain *voltdm)
> +{
> +	u32 errconfig_offs;
> +	u32 vpboundint_en, vpboundint_st;
> +	struct omap_sr *sr = _sr_lookup(voltdm);
> +
> +	if (IS_ERR(sr)) {
> +		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
> +		return PTR_ERR(sr);
> +	}
> +
> +	switch (sr->ip_type) {
> +	case SR_TYPE_V1:
> +		errconfig_offs = ERRCONFIG_V1;
> +		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V1;
> +		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V1;
> +		break;
> +	case SR_TYPE_V2:
> +		errconfig_offs = ERRCONFIG_V2;
> +		vpboundint_en = ERRCONFIG_VPBOUNDINTEN_V2;
> +		vpboundint_st = ERRCONFIG_VPBOUNDINTST_V2;
> +		break;
> +	default:
> +		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex"
> +			"module without specifying the ip\n", __func__);
> +		return -EINVAL;
> +	}
> +
> +	/* Disable the interrupts of ERROR module */
> +	sr_modify_reg(sr, errconfig_offs, vpboundint_en | vpboundint_st, 0);
> +
> +	/* Disable the Sensor and errorgen */
> +	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SENENABLE | SRCONFIG_ERRGEN_EN, 0);
> +
> +	return 0;
> +}
> +
> +/**
> + * sr_configure_minmax() - Configures the smrtreflex to perform AVS using the
> + *			 minmaxavg module.
> + * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
> + *
> + * This API is to be called from the smartreflex class driver to
> + * configure the minmaxavg module inside the smartreflex module.
> + * SR settings if using the ERROR module inside Smartreflex.
> + * SR CLASS 3 by default uses only the ERROR module where as
> + * SR CLASS 2 can choose between ERROR module and MINMAXAVG
> + * module. Returns 0 on success and error value in case of failure.
> + */
> +int sr_configure_minmax(struct voltagedomain *voltdm)
> +{
> +	u32 sr_config, sr_avgwt;
> +	u32 senp_en = 0, senn_en = 0;
> +	u8 senp_shift, senn_shift;
> +	struct omap_sr *sr = _sr_lookup(voltdm);
> +
> +	if (IS_ERR(sr)) {
> +		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
> +		return PTR_ERR(sr);
> +	}
> +
> +	if (!sr->clk_length)
> +		sr_set_clk_length(sr);
> +
> +	senp_en = sr->senp_mod;
> +	senn_en = sr->senn_mod;
> +
> +	sr_config = (sr->clk_length << SRCONFIG_SRCLKLENGTH_SHIFT) |
> +		SRCONFIG_SENENABLE |
> +		(sr->accum_data << SRCONFIG_ACCUMDATA_SHIFT);
> +
> +	switch (sr->ip_type) {
> +	case SR_TYPE_V1:
> +		sr_config |= SRCONFIG_DELAYCTRL;
> +		senn_shift = SRCONFIG_SENNENABLE_V1_SHIFT;
> +		senp_shift = SRCONFIG_SENPENABLE_V1_SHIFT;
> +		break;
> +	case SR_TYPE_V2:
> +		senn_shift = SRCONFIG_SENNENABLE_V2_SHIFT;
> +		senp_shift = SRCONFIG_SENPENABLE_V2_SHIFT;
> +		break;
> +	default:
> +		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex"
> +			"module without specifying the ip\n", __func__);
> +		return -EINVAL;
> +	}
> +
> +	sr_config |= ((senn_en << senn_shift) | (senp_en << senp_shift));
> +	sr_write_reg(sr, SRCONFIG, sr_config);
> +	sr_avgwt = (sr->senp_avgweight << AVGWEIGHT_SENPAVGWEIGHT_SHIFT) |
> +		(sr->senn_avgweight << AVGWEIGHT_SENNAVGWEIGHT_SHIFT);
> +	sr_write_reg(sr, AVGWEIGHT, sr_avgwt);
> +
> +	/*
> +	 * Enabling the interrupts if MINMAXAVG module is used.
> +	 * TODO: check if all the interrupts are mandatory
> +	 */
> +	switch (sr->ip_type) {
> +	case SR_TYPE_V1:
> +		sr_modify_reg(sr, ERRCONFIG_V1,
> +			(ERRCONFIG_MCUACCUMINTEN | ERRCONFIG_MCUVALIDINTEN |
> +			ERRCONFIG_MCUBOUNDINTEN),
> +			(ERRCONFIG_MCUACCUMINTEN | ERRCONFIG_MCUACCUMINTST |
> +			 ERRCONFIG_MCUVALIDINTEN | ERRCONFIG_MCUVALIDINTST |
> +			 ERRCONFIG_MCUBOUNDINTEN | ERRCONFIG_MCUBOUNDINTST));
> +		break;
> +	case SR_TYPE_V2:
> +		sr_write_reg(sr, IRQSTATUS,
> +			IRQSTATUS_MCUACCUMINT | IRQSTATUS_MCVALIDINT |
> +			IRQSTATUS_MCBOUNDSINT | IRQSTATUS_MCUDISABLEACKINT);
> +		sr_write_reg(sr, IRQENABLE_SET,
> +			IRQENABLE_MCUACCUMINT | IRQENABLE_MCUVALIDINT |
> +			IRQENABLE_MCUBOUNDSINT | IRQENABLE_MCUDISABLEACKINT);
> +		break;
> +	default:
> +		dev_err(&sr->pdev->dev, "%s: Trying to Configure smartreflex"
> +			"module without specifying the ip\n", __func__);
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
> +/**
> + * sr_enable() - Enables the smartreflex module.
> + * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
> + * @volt:	The voltage at which the Voltage domain associated with
> + *		the smartreflex module is operating at.
> + *		This is required only to program the correct Ntarget value.
> + *
> + * This API is to be called from the smartreflex class driver to
> + * enable a smartreflex module. Returns 0 on success. Returns error
> + * value if the voltage passed is wrong or if ntarget value is wrong.
> + */
> +int sr_enable(struct voltagedomain *voltdm, unsigned long volt)
> +{
> +	struct omap_sr *sr = _sr_lookup(voltdm);
> +	struct omap_sr_nvalue_table *nvalue_row;
> +	int ret;
> +
> +	if (IS_ERR(sr)) {
> +		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
> +		return PTR_ERR(sr);
> +	}
> +
> +	nvalue_row = sr_retrieve_nvalue_row(sr, volt);
> +	if (!nvalue_row) {
> +		dev_warn(&sr->pdev->dev, "%s: failure getting SR data for this voltage %ld\n",
> +			 __func__, volt);
> +		return -ENODATA;
> +	}
> +
> +
> +	/* errminlimit is opp dependent and hence linked to voltage */
> +	sr->err_minlimit = nvalue_row->errminlimit;
> +
> +	pm_runtime_get_sync(&sr->pdev->dev);
> +
> +	/* Check if SR is already enabled. If yes do nothing */
> +	if (sr_read_reg(sr, SRCONFIG) & SRCONFIG_SRENABLE)
> +		return 0;
> +
> +	/* Configure SR */
> +	ret = sr_class->configure(sr);
> +	if (ret)
> +		return ret;
> +
> +	sr_write_reg(sr, NVALUERECIPROCAL, nvalue_row->nvalue);
> +
> +	/* SRCONFIG - enable SR */
> +	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SRENABLE, SRCONFIG_SRENABLE);
> +	return 0;
> +}
> +
> +/**
> + * sr_disable() - Disables the smartreflex module.
> + * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
> + *
> + * This API is to be called from the smartreflex class driver to
> + * disable a smartreflex module.
> + */
> +void sr_disable(struct voltagedomain *voltdm)
> +{
> +	struct omap_sr *sr = _sr_lookup(voltdm);
> +
> +	if (IS_ERR(sr)) {
> +		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
> +		return;
> +	}
> +
> +	/* Check if SR clocks are already disabled. If yes do nothing */
> +	if (pm_runtime_suspended(&sr->pdev->dev))
> +		return;
> +
> +	/*
> +	 * Disable SR if only it is indeed enabled. Else just
> +	 * disable the clocks.
> +	 */
> +	if (sr_read_reg(sr, SRCONFIG) & SRCONFIG_SRENABLE) {
> +		switch (sr->ip_type) {
> +		case SR_TYPE_V1:
> +			sr_v1_disable(sr);
> +			break;
> +		case SR_TYPE_V2:
> +			sr_v2_disable(sr);
> +			break;
> +		default:
> +			dev_err(&sr->pdev->dev, "UNKNOWN IP type %d\n",
> +				sr->ip_type);
> +		}
> +	}
> +
> +	pm_runtime_put_sync_suspend(&sr->pdev->dev);
> +}
> +
> +/**
> + * sr_register_class() - API to register a smartreflex class parameters.
> + * @class_data:	The structure containing various sr class specific data.
> + *
> + * This API is to be called by the smartreflex class driver to register itself
> + * with the smartreflex driver during init. Returns 0 on success else the
> + * error value.
> + */
> +int sr_register_class(struct omap_sr_class_data *class_data)
> +{
> +	struct omap_sr *sr_info;
> +
> +	if (!class_data) {
> +		pr_warning("%s:, Smartreflex class data passed is NULL\n",
> +			__func__);
> +		return -EINVAL;
> +	}
> +
> +	if (sr_class) {
> +		pr_warning("%s: Smartreflex class driver already registered\n",
> +			__func__);
> +		return -EBUSY;
> +	}
> +
> +	sr_class = class_data;
> +
> +	/*
> +	 * Call into late init to do intializations that require
> +	 * both sr driver and sr class driver to be initiallized.
> +	 */
> +	list_for_each_entry(sr_info, &sr_list, node)
> +		sr_late_init(sr_info);
> +
> +	return 0;
> +}
> +
> +/**
> + * omap_sr_enable() -  API to enable SR clocks and to call into the
> + *			registered smartreflex class enable API.
> + * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
> + *
> + * This API is to be called from the kernel in order to enable
> + * a particular smartreflex module. This API will do the initial
> + * configurations to turn on the smartreflex module and in turn call
> + * into the registered smartreflex class enable API.
> + */
> +void omap_sr_enable(struct voltagedomain *voltdm)
> +{
> +	struct omap_sr *sr = _sr_lookup(voltdm);
> +
> +	if (IS_ERR(sr)) {
> +		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
> +		return;
> +	}
> +
> +	if (!sr->autocomp_active)
> +		return;
> +
> +	if (!sr_class || !(sr_class->enable) || !(sr_class->configure)) {
> +		dev_warn(&sr->pdev->dev, "%s: smartreflex class driver not"
> +			"registered\n", __func__);
> +		return;
> +	}
> +
> +	sr_class->enable(sr);
> +}
> +
> +/**
> + * omap_sr_disable() - API to disable SR without resetting the voltage
> + *			processor voltage
> + * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
> + *
> + * This API is to be called from the kernel in order to disable
> + * a particular smartreflex module. This API will in turn call
> + * into the registered smartreflex class disable API. This API will tell
> + * the smartreflex class disable not to reset the VP voltage after
> + * disabling smartreflex.
> + */
> +void omap_sr_disable(struct voltagedomain *voltdm)
> +{
> +	struct omap_sr *sr = _sr_lookup(voltdm);
> +
> +	if (IS_ERR(sr)) {
> +		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
> +		return;
> +	}
> +
> +	if (!sr->autocomp_active)
> +		return;
> +
> +	if (!sr_class || !(sr_class->disable)) {
> +		dev_warn(&sr->pdev->dev, "%s: smartreflex class driver not"
> +			"registered\n", __func__);
> +		return;
> +	}
> +
> +	sr_class->disable(sr, 0);
> +}
> +
> +/**
> + * omap_sr_disable_reset_volt() - API to disable SR and reset the
> + *				voltage processor voltage
> + * @voltdm:	VDD pointer to which the SR module to be configured belongs to.
> + *
> + * This API is to be called from the kernel in order to disable
> + * a particular smartreflex module. This API will in turn call
> + * into the registered smartreflex class disable API. This API will tell
> + * the smartreflex class disable to reset the VP voltage after
> + * disabling smartreflex.
> + */
> +void omap_sr_disable_reset_volt(struct voltagedomain *voltdm)
> +{
> +	struct omap_sr *sr = _sr_lookup(voltdm);
> +
> +	if (IS_ERR(sr)) {
> +		pr_warning("%s: omap_sr struct for voltdm not found\n",	__func__);
> +		return;
> +	}
> +
> +	if (!sr->autocomp_active)
> +		return;
> +
> +	if (!sr_class || !(sr_class->disable)) {
> +		dev_warn(&sr->pdev->dev, "%s: smartreflex class driver not"
> +			"registered\n", __func__);
> +		return;
> +	}
> +
> +	sr_class->disable(sr, 1);
> +}
> +
> +/**
> + * omap_sr_register_pmic() - API to register pmic specific info.
> + * @pmic_data:	The structure containing pmic specific data.
> + *
> + * This API is to be called from the PMIC specific code to register with
> + * smartreflex driver pmic specific info. Currently the only info required
> + * is the smartreflex init on the PMIC side.
> + */
> +void omap_sr_register_pmic(struct omap_sr_pmic_data *pmic_data)
> +{
> +	if (!pmic_data) {
> +		pr_warning("%s: Trying to register NULL PMIC data structure"
> +			"with smartreflex\n", __func__);
> +		return;
> +	}
> +
> +	sr_pmic_data = pmic_data;
> +}
> +
> +/* PM Debug FS entries to enable and disable smartreflex. */
> +static int omap_sr_autocomp_show(void *data, u64 *val)
> +{
> +	struct omap_sr *sr_info = data;
> +
> +	if (!sr_info) {
> +		pr_warning("%s: omap_sr struct not found\n", __func__);
> +		return -EINVAL;
> +	}
> +
> +	*val = sr_info->autocomp_active;
> +
> +	return 0;
> +}
> +
> +static int omap_sr_autocomp_store(void *data, u64 val)
> +{
> +	struct omap_sr *sr_info = data;
> +
> +	if (!sr_info) {
> +		pr_warning("%s: omap_sr struct not found\n", __func__);
> +		return -EINVAL;
> +	}
> +
> +	/* Sanity check */
> +	if (val > 1) {
> +		pr_warning("%s: Invalid argument %lld\n", __func__, val);
> +		return -EINVAL;
> +	}
> +
> +	/* control enable/disable only if there is a delta in value */
> +	if (sr_info->autocomp_active != val) {
> +		if (!val)
> +			sr_stop_vddautocomp(sr_info);
> +		else
> +			sr_start_vddautocomp(sr_info);
> +	}
> +
> +	return 0;
> +}
> +
> +DEFINE_SIMPLE_ATTRIBUTE(pm_sr_fops, omap_sr_autocomp_show,
> +			omap_sr_autocomp_store, "%llu\n");
> +
> +static int __init omap_sr_probe(struct platform_device *pdev)
> +{
> +	struct omap_sr *sr_info;
> +	struct omap_sr_data *pdata = pdev->dev.platform_data;
> +	struct resource *mem, *irq;
> +	struct dentry *nvalue_dir;
> +	int i, ret = 0;
> +
> +	sr_info = kzalloc(sizeof(struct omap_sr), GFP_KERNEL);
> +	if (!sr_info) {
> +		dev_err(&pdev->dev, "%s: unable to allocate sr_info\n",
> +			__func__);
> +		return -ENOMEM;
> +	}
> +
> +	platform_set_drvdata(pdev, sr_info);
> +
> +	if (!pdata) {
> +		dev_err(&pdev->dev, "%s: platform data missing\n", __func__);
> +		ret = -EINVAL;
> +		goto err_free_devinfo;
> +	}
> +
> +	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!mem) {
> +		dev_err(&pdev->dev, "%s: no mem resource\n", __func__);
> +		ret = -ENODEV;
> +		goto err_free_devinfo;
> +	}
> +
> +	mem = request_mem_region(mem->start, resource_size(mem),
> +					dev_name(&pdev->dev));
> +	if (!mem) {
> +		dev_err(&pdev->dev, "%s: no mem region\n", __func__);
> +		ret = -EBUSY;
> +		goto err_free_devinfo;
> +	}
> +
> +	irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> +
> +	pm_runtime_enable(&pdev->dev);
> +	pm_runtime_irq_safe(&pdev->dev);
> +
> +	sr_info->name = kasprintf(GFP_KERNEL, "sr_%s", pdata->name);
> +	if (!sr_info->name) {
> +		dev_err(&pdev->dev, "%s: Unable to alloc SR instance name\n",
> +			__func__);
> +		ret = -ENOMEM;
> +		goto err_release_region;
> +	}
> +
> +	sr_info->pdev = pdev;
> +	sr_info->srid = pdev->id;
> +	sr_info->voltdm = pdata->voltdm;
> +	sr_info->nvalue_table = pdata->nvalue_table;
> +	sr_info->nvalue_count = pdata->nvalue_count;
> +	sr_info->senn_mod = pdata->senn_mod;
> +	sr_info->senp_mod = pdata->senp_mod;
> +	sr_info->autocomp_active = false;
> +	sr_info->ip_type = pdata->ip_type;
> +	sr_info->base = ioremap(mem->start, resource_size(mem));
> +	if (!sr_info->base) {
> +		dev_err(&pdev->dev, "%s: ioremap fail\n", __func__);
> +		ret = -ENOMEM;
> +		goto err_release_region;
> +	}
> +
> +	if (irq)
> +		sr_info->irq = irq->start;
> +
> +	sr_set_clk_length(sr_info);
> +	sr_set_regfields(sr_info);
> +
> +	list_add(&sr_info->node, &sr_list);
> +
> +	/*
> +	 * Call into late init to do intializations that require
> +	 * both sr driver and sr class driver to be initiallized.
> +	 */
> +	if (sr_class) {
> +		ret = sr_late_init(sr_info);
> +		if (ret) {
> +			pr_warning("%s: Error in SR late init\n", __func__);
> +			goto err_iounmap;
> +		}
> +	}
> +
> +	dev_info(&pdev->dev, "%s: SmartReflex driver initialized\n", __func__);
> +	if (!sr_dbg_dir) {
> +		sr_dbg_dir = debugfs_create_dir("smartreflex", NULL);
> +		if (IS_ERR_OR_NULL(sr_dbg_dir)) {
> +			ret = PTR_ERR(sr_dbg_dir);
> +			pr_err("%s:sr debugfs dir creation failed(%d)\n",
> +				__func__, ret);
> +			goto err_iounmap;
> +		}
> +	}
> +
> +	sr_info->dbg_dir = debugfs_create_dir(sr_info->name, sr_dbg_dir);
> +	if (IS_ERR_OR_NULL(sr_info->dbg_dir)) {
> +		dev_err(&pdev->dev, "%s: Unable to create debugfs directory\n",
> +			__func__);
> +		ret = PTR_ERR(sr_info->dbg_dir);
> +		goto err_free_name;
> +	}
> +
> +	(void) debugfs_create_file("autocomp", S_IRUGO | S_IWUSR,
> +			sr_info->dbg_dir, (void *)sr_info, &pm_sr_fops);
> +	(void) debugfs_create_x32("errweight", S_IRUGO, sr_info->dbg_dir,
> +			&sr_info->err_weight);
> +	(void) debugfs_create_x32("errmaxlimit", S_IRUGO, sr_info->dbg_dir,
> +			&sr_info->err_maxlimit);
> +
> +	nvalue_dir = debugfs_create_dir("nvalue", sr_info->dbg_dir);
> +	if (IS_ERR_OR_NULL(nvalue_dir)) {
> +		dev_err(&pdev->dev, "%s: Unable to create debugfs directory"
> +			"for n-values\n", __func__);
> +		ret = PTR_ERR(nvalue_dir);
> +		goto err_debugfs;
> +	}
> +
> +	if (sr_info->nvalue_count == 0 || !sr_info->nvalue_table) {
> +		dev_warn(&pdev->dev, "%s: %s: No Voltage table for the corresponding vdd. Cannot create debugfs entries for n-values\n",
> +			 __func__, sr_info->name);
> +		ret = -ENODATA;
> +		goto err_debugfs;
> +	}
> +
> +	for (i = 0; i < sr_info->nvalue_count; i++) {
> +		char name[NVALUE_NAME_LEN + 1];
> +
> +		snprintf(name, sizeof(name), "volt_%lu",
> +			 sr_info->nvalue_table[i].volt_nominal);
> +		(void) debugfs_create_x32(name, S_IRUGO | S_IWUSR, nvalue_dir,
> +				&(sr_info->nvalue_table[i].nvalue));
> +		snprintf(name, sizeof(name), "errminlimit_%lu",
> +			 sr_info->nvalue_table[i].volt_nominal);
> +		(void) debugfs_create_x32(name, S_IRUGO | S_IWUSR, nvalue_dir,
> +				&(sr_info->nvalue_table[i].errminlimit));
> +	}
> +
> +	return ret;
> +
> +err_debugfs:
> +	debugfs_remove_recursive(sr_info->dbg_dir);
> +err_free_name:
> +	kfree(sr_info->name);
> +err_iounmap:
> +	list_del(&sr_info->node);
> +	iounmap(sr_info->base);
> +err_release_region:
> +	release_mem_region(mem->start, resource_size(mem));
> +err_free_devinfo:
> +	kfree(sr_info);
> +
> +	return ret;
> +}
> +
> +static int __devexit omap_sr_remove(struct platform_device *pdev)
> +{
> +	struct omap_sr_data *pdata = pdev->dev.platform_data;
> +	struct omap_sr *sr_info;
> +	struct resource *mem;
> +
> +	if (!pdata) {
> +		dev_err(&pdev->dev, "%s: platform data missing\n", __func__);
> +		return -EINVAL;
> +	}
> +
> +	sr_info = _sr_lookup(pdata->voltdm);
> +	if (IS_ERR(sr_info)) {
> +		dev_warn(&pdev->dev, "%s: omap_sr struct not found\n",
> +			__func__);
> +		return PTR_ERR(sr_info);
> +	}
> +
> +	if (sr_info->autocomp_active)
> +		sr_stop_vddautocomp(sr_info);
> +	if (sr_info->dbg_dir)
> +		debugfs_remove_recursive(sr_info->dbg_dir);
> +
> +	list_del(&sr_info->node);
> +	iounmap(sr_info->base);
> +	kfree(sr_info->name);
> +	kfree(sr_info);
> +	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	release_mem_region(mem->start, resource_size(mem));
> +
> +	return 0;
> +}
> +
> +static void __devexit omap_sr_shutdown(struct platform_device *pdev)
> +{
> +	struct omap_sr_data *pdata = pdev->dev.platform_data;
> +	struct omap_sr *sr_info;
> +
> +	if (!pdata) {
> +		dev_err(&pdev->dev, "%s: platform data missing\n", __func__);
> +		return;
> +	}
> +
> +	sr_info = _sr_lookup(pdata->voltdm);
> +	if (IS_ERR(sr_info)) {
> +		dev_warn(&pdev->dev, "%s: omap_sr struct not found\n",
> +			__func__);
> +		return;
> +	}
> +
> +	if (sr_info->autocomp_active)
> +		sr_stop_vddautocomp(sr_info);
> +
> +	return;
> +}
> +
> +static struct platform_driver smartreflex_driver = {
> +	.remove         = __devexit_p(omap_sr_remove),
> +	.shutdown	= __devexit_p(omap_sr_shutdown),
> +	.driver		= {
> +		.name	= "smartreflex",
> +	},
> +};
> +
> +static int __init sr_init(void)
> +{
> +	int ret = 0;
> +
> +	/*
> +	 * sr_init is a late init. If by then a pmic specific API is not
> +	 * registered either there is no need for anything to be done on
> +	 * the PMIC side or somebody has forgotten to register a PMIC
> +	 * handler. Warn for the second condition.
> +	 */
> +	if (sr_pmic_data && sr_pmic_data->sr_pmic_init)
> +		sr_pmic_data->sr_pmic_init();
> +	else
> +		pr_warning("%s: No PMIC hook to init smartreflex\n", __func__);
> +
> +	ret = platform_driver_probe(&smartreflex_driver, omap_sr_probe);
> +	if (ret) {
> +		pr_err("%s: platform driver register failed for SR\n",
> +			__func__);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +late_initcall(sr_init);
> +
> +static void __exit sr_exit(void)
> +{
> +	platform_driver_unregister(&smartreflex_driver);
> +}
> +module_exit(sr_exit);
> +
> +MODULE_DESCRIPTION("OMAP Smartreflex Driver");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("platform:" DRIVER_NAME);
> +MODULE_AUTHOR("Texas Instruments Inc");
> diff --git a/drivers/power/avs/smartreflex.h b/drivers/power/avs/smartreflex.h
> new file mode 100644
> index 0000000..754f6aa
> --- /dev/null
> +++ b/drivers/power/avs/smartreflex.h
> @@ -0,0 +1,238 @@
> +/*
> + * OMAP Smartreflex Defines and Routines
> + *
> + * Author: Thara Gopinath	<thara@ti.com>
> + *
> + * Copyright (C) 2010 Texas Instruments, Inc.
> + * Thara Gopinath <thara@ti.com>
> + *
> + * Copyright (C) 2008 Nokia Corporation
> + * Kalle Jokiniemi
> + *
> + * Copyright (C) 2007 Texas Instruments, Inc.
> + * Lesly A M <x0080970@ti.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#ifndef __DRIVERS_POWER_AVS_SMARTREFLEX_H
> +#define __DRIVERS_POWER_AVS_SMARTREFLEX_H
> +
> +#include <linux/platform_device.h>
> +#include <linux/delay.h>
> +#include <linux/power/smartreflex.h>
> +
> +#include <plat/voltage.h>
> +
> +/*
> + * Different Smartreflex IPs version. The v1 is the 65nm version used in
> + * OMAP3430. The v2 is the update for the 45nm version of the IP
> + * used in OMAP3630 and OMAP4430
> + */
> +#define SR_TYPE_V1	1
> +#define SR_TYPE_V2	2
> +
> +/* SMART REFLEX REG ADDRESS OFFSET */
> +#define SRCONFIG		0x00
> +#define SRSTATUS		0x04
> +#define SENVAL			0x08
> +#define SENMIN			0x0C
> +#define SENMAX			0x10
> +#define SENAVG			0x14
> +#define AVGWEIGHT		0x18
> +#define NVALUERECIPROCAL	0x1c
> +#define SENERROR_V1		0x20
> +#define ERRCONFIG_V1		0x24
> +#define IRQ_EOI			0x20
> +#define IRQSTATUS_RAW		0x24
> +#define IRQSTATUS		0x28
> +#define IRQENABLE_SET		0x2C
> +#define IRQENABLE_CLR		0x30
> +#define SENERROR_V2		0x34
> +#define ERRCONFIG_V2		0x38
> +
> +/* Bit/Shift Positions */
> +
> +/* SRCONFIG */
> +#define SRCONFIG_ACCUMDATA_SHIFT	22
> +#define SRCONFIG_SRCLKLENGTH_SHIFT	12
> +#define SRCONFIG_SENNENABLE_V1_SHIFT	5
> +#define SRCONFIG_SENPENABLE_V1_SHIFT	3
> +#define SRCONFIG_SENNENABLE_V2_SHIFT	1
> +#define SRCONFIG_SENPENABLE_V2_SHIFT	0
> +#define SRCONFIG_CLKCTRL_SHIFT		0
> +
> +#define SRCONFIG_ACCUMDATA_MASK		(0x3ff << 22)
> +
> +#define SRCONFIG_SRENABLE		BIT(11)
> +#define SRCONFIG_SENENABLE		BIT(10)
> +#define SRCONFIG_ERRGEN_EN		BIT(9)
> +#define SRCONFIG_MINMAXAVG_EN		BIT(8)
> +#define SRCONFIG_DELAYCTRL		BIT(2)
> +
> +/* AVGWEIGHT */
> +#define AVGWEIGHT_SENPAVGWEIGHT_SHIFT	2
> +#define AVGWEIGHT_SENNAVGWEIGHT_SHIFT	0
> +
> +/* NVALUERECIPROCAL */
> +#define NVALUERECIPROCAL_SENPGAIN_SHIFT	20
> +#define NVALUERECIPROCAL_SENNGAIN_SHIFT	16
> +#define NVALUERECIPROCAL_RNSENP_SHIFT	8
> +#define NVALUERECIPROCAL_RNSENN_SHIFT	0
> +
> +/* ERRCONFIG */
> +#define ERRCONFIG_ERRWEIGHT_SHIFT	16
> +#define ERRCONFIG_ERRMAXLIMIT_SHIFT	8
> +#define ERRCONFIG_ERRMINLIMIT_SHIFT	0
> +
> +#define SR_ERRWEIGHT_MASK		(0x07 << 16)
> +#define SR_ERRMAXLIMIT_MASK		(0xff << 8)
> +#define SR_ERRMINLIMIT_MASK		(0xff << 0)
> +
> +#define ERRCONFIG_VPBOUNDINTEN_V1	BIT(31)
> +#define ERRCONFIG_VPBOUNDINTST_V1	BIT(30)
> +#define	ERRCONFIG_MCUACCUMINTEN		BIT(29)
> +#define ERRCONFIG_MCUACCUMINTST		BIT(28)
> +#define	ERRCONFIG_MCUVALIDINTEN		BIT(27)
> +#define ERRCONFIG_MCUVALIDINTST		BIT(26)
> +#define ERRCONFIG_MCUBOUNDINTEN		BIT(25)
> +#define	ERRCONFIG_MCUBOUNDINTST		BIT(24)
> +#define	ERRCONFIG_MCUDISACKINTEN	BIT(23)
> +#define ERRCONFIG_VPBOUNDINTST_V2	BIT(23)
> +#define ERRCONFIG_MCUDISACKINTST	BIT(22)
> +#define ERRCONFIG_VPBOUNDINTEN_V2	BIT(22)
> +
> +#define ERRCONFIG_STATUS_V1_MASK	(ERRCONFIG_VPBOUNDINTST_V1 | \
> +					ERRCONFIG_MCUACCUMINTST | \
> +					ERRCONFIG_MCUVALIDINTST | \
> +					ERRCONFIG_MCUBOUNDINTST | \
> +					ERRCONFIG_MCUDISACKINTST)
> +/* IRQSTATUS */
> +#define IRQSTATUS_MCUACCUMINT		BIT(3)
> +#define IRQSTATUS_MCVALIDINT		BIT(2)
> +#define IRQSTATUS_MCBOUNDSINT		BIT(1)
> +#define IRQSTATUS_MCUDISABLEACKINT	BIT(0)
> +
> +/* IRQENABLE_SET and IRQENABLE_CLEAR */
> +#define IRQENABLE_MCUACCUMINT		BIT(3)
> +#define IRQENABLE_MCUVALIDINT		BIT(2)
> +#define IRQENABLE_MCUBOUNDSINT		BIT(1)
> +#define IRQENABLE_MCUDISABLEACKINT	BIT(0)
> +
> +/* Common Bit values */
> +
> +#define SRCLKLENGTH_12MHZ_SYSCLK	0x3c
> +#define SRCLKLENGTH_13MHZ_SYSCLK	0x41
> +#define SRCLKLENGTH_19MHZ_SYSCLK	0x60
> +#define SRCLKLENGTH_26MHZ_SYSCLK	0x82
> +#define SRCLKLENGTH_38MHZ_SYSCLK	0xC0
> +
> +/*
> + * 3430 specific values. Maybe these should be passed from board file or
> + * pmic structures.
> + */
> +#define OMAP3430_SR_ACCUMDATA		0x1f4
> +
> +#define OMAP3430_SR1_SENPAVGWEIGHT	0x03
> +#define OMAP3430_SR1_SENNAVGWEIGHT	0x03
> +
> +#define OMAP3430_SR2_SENPAVGWEIGHT	0x01
> +#define OMAP3430_SR2_SENNAVGWEIGHT	0x01
> +
> +#define OMAP3430_SR_ERRWEIGHT		0x04
> +#define OMAP3430_SR_ERRMAXLIMIT		0x02
> +
> +/**
> + * test_cond_timeout - busy-loop, testing a condition
> + * @cond: condition to test until it evaluates to true
> + * @timeout: maximum number of microseconds in the timeout
> + * @index: loop index (integer)
> + *
> + * Loop waiting for @cond to become true or until at least @timeout
> + * microseconds have passed.  To use, define some integer @index in the
> + * calling code.  After running, if @index == @timeout, then the loop has
> + * timed out.
> + *
> + * Copied from omap_test_timeout
> + */
> +#define sr_test_cond_timeout(cond, timeout, index)		\
> +({								\
> +	for (index = 0; index < timeout; index++) {		\
> +		if (cond)					\
> +			break;					\
> +		udelay(1);					\
> +	}							\
> +})
> +
> +/**
> + * struct omap_sr_pmic_data - Strucutre to be populated by pmic code to pass
> + *				pmic specific info to smartreflex driver
> + *
> + * @sr_pmic_init:	API to initialize smartreflex on the PMIC side.
> + */
> +struct omap_sr_pmic_data {
> +	void (*sr_pmic_init) (void);
> +};
> +
> +
> +#ifdef CONFIG_POWER_AVS_OMAP
> +/*
> + * The smart reflex driver supports CLASS1 CLASS2 and CLASS3 SR.
> + * The smartreflex class driver should pass the class type.
> + * Should be used to populate the class_type field of the
> + * omap_smartreflex_class_data structure.
> + */
> +#define SR_CLASS1	0x1
> +#define SR_CLASS2	0x2
> +#define SR_CLASS3	0x3
> +
> +/**
> + * struct omap_sr_class_data - Smartreflex class driver info
> + *
> + * @enable:		API to enable a particular class smaartreflex.
> + * @disable:		API to disable a particular class smartreflex.
> + * @configure:		API to configure a particular class smartreflex.
> + * @notify:		API to notify the class driver about an event in SR.
> + *			Not needed for class3.
> + * @notify_flags:	specify the events to be notified to the class driver
> + * @class_type:		specify which smartreflex class.
> + *			Can be used by the SR driver to take any class
> + *			based decisions.
> + */
> +struct omap_sr_class_data {
> +	int (*enable)(struct omap_sr *sr);
> +	int (*disable)(struct omap_sr *sr, int is_volt_reset);
> +	int (*configure)(struct omap_sr *sr);
> +	int (*notify)(struct omap_sr *sr, u32 status);
> +	u8 notify_flags;
> +	u8 class_type;
> +};
> +
> +/* Smartreflex module enable/disable interface */
> +void omap_sr_enable(struct voltagedomain *voltdm);
> +void omap_sr_disable(struct voltagedomain *voltdm);
> +void omap_sr_disable_reset_volt(struct voltagedomain *voltdm);
> +
> +/* API to register the pmic specific data with the smartreflex driver. */
> +void omap_sr_register_pmic(struct omap_sr_pmic_data *pmic_data);
> +
> +/* Smartreflex driver hooks to be called from Smartreflex class driver */
> +int sr_enable(struct voltagedomain *voltdm, unsigned long volt);
> +void sr_disable(struct voltagedomain *voltdm);
> +int sr_configure_errgen(struct voltagedomain *voltdm);
> +int sr_disable_errgen(struct voltagedomain *voltdm);
> +int sr_configure_minmax(struct voltagedomain *voltdm);
> +
> +/* API to register the smartreflex class driver with the smartreflex driver */
> +int sr_register_class(struct omap_sr_class_data *class_data);
> +#else
> +static inline void omap_sr_enable(struct voltagedomain *voltdm) {}
> +static inline void omap_sr_disable(struct voltagedomain *voltdm) {}
> +static inline void omap_sr_disable_reset_volt(
> +		struct voltagedomain *voltdm) {}
> +static inline void omap_sr_register_pmic(
> +		struct omap_sr_pmic_data *pmic_data) {}
> +#endif
> +#endif

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 7/9] ARM: OMAP2+: SmartReflex: Use per-OPP data structure
  2012-03-19 16:12 ` [PATCH 7/9] ARM: OMAP2+: SmartReflex: Use per-OPP data structure jean.pihet
@ 2012-04-18 18:21   ` Kevin Hilman
  2012-04-18 20:52     ` Jean Pihet
  0 siblings, 1 reply; 31+ messages in thread
From: Kevin Hilman @ 2012-04-18 18:21 UTC (permalink / raw)
  To: jean.pihet
  Cc: linux-omap, linux-arm-kernel, Rafael J. Wysocki, LKML,
	Jean Pihet, Paul Walmsley, Thara Gopinath, Nishanth Menon

jean.pihet@newoldbits.com writes:

> From: Jean Pihet <j-pihet@ti.com>
>
> The SmartReflex driver incorrectly treats some per-OPP data as data
> common to all OPPs (e.g., ERRMINLIMIT).  Move this data into a per-OPP
> data structure.

OK

> The SmartReflex driver should not be dependent on whether the host SoC
> uses eFuses to store SmartReflex parameters or not.  (Even SoCs that
> do store SR data in eFuses often need to override that data with
> software-defined values.)  So, convert sr_retrieve_nvalue() to look up
> per-OPP data by the OPP's nominal voltage, rather than by the eFuse
> offset.

Right.

> While at it:
>  . tidy up the code wrt default values in the data tables,
>  . remove the global errminlimit debugfs entry and create per-voltage
>    entries from the data tables.

OK

> Furthermore, in order to make the SmartReflex implementation ready for
> the move to drivers/, remove the dependency from the SR driver code
> to the voltage layer by querying the data tables only from the SR device
> init code.

So that's 4 relatively independent things going on in this patch which
makes it somewhat difficult to review and understand.

I'd suggest breaking it up into smaller parts if possible.  If not, fix
up the changelog to describe why all of these need to go together, and
why it's necessary to do them before the move.

Thanks,

Kevin

> Based on Paul's original code for the SmartReflex driver conversion.
>
> Signed-off-by: Jean Pihet <j-pihet@ti.com>
> Cc: Paul Walmsley <paul@pwsan.com>
> Cc: Thara Gopinath <thara@ti.com>
> Cc: Nishanth Menon <nm@ti.com>
> Cc: Kevin Hilman <khilman@ti.com>
> ---
>  arch/arm/mach-omap2/smartreflex.c |   57 +++++++++++++++---------------------
>  arch/arm/mach-omap2/sr_device.c   |   35 +++++++++++++++++++----
>  include/linux/power/smartreflex.h |    8 ++++-
>  3 files changed, 59 insertions(+), 41 deletions(-)
>
> diff --git a/arch/arm/mach-omap2/smartreflex.c b/arch/arm/mach-omap2/smartreflex.c
> index 5f3faf3..71f70ca 100644
> --- a/arch/arm/mach-omap2/smartreflex.c
> +++ b/arch/arm/mach-omap2/smartreflex.c
> @@ -348,22 +348,24 @@ static void sr_v2_disable(struct omap_sr *sr)
>  	sr_write_reg(sr, IRQSTATUS, IRQSTATUS_MCUDISABLEACKINT);
>  }
>  
> -static u32 sr_retrieve_nvalue(struct omap_sr *sr, u32 efuse_offs)
> +static struct omap_sr_nvalue_table *sr_retrieve_nvalue_row(
> +				struct omap_sr *sr,
> +				unsigned long volt_nominal)
>  {
>  	int i;
>  
>  	if (!sr->nvalue_table) {
>  		dev_warn(&sr->pdev->dev, "%s: Missing ntarget value table\n",
>  			__func__);
> -		return 0;
> +		return NULL;
>  	}
>  
>  	for (i = 0; i < sr->nvalue_count; i++) {
> -		if (sr->nvalue_table[i].efuse_offs == efuse_offs)
> -			return sr->nvalue_table[i].nvalue;
> +		if (sr->nvalue_table[i].volt_nominal == volt_nominal)
> +			return &sr->nvalue_table[i];
>  	}
>  
> -	return 0;
> +	return NULL;
>  }
>  
>  /* Public Functions */
> @@ -585,9 +587,8 @@ int sr_configure_minmax(struct voltagedomain *voltdm)
>   */
>  int sr_enable(struct voltagedomain *voltdm, unsigned long volt)
>  {
> -	struct omap_volt_data *volt_data;
>  	struct omap_sr *sr = _sr_lookup(voltdm);
> -	u32 nvalue_reciprocal;
> +	struct omap_sr_nvalue_table *nvalue_row;
>  	int ret;
>  
>  	if (IS_ERR(sr)) {
> @@ -595,24 +596,16 @@ int sr_enable(struct voltagedomain *voltdm, unsigned long volt)
>  		return PTR_ERR(sr);
>  	}
>  
> -	volt_data = omap_voltage_get_voltdata(sr->voltdm, volt);
> -
> -	if (IS_ERR(volt_data)) {
> -		dev_warn(&sr->pdev->dev, "%s: Unable to get voltage table"
> -			"for nominal voltage %ld\n", __func__, volt);
> -		return PTR_ERR(volt_data);
> -	}
> -
> -	nvalue_reciprocal = sr_retrieve_nvalue(sr, volt_data->sr_efuse_offs);
> -
> -	if (!nvalue_reciprocal) {
> -		dev_warn(&sr->pdev->dev, "%s: NVALUE = 0 at voltage %ld\n",
> -			__func__, volt);
> +	nvalue_row = sr_retrieve_nvalue_row(sr, volt);
> +	if (!nvalue_row) {
> +		dev_warn(&sr->pdev->dev, "%s: failure getting SR data for this voltage %ld\n",
> +			 __func__, volt);
>  		return -ENODATA;
>  	}
>  
> +
>  	/* errminlimit is opp dependent and hence linked to voltage */
> -	sr->err_minlimit = volt_data->sr_errminlimit;
> +	sr->err_minlimit = nvalue_row->errminlimit;
>  
>  	pm_runtime_get_sync(&sr->pdev->dev);
>  
> @@ -625,7 +618,7 @@ int sr_enable(struct voltagedomain *voltdm, unsigned long volt)
>  	if (ret)
>  		return ret;
>  
> -	sr_write_reg(sr, NVALUERECIPROCAL, nvalue_reciprocal);
> +	sr_write_reg(sr, NVALUERECIPROCAL, nvalue_row->nvalue);
>  
>  	/* SRCONFIG - enable SR */
>  	sr_modify_reg(sr, SRCONFIG, SRCONFIG_SRENABLE, SRCONFIG_SRENABLE);
> @@ -873,7 +866,6 @@ static int __init omap_sr_probe(struct platform_device *pdev)
>  	struct omap_sr_data *pdata = pdev->dev.platform_data;
>  	struct resource *mem, *irq;
>  	struct dentry *nvalue_dir;
> -	struct omap_volt_data *volt_data;
>  	int i, ret = 0;
>  
>  	sr_info = kzalloc(sizeof(struct omap_sr), GFP_KERNEL);
> @@ -980,8 +972,6 @@ static int __init omap_sr_probe(struct platform_device *pdev)
>  			&sr_info->err_weight);
>  	(void) debugfs_create_x32("errmaxlimit", S_IRUGO, sr_info->dbg_dir,
>  			&sr_info->err_maxlimit);
> -	(void) debugfs_create_x32("errminlimit", S_IRUGO, sr_info->dbg_dir,
> -			&sr_info->err_minlimit);
>  
>  	nvalue_dir = debugfs_create_dir("nvalue", sr_info->dbg_dir);
>  	if (IS_ERR_OR_NULL(nvalue_dir)) {
> @@ -991,12 +981,9 @@ static int __init omap_sr_probe(struct platform_device *pdev)
>  		goto err_debugfs;
>  	}
>  
> -	omap_voltage_get_volttable(sr_info->voltdm, &volt_data);
> -	if (!volt_data) {
> -		dev_warn(&pdev->dev, "%s: %s: No Voltage table for the"
> -			" corresponding vdd. Cannot create debugfs"
> -			"entries for n-values\n",
> -			__func__, sr_info->name);
> +	if (sr_info->nvalue_count == 0 || !sr_info->nvalue_table) {
> +		dev_warn(&pdev->dev, "%s: %s: No Voltage table for the corresponding vdd. Cannot create debugfs entries for n-values\n",
> +			 __func__, sr_info->name);
>  		ret = -ENODATA;
>  		goto err_debugfs;
>  	}
> @@ -1004,10 +991,14 @@ static int __init omap_sr_probe(struct platform_device *pdev)
>  	for (i = 0; i < sr_info->nvalue_count; i++) {
>  		char name[NVALUE_NAME_LEN + 1];
>  
> -		snprintf(name, sizeof(name), "volt_%d",
> -			 volt_data[i].volt_nominal);
> +		snprintf(name, sizeof(name), "volt_%lu",
> +			 sr_info->nvalue_table[i].volt_nominal);
>  		(void) debugfs_create_x32(name, S_IRUGO | S_IWUSR, nvalue_dir,
>  				&(sr_info->nvalue_table[i].nvalue));
> +		snprintf(name, sizeof(name), "errminlimit_%lu",
> +			 sr_info->nvalue_table[i].volt_nominal);
> +		(void) debugfs_create_x32(name, S_IRUGO | S_IWUSR, nvalue_dir,
> +				&(sr_info->nvalue_table[i].errminlimit));
>  	}
>  
>  	return ret;
> diff --git a/arch/arm/mach-omap2/sr_device.c b/arch/arm/mach-omap2/sr_device.c
> index e081174..67d967e 100644
> --- a/arch/arm/mach-omap2/sr_device.c
> +++ b/arch/arm/mach-omap2/sr_device.c
> @@ -36,7 +36,10 @@ static void __init sr_set_nvalues(struct omap_volt_data *volt_data,
>  				struct omap_sr_data *sr_data)
>  {
>  	struct omap_sr_nvalue_table *nvalue_table;
> -	int i, count = 0;
> +	int i, j, count = 0;
> +
> +	sr_data->nvalue_count = 0;
> +	sr_data->nvalue_table = NULL;
>  
>  	while (volt_data[count].volt_nominal)
>  		count++;
> @@ -44,8 +47,14 @@ static void __init sr_set_nvalues(struct omap_volt_data *volt_data,
>  	nvalue_table = kzalloc(sizeof(struct omap_sr_nvalue_table)*count,
>  			GFP_KERNEL);
>  
> -	for (i = 0; i < count; i++) {
> +	if (!nvalue_table) {
> +		pr_err("OMAP: SmartReflex: cannot allocate memory for n-value table\n");
> +		return;
> +	}
> +
> +	for (i = 0, j = 0; i < count; i++) {
>  		u32 v;
> +
>  		/*
>  		 * In OMAP4 the efuse registers are 24 bit aligned.
>  		 * A __raw_readl will fail for non-32 bit aligned address
> @@ -58,15 +67,29 @@ static void __init sr_set_nvalues(struct omap_volt_data *volt_data,
>  				omap_ctrl_readb(offset + 1) << 8 |
>  				omap_ctrl_readb(offset + 2) << 16;
>  		} else {
> -			 v = omap_ctrl_readl(volt_data[i].sr_efuse_offs);
> +			v = omap_ctrl_readl(volt_data[i].sr_efuse_offs);
>  		}
>  
> -		nvalue_table[i].efuse_offs = volt_data[i].sr_efuse_offs;
> -		nvalue_table[i].nvalue = v;
> +		/*
> +		 * Many OMAP SoCs don't have the eFuse values set.
> +		 * For example, pretty much all OMAP3xxx before
> +		 * ES3.something.
> +		 *
> +		 * XXX There needs to be some way for board files or
> +		 * userspace to add these in.
> +		 */
> +		if (v == 0)
> +			continue;
> +
> +		nvalue_table[j].nvalue = v;
> +		nvalue_table[j].errminlimit = volt_data[i].sr_errminlimit;
> +		nvalue_table[j].volt_nominal = volt_data[i].volt_nominal;
> +
> +		j++;
>  	}
>  
>  	sr_data->nvalue_table = nvalue_table;
> -	sr_data->nvalue_count = count;
> +	sr_data->nvalue_count = j;
>  }
>  
>  static int __init sr_dev_init(struct omap_hwmod *oh, void *user)
> diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
> index e7dff08..0f7c81b 100644
> --- a/include/linux/power/smartreflex.h
> +++ b/include/linux/power/smartreflex.h
> @@ -48,12 +48,16 @@ struct omap_sr {
>  /**
>   * struct omap_sr_nvalue_table	- Smartreflex n-target value info
>   *
> - * @efuse_offs:	The offset of the efuse where n-target values are stored.
> - * @nvalue:	The n-target value.
> + * @efuse_offs:	  The offset of the efuse where n-target values are stored.
> + * @nvalue:	  The n-target value.
> + * @errminlimit:  The value of the ERRMINLIMIT bitfield for this n-target
> + * @volt_nominal: microvolts DC that the VDD is initially programmed to
>   */
>  struct omap_sr_nvalue_table {
>  	u32 efuse_offs;
>  	u32 nvalue;
> +	u32 errminlimit;
> +	unsigned long volt_nominal;
>  };
>  
>  /**

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH v2 0/9] PM: Create the AVS class of drivers
  2012-03-19 16:12 [PATCH v2 0/9] PM: Create the AVS class of drivers jean.pihet
                   ` (10 preceding siblings ...)
  2012-04-18  8:04 ` Jean Pihet
@ 2012-04-18 18:29 ` Kevin Hilman
  2012-04-18 18:30 ` Kevin Hilman
  12 siblings, 0 replies; 31+ messages in thread
From: Kevin Hilman @ 2012-04-18 18:29 UTC (permalink / raw)
  To: jean.pihet
  Cc: linux-omap, linux-arm-kernel, Rafael J. Wysocki, LKML, Jean Pihet

jean.pihet@newoldbits.com writes:

> From: Jean Pihet <j-pihet@ti.com>
>
> AVS is a power management technique which controls the operating

nit: you don't define AVS anywhere here, so those not familiar with the
technique will probably be lost in acronyms.  I suggest you add what it
means after the first use: e.g.  "AVS (Adaptive Voltage Scaling) is
a...."

Kevin

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH v2 0/9] PM: Create the AVS class of drivers
  2012-03-19 16:12 [PATCH v2 0/9] PM: Create the AVS class of drivers jean.pihet
                   ` (11 preceding siblings ...)
  2012-04-18 18:29 ` Kevin Hilman
@ 2012-04-18 18:30 ` Kevin Hilman
  2012-04-18 18:49   ` Rafael J. Wysocki
  12 siblings, 1 reply; 31+ messages in thread
From: Kevin Hilman @ 2012-04-18 18:30 UTC (permalink / raw)
  To: jean.pihet
  Cc: linux-omap, linux-arm-kernel, Rafael J. Wysocki, LKML, Jean Pihet

Rafael,

jean.pihet@newoldbits.com writes:

> From: Jean Pihet <j-pihet@ti.com>
>
> AVS is a power management technique which controls the operating
> voltage of a device in order to optimize (i.e. reduce) its power
> consumption. The voltage is adapted depending on static factors
> (chip manufacturing process) and dynamic factors (temperature
> depending performance).
> AVS is also called SmartReflex on OMAP devices.
>
> To that end, create the AVS framework in drivers/power/avs and
> move the OMAP SmartReflex code to the new directory.

I've done a review of this series and had a few very minor comments.

Once those are addressed, are you OK with us moving this AVS driver
under drivers/power?

Thanks,

Kevin


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH v2 0/9] PM: Create the AVS class of drivers
  2012-04-18 18:30 ` Kevin Hilman
@ 2012-04-18 18:49   ` Rafael J. Wysocki
  0 siblings, 0 replies; 31+ messages in thread
From: Rafael J. Wysocki @ 2012-04-18 18:49 UTC (permalink / raw)
  To: Kevin Hilman; +Cc: jean.pihet, linux-omap, linux-arm-kernel, LKML, Jean Pihet

On Wednesday, April 18, 2012, Kevin Hilman wrote:
> Rafael,
> 
> jean.pihet@newoldbits.com writes:
> 
> > From: Jean Pihet <j-pihet@ti.com>
> >
> > AVS is a power management technique which controls the operating
> > voltage of a device in order to optimize (i.e. reduce) its power
> > consumption. The voltage is adapted depending on static factors
> > (chip manufacturing process) and dynamic factors (temperature
> > depending performance).
> > AVS is also called SmartReflex on OMAP devices.
> >
> > To that end, create the AVS framework in drivers/power/avs and
> > move the OMAP SmartReflex code to the new directory.
> 
> I've done a review of this series and had a few very minor comments.
> 
> Once those are addressed, are you OK with us moving this AVS driver
> under drivers/power?

Yes, I am.

Thanks,
Rafael

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 1/9] ARM: OMAP3+: voltage: export functions to plat/voltage.h
  2012-04-18 17:27   ` Kevin Hilman
@ 2012-04-18 20:36     ` Jean Pihet
  0 siblings, 0 replies; 31+ messages in thread
From: Jean Pihet @ 2012-04-18 20:36 UTC (permalink / raw)
  To: Kevin Hilman, KEERTHY J
  Cc: linux-omap, linux-arm-kernel, Rafael J. Wysocki, LKML, Jean Pihet

Hi Kevin,

Adding Keerthy J

On Wed, Apr 18, 2012 at 7:27 PM, Kevin Hilman <khilman@ti.com> wrote:
> Hi Jean,
>
> jean.pihet@newoldbits.com writes:
>
>> From: Jean Pihet <j-pihet@ti.com>
>>
>> Move some functions from mach-omap2/ dir to the plat/ dir.
>> The SmartReflex class driver is a user of the basic voltage domains
>> functions (enable, disable, reset).
>>
>> Signed-off-by: Jean Pihet <j-pihet@ti.com>
>> Cc: Kevin Hilman <khilman@ti.com>
>
> Rather than expose the VP functions directly, how about adding a new API
> at the voltdm layer to start/stop AVS.  Maybe something like:
>
>  voltdm_avs_start(struct voltagedomain *voltdm)
>  voltdm_avs_stop(struct voltagedomain *voltdm)
>
> These will internally just call VP enable/disable for now, but we may
> have more to add to these in the future to support other SR classes.
Agree.
That would be a first step in the definition of the API between SR and
VP. Implementing other SR classes might require more than that, this
is still under investigation for now.

>
> Kevin
>

Thanks for reviewing,
Jean

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 5/9] ARM: OMAP3: hwmod: rename the smartreflex entries
  2012-04-18 17:33   ` Kevin Hilman
@ 2012-04-18 20:41     ` Jean Pihet
  0 siblings, 0 replies; 31+ messages in thread
From: Jean Pihet @ 2012-04-18 20:41 UTC (permalink / raw)
  To: Kevin Hilman
  Cc: linux-omap, linux-arm-kernel, Rafael J. Wysocki, LKML, Jean Pihet

Kevin,

On Wed, Apr 18, 2012 at 7:33 PM, Kevin Hilman <khilman@ti.com> wrote:
> +Benoit
>
> jean.pihet@newoldbits.com writes:
>
>> From: Jean Pihet <j-pihet@ti.com>
>>
>> Change the name field value to better reflect the smartreflex
>> integration in the system
>>
>> Signed-off-by: Jean Pihet <j-pihet@ti.com>
>> ---
>>  arch/arm/mach-omap2/omap_hwmod_3xxx_data.c |    8 ++++----
>>  arch/arm/mach-omap2/smartreflex.c          |    2 +-
>>  2 files changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
>> index d7d4c70..40f57c4 100644
>> --- a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
>> +++ b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
>> @@ -2751,7 +2751,7 @@ static struct omap_hwmod_ocp_if *omap34xx_sr1_slaves[] = {
>>  };
>>
>>  static struct omap_hwmod omap34xx_sr1_hwmod = {
>> -     .name           = "sr1",
>> +     .name           = "mpu_iva",
>
> Should this be "smartreflex_mpu_iva"?
>
> The OMAP4 SR hwmods have a 'smartreflex_' prefix which seems better.
>
>>       .class          = &omap34xx_smartreflex_hwmod_class,
>>       .main_clk       = "sr1_fck",
>>       .prcm           = {
>> @@ -2775,7 +2775,7 @@ static struct omap_hwmod_ocp_if *omap36xx_sr1_slaves[] = {
>>  };
>>
>>  static struct omap_hwmod omap36xx_sr1_hwmod = {
>> -     .name           = "sr1",
>> +     .name           = "mpu_iva",
>>       .class          = &omap36xx_smartreflex_hwmod_class,
>>       .main_clk       = "sr1_fck",
>>       .prcm           = {
>> @@ -2803,7 +2803,7 @@ static struct omap_hwmod_ocp_if *omap34xx_sr2_slaves[] = {
>>  };
>>
>>  static struct omap_hwmod omap34xx_sr2_hwmod = {
>> -     .name           = "sr2",
>> +     .name           = "core",
>>       .class          = &omap34xx_smartreflex_hwmod_class,
>>       .main_clk       = "sr2_fck",
>>       .prcm           = {
>> @@ -2827,7 +2827,7 @@ static struct omap_hwmod_ocp_if *omap36xx_sr2_slaves[] = {
>>  };
>>
>>  static struct omap_hwmod omap36xx_sr2_hwmod = {
>> -     .name           = "sr2",
>> +     .name           = "core",
>>       .class          = &omap36xx_smartreflex_hwmod_class,
>>       .main_clk       = "sr2_fck",
>>       .prcm           = {
>> diff --git a/arch/arm/mach-omap2/smartreflex.c b/arch/arm/mach-omap2/smartreflex.c
>> index c18d47d..b2728a5 100644
>> --- a/arch/arm/mach-omap2/smartreflex.c
>> +++ b/arch/arm/mach-omap2/smartreflex.c
>> @@ -184,7 +184,7 @@ static void sr_set_regfields(struct omap_sr *sr)
>>               sr->err_weight = OMAP3430_SR_ERRWEIGHT;
>>               sr->err_maxlimit = OMAP3430_SR_ERRMAXLIMIT;
>>               sr->accum_data = OMAP3430_SR_ACCUMDATA;
>> -             if (!(strcmp(sr->name, "sr1"))) {
>> +             if (!(strcmp(sr->name, "sr_mpu_iva"))) {
>
> Why the 'sr_' prefix?
Historically the sr instance name is generated from hwmod name
prepended with "sr_".
I agree it is better to change the hwmod name and remove the "sr_"
prefix from the sr init code.

>
>>                       sr->senn_avgweight = OMAP3430_SR1_SENNAVGWEIGHT;
>>                       sr->senp_avgweight = OMAP3430_SR1_SENPAVGWEIGHT;
>>               } else {
>
> Kevin

Thanks,
Jean

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 7/9] ARM: OMAP2+: SmartReflex: Use per-OPP data structure
  2012-04-18 18:21   ` Kevin Hilman
@ 2012-04-18 20:52     ` Jean Pihet
  0 siblings, 0 replies; 31+ messages in thread
From: Jean Pihet @ 2012-04-18 20:52 UTC (permalink / raw)
  To: Kevin Hilman
  Cc: linux-omap, linux-arm-kernel, Rafael J. Wysocki, LKML,
	Jean Pihet, Paul Walmsley, Thara Gopinath, Nishanth Menon

On Wed, Apr 18, 2012 at 8:21 PM, Kevin Hilman <khilman@ti.com> wrote:
> jean.pihet@newoldbits.com writes:
>
>> From: Jean Pihet <j-pihet@ti.com>
>>
>> The SmartReflex driver incorrectly treats some per-OPP data as data
>> common to all OPPs (e.g., ERRMINLIMIT).  Move this data into a per-OPP
>> data structure.
>
> OK
>
>> The SmartReflex driver should not be dependent on whether the host SoC
>> uses eFuses to store SmartReflex parameters or not.  (Even SoCs that
>> do store SR data in eFuses often need to override that data with
>> software-defined values.)  So, convert sr_retrieve_nvalue() to look up
>> per-OPP data by the OPP's nominal voltage, rather than by the eFuse
>> offset.
>
> Right.
>
>> While at it:
>>  . tidy up the code wrt default values in the data tables,
>>  . remove the global errminlimit debugfs entry and create per-voltage
>>    entries from the data tables.
>
> OK
>
>> Furthermore, in order to make the SmartReflex implementation ready for
>> the move to drivers/, remove the dependency from the SR driver code
>> to the voltage layer by querying the data tables only from the SR device
>> init code.
>
> So that's 4 relatively independent things going on in this patch which
> makes it somewhat difficult to review and understand.
>
> I'd suggest breaking it up into smaller parts if possible.  If not, fix
> up the changelog to describe why all of these need to go together, and
> why it's necessary to do them before the move.
Those changes are not independent from each other.
However for improved readability the patch can be split up (e.g.
efuse->opp, debugfs ...) and the changelog updated accordingly.

>
> Thanks,
>
> Kevin
>

Thanks,
Jean

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH v2 0/9] PM: Create the AVS class of drivers
  2012-04-18  8:04 ` Jean Pihet
@ 2012-04-19  0:08   ` Greg KH
  0 siblings, 0 replies; 31+ messages in thread
From: Greg KH @ 2012-04-19  0:08 UTC (permalink / raw)
  To: Jean Pihet
  Cc: akpm, linux-omap, linux-arm-kernel, Kevin Hilman,
	Rafael J. Wysocki, LKML, Tony Lindgren, KEERTHY J, Jean Pihet

On Wed, Apr 18, 2012 at 10:04:22AM +0200, Jean Pihet wrote:
> Hi Andrew, Greg,
> 
> Can you please look at this patch set?
> The idea is to create a framework and drivers for the AVS class of
> devices. This patch set implements the first step by moving the
> existing code to drivers/power/avs. Next steps will be to implement
> class support and notifications, add more classes of operations for
> OMAP chips, etc.
> 
> Keerthy J is taking over the ownership of this code and will continue
> the development further.
> 
> What do you think?

I think Kevin and Rafael's comments need to be addressed.

greg k-h

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 2/9] ARM: OMAP2+: SmartReflex: move the driver specific macros in include/linux/power
  2012-04-05  9:35           ` Trilok Soni
@ 2012-04-19 13:54             ` Arnd Bergmann
  2012-04-19 16:02               ` Jean Pihet
  2012-04-19 17:06               ` Kevin Hilman
  0 siblings, 2 replies; 31+ messages in thread
From: Arnd Bergmann @ 2012-04-19 13:54 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Trilok Soni, Jean Pihet, Kevin Hilman, Cousson, Benoit, gregkh,
	LKML, Rafael J. Wysocki, linux-omap, Jean Pihet

On Thursday 05 April 2012, Trilok Soni wrote:
> >> Couple of suggestions:
> >>
> >> drivers/platform/omap/avs?
> >> drivers/misc/omap/avs?
> >>

I would definitely prefer something under drivers/power,
drivers/regulators or a new top-level directory under
drivers.

> >>> IIRC, David Brownell was referring to the rule of three for such case.
> >>> Meaning that it worth having a generic fmwk when at least three
> >>> different drivers are doing the same kind of things.
> >
> > Do OMAP v1 and OMAP v2 implementations count as 2 drivers? ;-)
> > More seriously, the OMAP code for SmartReflex is far from complete in
> > mainline. There is a plan to provide the following features:
> > - OMAP v1 IP,
> > - OMAP v2 IP,
> > - class 1.5,
> > - class 3,
> > - class 3.5,
> > - and more support for the upcoming chipsets.
> 
> I don't understand much of these versions right now, but hopefully after 
> going through all these docs. My only contention point is to not create 
> any directory into the drivers/power, unless it is generic fwk and then 
> build up "client" drivers on top of it. Meanwhile we could move this 
> driver into above options as I have suggested.

I think creating the directory in the place where we want the files
to stay in the long run is ok, if the plan is to add more drivers and
make the base code more generic. We don't have to wait until it's too
late and we absolutely need a framework ;-)

The part I don't understand is how this relates to the regulator framework.
Is there any overlap between the functionality provided by the
smartreflex framework and the regulator framework? If so, would it be
better to extend the existing framework so it can do smartreflex as well?

	Arnd

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 2/9] ARM: OMAP2+: SmartReflex: move the driver specific macros in include/linux/power
  2012-04-19 13:54             ` Arnd Bergmann
@ 2012-04-19 16:02               ` Jean Pihet
  2012-04-19 17:06               ` Kevin Hilman
  1 sibling, 0 replies; 31+ messages in thread
From: Jean Pihet @ 2012-04-19 16:02 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: linux-arm-kernel, Trilok Soni, Kevin Hilman, Cousson, Benoit,
	gregkh, LKML, Rafael J. Wysocki, linux-omap, Jean Pihet

Hi Arnd,

On Thu, Apr 19, 2012 at 3:54 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> On Thursday 05 April 2012, Trilok Soni wrote:
>> >> Couple of suggestions:
>> >>
>> >> drivers/platform/omap/avs?
>> >> drivers/misc/omap/avs?
>> >>
>
> I would definitely prefer something under drivers/power,
> drivers/regulators or a new top-level directory under
> drivers.
Can I take this as an OK for drivers/power/avs as suggested?

>
>> >>> IIRC, David Brownell was referring to the rule of three for such case.
>> >>> Meaning that it worth having a generic fmwk when at least three
>> >>> different drivers are doing the same kind of things.
>> >
>> > Do OMAP v1 and OMAP v2 implementations count as 2 drivers? ;-)
>> > More seriously, the OMAP code for SmartReflex is far from complete in
>> > mainline. There is a plan to provide the following features:
>> > - OMAP v1 IP,
>> > - OMAP v2 IP,
>> > - class 1.5,
>> > - class 3,
>> > - class 3.5,
>> > - and more support for the upcoming chipsets.
>>
>> I don't understand much of these versions right now, but hopefully after
>> going through all these docs. My only contention point is to not create
>> any directory into the drivers/power, unless it is generic fwk and then
>> build up "client" drivers on top of it. Meanwhile we could move this
>> driver into above options as I have suggested.
>
> I think creating the directory in the place where we want the files
> to stay in the long run is ok, if the plan is to add more drivers and
> make the base code more generic. We don't have to wait until it's too
> late and we absolutely need a framework ;-)
Agree! That is the intention to provide a fwk.

> The part I don't understand is how this relates to the regulator framework.
> Is there any overlap between the functionality provided by the
> smartreflex framework and the regulator framework? If so, would it be
> better to extend the existing framework so it can do smartreflex as well?
The link with regulator has indeed an impact on the target dir, this
is still unknown and discussed internally.

>
>        Arnd

Thanks,
Jean

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 2/9] ARM: OMAP2+: SmartReflex: move the driver specific macros in include/linux/power
  2012-04-19 13:54             ` Arnd Bergmann
  2012-04-19 16:02               ` Jean Pihet
@ 2012-04-19 17:06               ` Kevin Hilman
  1 sibling, 0 replies; 31+ messages in thread
From: Kevin Hilman @ 2012-04-19 17:06 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: linux-arm-kernel, Trilok Soni, Jean Pihet, Cousson, Benoit,
	gregkh, LKML, Rafael J. Wysocki, linux-omap, Jean Pihet

Arnd Bergmann <arnd@arndb.de> writes:

> On Thursday 05 April 2012, Trilok Soni wrote:
>> >> Couple of suggestions:
>> >>
>> >> drivers/platform/omap/avs?
>> >> drivers/misc/omap/avs?
>> >>
>
> I would definitely prefer something under drivers/power,
> drivers/regulators or a new top-level directory under
> drivers.
>
>> >>> IIRC, David Brownell was referring to the rule of three for such case.
>> >>> Meaning that it worth having a generic fmwk when at least three
>> >>> different drivers are doing the same kind of things.
>> >
>> > Do OMAP v1 and OMAP v2 implementations count as 2 drivers? ;-)
>> > More seriously, the OMAP code for SmartReflex is far from complete in
>> > mainline. There is a plan to provide the following features:
>> > - OMAP v1 IP,
>> > - OMAP v2 IP,
>> > - class 1.5,
>> > - class 3,
>> > - class 3.5,
>> > - and more support for the upcoming chipsets.
>> 
>> I don't understand much of these versions right now, but hopefully after 
>> going through all these docs. My only contention point is to not create 
>> any directory into the drivers/power, unless it is generic fwk and then 
>> build up "client" drivers on top of it. Meanwhile we could move this 
>> driver into above options as I have suggested.
>
> I think creating the directory in the place where we want the files
> to stay in the long run is ok, if the plan is to add more drivers and
> make the base code more generic. We don't have to wait until it's too
> late and we absolutely need a framework ;-)

Completely agree, thanks.

> The part I don't understand is how this relates to the regulator framework.
> Is there any overlap between the functionality provided by the
> smartreflex framework and the regulator framework? If so, would it be
> better to extend the existing framework so it can do smartreflex as well?

IMO, there isn't any overlap with the regulator framework, and AVS
drivers/devices should be separate from the regulator framework.

Think of AVS/SmartReflex as a way for hardware to do automatic
micro-adjustments to the regulator.  The regulator voltage (a.k.a
nominal voltage) will stay same from the perspective of the regulator
and regulator framework, but AVS allows the hardware to do micro voltage
adjustments around the nominal voltage.

We recently extended the regulator framework to have allow get/set
voltage hooks which can query platform-specific voltage frameworks which
do hardware voltage control (which in turn can control AVS
sensors/devices.)

Kevin

^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2012-04-19 17:06 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-19 16:12 [PATCH v2 0/9] PM: Create the AVS class of drivers jean.pihet
2012-03-19 16:12 ` [PATCH 1/9] ARM: OMAP3+: voltage: export functions to plat/voltage.h jean.pihet
2012-04-18 17:27   ` Kevin Hilman
2012-04-18 20:36     ` Jean Pihet
2012-03-19 16:12 ` [PATCH 2/9] ARM: OMAP2+: SmartReflex: move the driver specific macros in include/linux/power jean.pihet
2012-04-04 19:10   ` Trilok Soni
2012-04-04 19:41     ` Cousson, Benoit
2012-04-05  6:53       ` Trilok Soni
2012-04-05  8:59         ` Jean Pihet
2012-04-05  9:35           ` Trilok Soni
2012-04-19 13:54             ` Arnd Bergmann
2012-04-19 16:02               ` Jean Pihet
2012-04-19 17:06               ` Kevin Hilman
2012-03-19 16:12 ` [PATCH 3/9] ARM: OMAP3+: SmartReflex: class drivers should use struct omap_sr * jean.pihet
2012-03-19 16:12 ` [PATCH 4/9] ARM: OMAP2+: smartreflex: Use the names from hwmod data instead of voltage domains jean.pihet
2012-03-19 16:12 ` [PATCH 5/9] ARM: OMAP3: hwmod: rename the smartreflex entries jean.pihet
2012-04-18 17:33   ` Kevin Hilman
2012-04-18 20:41     ` Jean Pihet
2012-03-19 16:12 ` [PATCH 6/9] ARM: OMAP2+: SmartReflex: introduce a busy loop condition test macro jean.pihet
2012-03-19 16:12 ` [PATCH 7/9] ARM: OMAP2+: SmartReflex: Use per-OPP data structure jean.pihet
2012-04-18 18:21   ` Kevin Hilman
2012-04-18 20:52     ` Jean Pihet
2012-03-19 16:12 ` [PATCH 8/9] ARM: OMAP2+: SmartReflex: add POWER_AVS Kconfig options jean.pihet
2012-03-19 16:12 ` [PATCH 9/9] ARM: OMAP: SmartReflex: Move smartreflex driver to drivers/ jean.pihet
2012-04-18 18:17   ` Kevin Hilman
2012-04-03 11:14 ` [PATCH v2 0/9] PM: Create the AVS class of drivers Jean Pihet
2012-04-18  8:04 ` Jean Pihet
2012-04-19  0:08   ` Greg KH
2012-04-18 18:29 ` Kevin Hilman
2012-04-18 18:30 ` Kevin Hilman
2012-04-18 18:49   ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).