Skip to contentSkip to conversation

Support CPR on MSM8916

PATCH Superseded Stephen Boyd 4 participants 16 messages Jun 2, 2015 – Jun 3, 2015

Subsystems (8)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Support CPR on MSM8916

This patch series adds support for CPR on MSM8916. It depends on a few different patch series to be fully functional. It needs SPMI regulator support[1] and secondly it needs the NVMEM framework[2]. It also needs a patch that provides a "corner" voting mechanism to the SMD RPM regulators (and it relies on the SMD RPM regulators to function properly). If possible I would like to get rid of that patch entirely. Finally it needs CPU clock support to support scaling CPU frequencies. Once you have those 4 or 5 patch series in place you can apply these patches and enable cpufreq-dt and add the cpufreq-dt device (maybe the CPR driver should add the cpufreq-dt device?) and you'll see interrupts for CPR and OPP voltage adjustments triggering CPUfreq to modify voltages.

Stephen Boyd (6):
regulator: core: Don't spew backtraces on duplicate sysfs
regulator: core: Print at debug level on debugfs creation failure PM / OPP: Support adjusting OPP voltages at runtime
OPP: Allow notifiers to call dev_pm_opp_get_{voltage,freq} RCU-free
cpufreq-dt: Handle OPP voltage adjust events
power: avs: Add support for CPR (Core Power Reduction)

 drivers/base/power/opp.c     |   96 +-
 drivers/cpufreq/cpufreq-dt.c |   73 +-
 drivers/power/avs/Kconfig    |   14 +
 drivers/power/avs/Makefile   |    1 +
 drivers/power/avs/qcom-cpr.c | 1983 ++++++++++++++++++++++++++++++++++++++++++
 drivers/regulator/core.c     |    6 +-
 include/linux/pm_opp.h       |   10 +
 7 files changed, 2166 insertions(+), 17 deletions(-)
 create mode 100644 drivers/power/avs/qcom-cpr.c

[1] http://lkml.kernel.org/r/1431466787-32247-1-git-send-email-sboyd at codeaurora.org
[2] http://lkml.kernel.org/r/1432226535-8640-1-git-send-email-srinivas.kandagatla at linaro.org

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw

PATCH 1/6 regulator: core: Don't spew backtraces on duplicate sysfs

We don't consider a failure to add the sysfs node as a problem, so use sysfs_create_link_nowarn() so that we don't print a backtrace when duplicated files exist. Also, downgrade the printk message to a debug statement so that we're quiet here. This allows multiple drivers to request a CPU's regulator so that CPUfreq and AVSish drivers can coexist.

---
 drivers/regulator/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/core.c +2 -2
index 443eaab933fc..f6989485c382 100644
@@ -1192,10 +1192,10 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
 		if (regulator->supply_name == NULL)
 			goto overflow_err;
 
-		err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj,
+		err = sysfs_create_link_nowarn(&rdev->dev.kobj, &dev->kobj,
 					buf);
 		if (err) {
-			rdev_warn(rdev, "could not add device link %s err %d\n",
+			rdev_dbg(rdev, "could not add device link %s err %d\n",
 				  dev->kobj.name, err);
 			/* non-fatal */
 		}
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer
#2 lore raw

Re: [PATCH 1/6] regulator: core: Don't spew backtraces on duplicate sysfs

Quoted 2 lines · Stephen Boyd

We don't consider a failure to add the sysfs node as a problem, so use sysfs_create_link_nowarn() so that we don't print a

Applied, thanks.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150603/4eaccb5d/attachment.sig>

#3 lore raw

PATCH 2/6 regulator: core: Print at debug level on debugfs creation failure

In reply to Stephen Boyd

Failure to create a debugfs node is not an error, but we print a warning upon failure to create the node. Downgrade this to a debug printk so that we're quiet here. This allows multiple drivers to request a CPU's regulator so that CPUfreq and AVSish drivers can coexist.

The downside of this approach is that whoever gets to debugfs first the others who come later to not have any debugfs attributes associated with them.

---
 drivers/regulator/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/regulator/core.c +1 -1
index f6989485c382..9dba0a3d4526 100644
@@ -1208,7 +1208,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
 	regulator->debugfs = debugfs_create_dir(regulator->supply_name,
 						rdev->debugfs);
 	if (!regulator->debugfs) {
-		rdev_warn(rdev, "Failed to create debugfs directory\n");
+		rdev_dbg(rdev, "Failed to create debugfs directory\n");
 	} else {
 		debugfs_create_u32("uA_load", 0444, regulator->debugfs,
 				   &regulator->uA_load);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer
#4 lore raw

Re: [PATCH 2/6] regulator: core: Print at debug level on debugfs creation failure

Quoted 3 lines · Stephen Boyd

The downside of this approach is that whoever gets to debugfs first the others who come later to not have any debugfs attributes associated with them.

Right, and we do it silently which I'm really not sure about (either
way). Let me think...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150603/0948b86e/attachment.sig>

#5 lore raw

PATCH 3/6 PM / OPP: Support adjusting OPP voltages at runtime

In reply to Stephen Boyd

On some SoCs the Adaptive Voltage Scaling (AVS) technique is employed to optimize the operating voltage of a device. At a given frequency, the hardware monitors dynamic factors and either makes a suggestion for how much to adjust a voltage for the current frequency, or it automatically adjusts the voltage without software intervention. Add an API to the OPP library for the former case, so that AVS type devices can update the voltages for an OPP when the hardware determines the voltage should change. The assumption is that drivers like CPUfreq or devfreq will register for the OPP notifiers and adjust the voltage according to suggestions that AVS makes.

Cc Nishanth Menon <[email protected]>
Cc Viresh Kumar <[email protected]>

---

This should probably be cleanded up to share code with the enable/disable APIs.

 drivers/base/power/opp.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pm_opp.h   | 10 +++++++
 2 files changed, 87 insertions(+)
drivers/base/power/opp.c +77 -0
index 677fb2843553..b997a7eabcd4 100644
@@ -748,6 +748,83 @@ unlock:
 }
 
 /**
+ * dev_pm_opp_adjust_voltage() - helper to change the voltage of an opp
+ * @dev:		device for which we do this operation
+ * @freq:		OPP frequency to adjust voltage of
+ * @u_volt:		new OPP voltage
+ *
+ * Change the voltage of an OPP with an RCU operation.
+ *
+ * Return: -EINVAL for bad pointers, -ENOMEM if no memory available for the
+ * copy operation, returns 0 if no modifcation was done OR modification was
+ * successful.
+ *
+ * Locking: The internal device_opp and opp structures are RCU protected.
+ * Hence this function internally uses RCU updater strategy with mutex locks to
+ * keep the integrity of the internal data structures. Callers should ensure
+ * that this function is *NOT* called under RCU protection or in contexts where
+ * mutex locking or synchronize_rcu() blocking calls cannot be used.
+ */
+int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
+				 unsigned long u_volt)
+{
+	struct device_opp *dev_opp;
+	struct dev_pm_opp *new_opp, *tmp_opp, *opp = ERR_PTR(-ENODEV);
+	int r = 0;
+
+	/* keep the node allocated */
+	new_opp = kmalloc(sizeof(*new_opp), GFP_KERNEL);
+	if (!new_opp)
+		return -ENOMEM;
+
+	mutex_lock(&dev_opp_list_lock);
+
+	/* Find the device_opp */
+	dev_opp = _find_device_opp(dev);
+	if (IS_ERR(dev_opp)) {
+		r = PTR_ERR(dev_opp);
+		dev_warn(dev, "%s: Device OPP not found (%d)\n", __func__, r);
+		goto unlock;
+	}
+
+	/* Do we have the frequency? */
+	list_for_each_entry(tmp_opp, &dev_opp->opp_list, node) {
+		if (tmp_opp->rate == freq) {
+			opp = tmp_opp;
+			break;
+		}
+	}
+	if (IS_ERR(opp)) {
+		r = PTR_ERR(opp);
+		goto unlock;
+	}
+
+	/* Is update really needed? */
+	if (opp->u_volt == u_volt)
+		goto unlock;
+	/* copy the old data over */
+	*new_opp = *opp;
+
+	/* plug in new node */
+	new_opp->u_volt = u_volt;
+
+	list_replace_rcu(&opp->node, &new_opp->node);
+	mutex_unlock(&dev_opp_list_lock);
+	call_srcu(&dev_opp->srcu_head.srcu, &opp->rcu_head, _kfree_opp_rcu);
+
+	/* Notify the change of the OPP */
+	srcu_notifier_call_chain(&dev_opp->srcu_head, OPP_EVENT_ADJUST_VOLTAGE,
+				 new_opp);
+
+	return 0;
+
+unlock:
+	mutex_unlock(&dev_opp_list_lock);
+	kfree(new_opp);
+	return r;
+}
+
+/**
  * dev_pm_opp_enable() - Enable a specific OPP
  * @dev:	device for which we do this operation
  * @freq:	OPP frequency to enable
include/linux/pm_opp.h +10 -0
index cec2d4540914..80f2c41e7daa 100644
@@ -22,6 +22,7 @@ struct device;
 
 enum dev_pm_opp_event {
 	OPP_EVENT_ADD, OPP_EVENT_REMOVE, OPP_EVENT_ENABLE, OPP_EVENT_DISABLE,
+	OPP_EVENT_ADJUST_VOLTAGE,
 };
 
 #if defined(CONFIG_PM_OPP)
@@ -46,6 +47,9 @@ int dev_pm_opp_add(struct device *dev, unsigned long freq,
 		   unsigned long u_volt);
 void dev_pm_opp_remove(struct device *dev, unsigned long freq);
 
+int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
+		   unsigned long u_volt);
+
 int dev_pm_opp_enable(struct device *dev, unsigned long freq);
 
 int dev_pm_opp_disable(struct device *dev, unsigned long freq);
@@ -95,6 +99,12 @@ static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
 {
 }
 
+static inline int dev_pm_opp_adjust_voltage(struct device *dev,
+		unsigned long freq, unsigned long u_volt)
+{
+	return 0;
+}
+
 static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
 {
 	return 0;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer Acked-by on v1 3/6
#6 lore raw

Re: [PATCH 3/6] PM / OPP: Support adjusting OPP voltages at runtime

include/linux/pm_opp.h int dev_pm_opp_add(struct device *dev, unsigned long freq,

Quoted 5 lines · Stephen Boyd
include/linux/pm_opp.h +4 -0
+int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
+		   unsigned long u_volt);
 
+static inline int dev_pm_opp_adjust_voltage(struct device *dev,
+		unsigned long freq, unsigned long u_volt)

The 'u' of 'unsigned' isn't aligned to the opening curly brace. Try running with checkpatch --strict and you will see some warnings.

Otherwise,

Signature · 1 line
viresh
#7 lore raw

Re: [PATCH 3/6] PM / OPP: Support adjusting OPP voltages at runtime

Quoted 10 lines · Viresh Kumar

include/linux/pm_opp.h int dev_pm_opp_add(struct device *dev, unsigned long freq,

Quoted 5 lines · Stephen Boyd
include/linux/pm_opp.h +4 -0
+int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
+		   unsigned long u_volt);
 
+static inline int dev_pm_opp_adjust_voltage(struct device *dev,
+		unsigned long freq, unsigned long u_volt)

The 'u' of 'unsigned' isn't aligned to the opening curly brace. Try running with checkpatch --strict and you will see some warnings.

Quoted 4 lines

Otherwise,

Will do. Thanks.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#8 lore raw

PATCH 4/6 OPP: Allow notifiers to call dev_pm_opp_get_{voltage,freq} RCU-free

In reply to Stephen Boyd

We pass the dev_pm_opp structure to OPP notifiers but the users of the notifier need to surround calls to dev_pm_opp_get_*() with RCU read locks to avoid lockdep warnings. The notifier is already called with the dev_opp's srcu lock held, so it should be safe to assume the devm_pm_opp structure is already protected inside the notifier. Update the lockdep check for this.

Cc Krzysztof Kozlowski <[email protected]>

---

This is probably wrong, but it's what I had to hack up to be able to use the OPP functions from within the notifier to figure out the new values of the OPP without having to take an RCU read lock.

 drivers/base/power/opp.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
drivers/base/power/opp.c +11 -8
index b997a7eabcd4..6d75022c6a0e 100644
@@ -108,9 +108,10 @@ static LIST_HEAD(dev_opp_list);
 /* Lock to allow exclusive modification to the device and opp lists */
 static DEFINE_MUTEX(dev_opp_list_lock);
 
-#define opp_rcu_lockdep_assert()					\
+#define opp_rcu_lockdep_assert(s)					\
 do {									\
 	rcu_lockdep_assert(rcu_read_lock_held() ||			\
+				(s && srcu_read_lock_held(s)) || 	\
 				lockdep_is_held(&dev_opp_list_lock),	\
 			   "Missing rcu_read_lock() or "		\
 			   "dev_opp_list_lock protection");		\
@@ -169,9 +170,10 @@ unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
 	struct dev_pm_opp *tmp_opp;
 	unsigned long v = 0;
 
-	opp_rcu_lockdep_assert();
+	opp_rcu_lockdep_assert(&opp->dev_opp->srcu_head.srcu);
 
-	tmp_opp = rcu_dereference(opp);
+	tmp_opp = srcu_dereference_check(opp, &opp->dev_opp->srcu_head.srcu,
+					 rcu_read_lock_held());
 	if (unlikely(IS_ERR_OR_NULL(tmp_opp)) || !tmp_opp->available)
 		pr_err("%s: Invalid parameters\n", __func__);
 	else
@@ -201,9 +203,10 @@ unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
 	struct dev_pm_opp *tmp_opp;
 	unsigned long f = 0;
 
-	opp_rcu_lockdep_assert();
+	opp_rcu_lockdep_assert(&opp->dev_opp->srcu_head.srcu);
 
-	tmp_opp = rcu_dereference(opp);
+	tmp_opp = srcu_dereference_check(opp, &opp->dev_opp->srcu_head.srcu,
+					 rcu_read_lock_held());
 	if (unlikely(IS_ERR_OR_NULL(tmp_opp)) || !tmp_opp->available)
 		pr_err("%s: Invalid parameters\n", __func__);
 	else
@@ -282,7 +285,7 @@ struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
 	struct device_opp *dev_opp;
 	struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
 
-	opp_rcu_lockdep_assert();
+	opp_rcu_lockdep_assert(NULL);
 
 	dev_opp = _find_device_opp(dev);
 	if (IS_ERR(dev_opp)) {
@@ -330,7 +333,7 @@ struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
 	struct device_opp *dev_opp;
 	struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
 
-	opp_rcu_lockdep_assert();
+	opp_rcu_lockdep_assert(NULL);
 
 	if (!dev || !freq) {
 		dev_err(dev, "%s: Invalid argument freq=%p\n", __func__, freq);
@@ -380,7 +383,7 @@ struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
 	struct device_opp *dev_opp;
 	struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
 
-	opp_rcu_lockdep_assert();
+	opp_rcu_lockdep_assert(NULL);
 
 	if (!dev || !freq) {
 		dev_err(dev, "%s: Invalid argument freq=%p\n", __func__, freq);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#9 lore raw

Re: [RFC/PATCH 4/6] OPP: Allow notifiers to call dev_pm_opp_get_{voltage,freq} RCU-free

Quoted 36 lines · Stephen Boyd

We pass the dev_pm_opp structure to OPP notifiers but the users of the notifier need to surround calls to dev_pm_opp_get_*() with RCU read locks to avoid lockdep warnings. The notifier is already called with the dev_opp's srcu lock held, so it should be safe to assume the devm_pm_opp structure is already protected inside the notifier. Update the lockdep check for this.

Cc Krzysztof Kozlowski <[email protected]>

---

This is probably wrong, but it's what I had to hack up to be able to use the OPP functions from within the notifier to figure out the new values of the OPP without having to take an RCU read lock.

 drivers/base/power/opp.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
drivers/base/power/opp.c +2 -1
index b997a7eabcd4..6d75022c6a0e 100644
@@ -108,9 +108,10 @@ static LIST_HEAD(dev_opp_list);
 /* Lock to allow exclusive modification to the device and opp lists */
 static DEFINE_MUTEX(dev_opp_list_lock);
 
-#define opp_rcu_lockdep_assert()					\
+#define opp_rcu_lockdep_assert(s)					\
 do {									\
 	rcu_lockdep_assert(rcu_read_lock_held() ||			\
+				(s && srcu_read_lock_held(s)) || 	\
 				lockdep_is_held(&dev_opp_list_lock),	\
 			   "Missing rcu_read_lock() or "		\
 			   "dev_opp_list_lock protection");		\

drivers/base/power/opp.c unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp) · line 176

Quoted 9 lines
drivers/base/power/opp.c +3 -2
@@ -169,9 +170,10 @@ unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
 	struct dev_pm_opp *tmp_opp;
 	unsigned long v = 0;
 
-	opp_rcu_lockdep_assert();
+	opp_rcu_lockdep_assert(&opp->dev_opp->srcu_head.srcu);
 
-	tmp_opp = rcu_dereference(opp);
+	tmp_opp = srcu_dereference_check(opp, &opp->dev_opp->srcu_head.srcu,
+					 rcu_read_lock_held());

It looks strange. The notifier's SRCU is part of device_opp but here we want to protect the dev_pm_opp.

Because of this difference I am not sure that it is safe having around this a srcu_read_lock() from notifiers instead of rcu_read_lock().

Best regards,
Krzysztof

#10 lore raw

Re: [RFC/PATCH 4/6] OPP: Allow notifiers to call dev_pm_opp_get_{voltage,freq} RCU-free

Quoted 43 lines · Krzysztof Kozlowski
Quoted 42 lines · Stephen Boyd

We pass the dev_pm_opp structure to OPP notifiers but the users of the notifier need to surround calls to dev_pm_opp_get_*() with RCU read locks to avoid lockdep warnings. The notifier is already called with the dev_opp's srcu lock held, so it should be safe to assume the devm_pm_opp structure is already protected inside the notifier. Update the lockdep check for this.

Cc Krzysztof Kozlowski <[email protected]>

---

This is probably wrong, but it's what I had to hack up to be able to use the OPP functions from within the notifier to figure out the new values of the OPP without having to take an RCU read lock.

  drivers/base/power/opp.c | 19 +++++++++++--------
  1 file changed, 11 insertions(+), 8 deletions(-)
drivers/base/power/opp.c +3 -2
index b997a7eabcd4..6d75022c6a0e 100644
@@ -108,9 +108,10 @@ static LIST_HEAD(dev_opp_list);
  /* Lock to allow exclusive modification to the device and opp lists */
  static DEFINE_MUTEX(dev_opp_list_lock);
 
-#define opp_rcu_lockdep_assert()					\
+#define opp_rcu_lockdep_assert(s)					\
  do {									\
  	rcu_lockdep_assert(rcu_read_lock_held() ||			\
+				(s && srcu_read_lock_held(s)) || 	\
  				lockdep_is_held(&dev_opp_list_lock),	\
  			   "Missing rcu_read_lock() or "		\
  			   "dev_opp_list_lock protection");		\
@@ -169,9 +170,10 @@ unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
  	struct dev_pm_opp *tmp_opp;
  	unsigned long v = 0;
 
-	opp_rcu_lockdep_assert();
+	opp_rcu_lockdep_assert(&opp->dev_opp->srcu_head.srcu);
 
Quoted 10 lines

drivers/base/power/opp.c unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp) · line 176

Quoted 3 lines
drivers/base/power/opp.c +2 -1
-	tmp_opp = rcu_dereference(opp);
+	tmp_opp = srcu_dereference_check(opp, &opp->dev_opp->srcu_head.srcu,
+					 rcu_read_lock_held());

It looks strange. The notifier's SRCU is part of device_opp but here we want to protect the dev_pm_opp.

Because of this difference I am not sure that it is safe having around this a srcu_read_lock() from notifiers instead of rcu_read_lock().

Yeah I'm not sure, and I'll have to spend more time to figure out what's going on, hence the RFC. Does it make sense to allow the notifiers to call these functions without rcu_read_lock() though? It certainly looks strange to call rcu_read_lock() with a pointer that is handed to the notifier.

It also seems that rcu_dereference() will take care of calling rcu_read_lock_held() for us so having an opp_rcu_lockdep_assert() here is redundant.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#11 lore raw

PATCH 5/6 cpufreq-dt: Handle OPP voltage adjust events

In reply to Stephen Boyd

On some SoCs the Adaptive Voltage Scaling (AVS) technique is employed to optimize the operating voltage of a device. At a given frequency, the hardware monitors dynamic factors and either makes a suggestion for how much to adjust a voltage for the current frequency, or it automatically adjusts the voltage without software intervention.

In the former case, an AVS driver will call dev_pm_opp_modify_voltage() and update the voltage for the particular OPP the CPUs are using. Add an OPP notifier to cpufreq-dt so that we can adjust the voltage of the CPU when AVS updates the OPP.

---
 drivers/cpufreq/cpufreq-dt.c | 73 ++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 67 insertions(+), 6 deletions(-)
drivers/cpufreq/cpufreq-dt.c +67 -6
index bab67db54b7e..616218f133be 100644
@@ -34,8 +34,48 @@ struct private_data {
 	struct regulator *cpu_reg;
 	struct thermal_cooling_device *cdev;
 	unsigned int voltage_tolerance; /* in percentage */
+	struct notifier_block opp_nb;
+	struct mutex lock;
+	unsigned long opp_freq;
 };
 
+
+static int opp_notifier(struct notifier_block *nb, unsigned long event,
+			void *data)
+{
+	struct dev_pm_opp *opp = data;
+	struct private_data *priv = container_of(nb, struct private_data,
+						 opp_nb);
+	struct device *cpu_dev = priv->cpu_dev;
+	struct regulator *cpu_reg = priv->cpu_reg;
+	unsigned long volt, tol, freq;
+	int ret = 0;
+
+	switch (event) {
+		case OPP_EVENT_ADJUST_VOLTAGE:
+			volt = dev_pm_opp_get_voltage(opp);
+			freq = dev_pm_opp_get_freq(opp);
+			tol = volt * priv->voltage_tolerance / 100;
+
+			mutex_lock(&priv->lock);
+			if (freq == priv->opp_freq)
+				ret = regulator_set_voltage_tol(cpu_reg, volt,
+								tol);
+			mutex_unlock(&priv->lock);
+			if (ret) {
+				dev_err(cpu_dev,
+					"failed to scale voltage up: %d\n",
+					ret);
+				return ret;
+			}
+			break;
+		default:
+			break;
+	}
+
+	return 0;
+}
+
 static int set_target(struct cpufreq_policy *policy, unsigned int index)
 {
 	struct dev_pm_opp *opp;
@@ -47,6 +87,7 @@ static int set_target(struct cpufreq_policy *policy, unsigned int index)
 	unsigned long volt = 0, volt_old = 0, tol = 0;
 	unsigned int old_freq, new_freq;
 	long freq_Hz, freq_exact;
+	unsigned long opp_freq = 0;
 	int ret;
 
 	freq_Hz = clk_round_rate(cpu_clk, freq_table[index].frequency * 1000);
@@ -57,8 +98,8 @@ static int set_target(struct cpufreq_policy *policy, unsigned int index)
 	new_freq = freq_Hz / 1000;
 	old_freq = clk_get_rate(cpu_clk) / 1000;
 
+	mutex_lock(&priv->lock);
 	if (!IS_ERR(cpu_reg)) {
-		unsigned long opp_freq;
 
 		rcu_read_lock();
 		opp = dev_pm_opp_find_freq_ceil(cpu_dev, &freq_Hz);
@@ -66,7 +107,8 @@ static int set_target(struct cpufreq_policy *policy, unsigned int index)
 			rcu_read_unlock();
 			dev_err(cpu_dev, "failed to find OPP for %ld\n",
 				freq_Hz);
-			return PTR_ERR(opp);
+			ret = PTR_ERR(opp);
+			goto out;
 		}
 		volt = dev_pm_opp_get_voltage(opp);
 		opp_freq = dev_pm_opp_get_freq(opp);
@@ -87,7 +129,7 @@ static int set_target(struct cpufreq_policy *policy, unsigned int index)
 		if (ret) {
 			dev_err(cpu_dev, "failed to scale voltage up: %d\n",
 				ret);
-			return ret;
+			goto out;
 		}
 	}
 
@@ -96,7 +138,7 @@ static int set_target(struct cpufreq_policy *policy, unsigned int index)
 		dev_err(cpu_dev, "failed to set clock rate: %d\n", ret);
 		if (!IS_ERR(cpu_reg) && volt_old > 0)
 			regulator_set_voltage_tol(cpu_reg, volt_old, tol);
-		return ret;
+		goto out;
 	}
 
 	/* scaling down?  scale voltage after frequency */
@@ -106,9 +148,12 @@ static int set_target(struct cpufreq_policy *policy, unsigned int index)
 			dev_err(cpu_dev, "failed to scale voltage down: %d\n",
 				ret);
 			clk_set_rate(cpu_clk, old_freq * 1000);
+			goto out;
 		}
 	}
-
+	priv->opp_freq = opp_freq;
+out:
+	mutex_unlock(&priv->lock);
 	return ret;
 }
 
@@ -194,6 +239,7 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 	unsigned long min_uV = ~0, max_uV = 0;
 	unsigned int transition_latency;
 	int ret;
+	struct srcu_notifier_head *opp_srcu_head;
 
 	ret = allocate_resources(policy->cpu, &cpu_dev, &cpu_reg, &cpu_clk);
 	if (ret) {
@@ -228,6 +274,19 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 		goto out_free_opp;
 	}
 
+	mutex_init(&priv->lock);
+
+	opp_srcu_head = dev_pm_opp_get_notifier(cpu_dev);
+	if (IS_ERR(opp_srcu_head)) {
+		ret = PTR_ERR(opp_srcu_head);
+		goto out_free_priv;
+	}
+
+	priv->opp_nb.notifier_call = opp_notifier;
+	ret = srcu_notifier_chain_register(opp_srcu_head, &priv->opp_nb);
+	if (ret)
+		goto out_free_priv;
+
 	of_property_read_u32(np, "voltage-tolerance", &priv->voltage_tolerance);
 
 	if (of_property_read_u32(np, "clock-latency", &transition_latency))
@@ -276,7 +335,7 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 	ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table);
 	if (ret) {
 		pr_err("failed to init cpufreq table: %d\n", ret);
-		goto out_free_priv;
+		goto out_unregister_nb;
 	}
 
 	priv->cpu_dev = cpu_dev;
@@ -303,6 +362,8 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 
 out_free_cpufreq_table:
 	dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table);
+out_unregister_nb:
+	srcu_notifier_chain_unregister(opp_srcu_head, &priv->opp_nb);
 out_free_priv:
 	kfree(priv);
 out_free_opp:
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#12 lore raw

PATCH 6/6 power: avs: Add support for CPR (Core Power Reduction)

In reply to Stephen Boyd

RBCPR (RapidBridge Core Power Reduction) is a technology to reduce core power on a CPU or other device. It reads voltage settings in efuse from product test process as initial settings and populates OPPs for the device being "monitored". Each OPP corresponds to a "corner" that has a range of valid voltages for a particular frequency. While the device is running at a particular frequency, CPR monitors dynamic factors such as temperature, etc. and adjusts the voltage for that frequency accordingly to save power and meet silicon characteristic requirements.

This driver is based on work by others on codeaurora.org[1].

TODO:
* DT binding documentation

[1] https://www.codeaurora.org/cgit/quic/la/kernel/msm-3.10/tree/drivers/regulator/cpr-regulator.c?h=msm-3.10

---

There's still some TODOs left, but it's mostly surrounding the step voltage reading part, hotplug, and DT documentation.

 drivers/power/avs/Kconfig    |   14 +
 drivers/power/avs/Makefile   |    1 +
 drivers/power/avs/qcom-cpr.c | 1983 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1998 insertions(+)
 create mode 100644 drivers/power/avs/qcom-cpr.c
drivers/power/avs/Kconfig +14 -0
index 7f3d389bd601..82e604b363a6 100644
@@ -11,6 +11,20 @@ menuconfig POWER_AVS
 
 	  Say Y here to enable Adaptive Voltage Scaling class support.
 
+config QCOM_CPR
+	tristate "QCOM Core Power Reduction (CPR) support"
+	select PM_OPP
+	help
+	  Say Y here to enable support for the CPR hardware found on Qualcomm
+	  SoCs like MSM8916.
+
+	  This driver populates CPU OPPs tables and makes adjustments to the
+	  tables based on feedback from the CPR hardware. If you want to do
+	  CPUfrequency scaling say Y here.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called qcom-cpr
+
 config ROCKCHIP_IODOMAIN
         tristate "Rockchip IO domain support"
         depends on ARCH_ROCKCHIP && OF
drivers/power/avs/Makefile +1 -0
index ba4c7bc69225..88f4d5d49cba 100644
@@ -1,2 +1,3 @@
 obj-$(CONFIG_POWER_AVS_OMAP)		+= smartreflex.o
 obj-$(CONFIG_ROCKCHIP_IODOMAIN)		+= rockchip-io-domain.o
+obj-$(CONFIG_QCOM_CPR)			+= qcom-cpr.o
drivers/power/avs/qcom-cpr.c new file +1983 -0

1,983 lines not on this page · raw message

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer
#13 lore raw
In reply to Stephen Boyd
Quoted 3 lines · Stephen Boyd

Stephen Boyd (6):
regulator: core: Don't spew backtraces on duplicate sysfs
regulator: core: Print at debug level on debugfs creation failure

These two patches don't seem to be tied to the rest of the series at all
(they certainly trigger already for some systems).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150602/15cea945/attachment.sig>

#14 lore raw
Quoted 8 lines · Mark Brown
Quoted 3 lines · Stephen Boyd

Stephen Boyd (6):
regulator: core: Don't spew backtraces on duplicate sysfs
regulator: core: Print at debug level on debugfs creation failure

These two patches don't seem to be tied to the rest of the series at all (they certainly trigger already for some systems).

The series causes these warning to trigger on devices with CPR and these patches silence them. So it is related, but the patches aren't necessary for compilation. They should go through the regulator tree, if that's what you're asking.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer
#15 lore raw
Quoted 9 lines · Stephen Boyd
Quoted 2 lines · Mark Brown

These two patches don't seem to be tied to the rest of the series at all (they certainly trigger already for some systems).

The series causes these warning to trigger on devices with CPR and these patches silence them. So it is related, but the patches aren't necessary for compilation. They should go through the regulator tree, if that's what you're asking.

I wasn't really asking, more saying that they should not have been sent
in the same series, especially not a series listing such a complicated
set of external dependencies.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150602/b00ad5b1/attachment.sig>