Skip to contentSkip to conversation

OMAP: Basic DVFS framework

PATCH Superseded Thara Gopinath 9 participants 61 messages Aug 18, 2010 – Nov 24, 2010

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover OMAP: Basic DVFS framework

From: thara gopinath <[email protected]>

This patch series introduces support for support of Dynamic Voltage and Frequency Scaling (DVFS) for OMAP devices. DVFS is a technique that uses the optimal operating frequency and voltage to allow a task to be performed in the required amount of time.
OMAP processors have voltage domains whose voltage can be scaled to various levels depending on which the operating frequencies of certain devices belonging to the domain will also need to be scaled. This voltage frequency tuple is known as Operating Performance Point (OPP). A device can have multiple OPP's. Also a voltage domain could be shared between multiple devices. Also there could be dependencies between various voltage domains for maintaining system performance like VDD<X> should be at voltage v1 when VDD<Y> is at voltage v2.

The design of this framework take into account all the above mentioned points. To summarize the basic design of DVFS framework:-

1. Have device opp tables for each device whose operating frequency can be scaled. This is easy now due to the existance of hwmod layer which allow storing of device specific info. The device opp tables contain the opp pairs (frequency voltage tuples), the voltage domain pointer to which the device belongs to, the device specific set_rate and get_rate API's which will do the actual scaling of the device frequency and retrieve the current device frequency.
2. Introduce use counting on a per VDD basis. This is to take care multiple requests to scale a VDD. The VDD will be scaled to the maximum of the voltages requested.
3. Keep track of all scalable devices belonging to a particular voltage domain the voltage layer.
4. Generic API in the omap device layer which can be called by anybody to scale a device opp. This API will take in the device pointer and frequency to which the device needs to be scaled to. This API will then internally find out the voltage domain to which the device belongs to and the voltage to which the voltage domain needs to be put to for the device to be scaled to the new frequency from the device opp table. Then this API will call into the newly introduced API in voltage layer (as mentioned in 2) to see if there are other requests for the associated voltage domain to be at a voltage higher than the current chosen one. If not this API will go ahead and scale the voltage domain to the new voltage, run through the list of all scalable devices belonging to this voltage domain and scale them to the appropriate frequencies using the set_rate pointer in the device opp tables.
5. Handle inter VDD dependecies.

Work pending -
2. Add OMAP4 support.

Contributors to conceptualization of the design include Benoit Cousson <[email protected]>,
Kevin Hilman <[email protected]>, Paul Wamsley <[email protected]>,
Vishwanath Sripathy <[email protected]> Parthasarathy Basak <[email protected]>
Anand Sawant <[email protected]>

This patch series is primarily based of origin/pm-opp branch of kevin's PM tree and due to it's dependency on the newly introduced opp and voltage layer, and to test dvfs using cpufreq layer the following are the dependent patches to be applied in order.

	https://patchwork.kernel.org/patch/119544/
        https://patchwork.kernel.org/patch/117347/
        https://patchwork.kernel.org/patch/117348/
        https://patchwork.kernel.org/patch/117349/
        http://marc.info/?l=linux-omap&m=128162263809748&w=2
        https://patchwork.kernel.org/patch/119854/
        all 5 patches from origin/pm-cpufreq branch off Kevin's pm tree
        http://marc.info/?l=linux-omap&m=128170725127719&w=2
                                - all eight patches in this series
	http://marc.info/?l=linux-omap&m=128213020527909&w=2
				- all 10 patches in this series

This series has been tested on OMAP3430 SDP for mpu, iva and core DVFS through cpu freq framework.

Thara Gopinath (13):
OMAP: Introduce a user list for each voltage domain instance in the
voltage driver.
OMAP: Introduce API in the OPP layer to find the opp entry
corresponding to a voltage.
OMAP: Introduce voltage domain information in the hwmod structures
OMAP: Introduce API to return a device list associated with a voltage
domain
OMAP: Introduce device specific set rate and get rate in device opp
structures.
OMAP: Voltage layer changes to support DVFS.
OMAP: Introduce dependent voltage domain support.
OMAP: Introduce device set_rate and get_rate.
OMAP: Disable smartreflex across DVFS
OMAP3: Introduce custom set rate and get rate APIs for scalable
devices
OMAP3: Update cpufreq driver to use the new set_rate API
OMAP3: Introduce voltage domain info in the hwmod structures.
OMAP3: Add voltage dependency table for VDD1.

 arch/arm/mach-omap2/cpufreq34xx.c             |  104 ++++++++
 arch/arm/mach-omap2/omap_hwmod_3xxx_data.c    |    3 +
 arch/arm/mach-omap2/voltage.c                 |  313 +++++++++++++++++++++++++
 arch/arm/plat-omap/cpu-omap.c                 |    3 +-
 arch/arm/plat-omap/include/plat/omap_device.h |    3 +
 arch/arm/plat-omap/include/plat/omap_hwmod.h  |    5 +
 arch/arm/plat-omap/include/plat/opp.h         |   45 ++++-
 arch/arm/plat-omap/include/plat/voltage.h     |    4 +
 arch/arm/plat-omap/omap_device.c              |   74 ++++++
 arch/arm/plat-omap/opp.c                      |  159 +++++++++++++
 10 files changed, 711 insertions(+), 2 deletions(-)
Signature · 1 line
1.7.1.GIT
#1 lore raw

PATCH 1/13 OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

This patch introduces a user list of devices associated with each voltage domain instance. The user list is implemented using plist structure with priority node populated with the voltage values. This patch also adds an API which will take in a device and requested voltage as parameters, adds the info to the user list and returns back the maximum voltage requested by all the user devices. This can be used anytime to get the voltage that the voltage domain instance can be transitioned into.

---
 arch/arm/mach-omap2/voltage.c             |   94 +++++++++++++++++++++++++++++
 arch/arm/plat-omap/include/plat/voltage.h |    2 +
 2 files changed, 96 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/voltage.c +94 -0
index 6a07fe9..4624250 100644
@@ -24,6 +24,9 @@
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/debugfs.h>
+#include <linux/spinlock.h>
+#include <linux/plist.h>
+#include <linux/slab.h>
 
 #include <plat/omap-pm.h>
 #include <plat/omap34xx.h>
@@ -95,6 +98,20 @@ struct vp_reg_val {
 };
 
 /**
+ * omap_vdd_user_list	- The per vdd user list
+ *
+ * @dev		: The device asking for the vdd to be set at a particular
+ *		  voltage
+ * @node	: The list head entry
+ * @volt	: The voltage requested by the device <dev>
+ */
+struct omap_vdd_user_list {
+	struct device *dev;
+	struct plist_node node;
+	u32 volt;
+};
+
+/**
  * omap_vdd_info - Per Voltage Domain info
  *
  * @volt_data		: voltage table having the distinct voltages supported
@@ -105,6 +122,9 @@ struct vp_reg_val {
  *			  vp registers
  * @volt_clk		: the clock associated with the vdd.
  * @opp_dev		: the 'struct device' associated with this vdd.
+ * @user_lock		: the lock to be used by the plist user_list
+ * @user_list		: the list head maintaining the various users
+ *			  of this vdd with the voltage requested by each user.
  * @volt_data_count	: Number of distinct voltages supported by this vdd.
  * @nominal_volt	: Nominal voltaged for this vdd.
  * cmdval_reg		: Voltage controller cmdval register.
@@ -117,6 +137,9 @@ struct omap_vdd_info{
 	struct clk *volt_clk;
 	struct device *opp_dev;
 	struct voltagedomain voltdm;
+	spinlock_t user_lock;
+	struct plist_head user_list;
+	struct mutex scaling_mutex;
 	int volt_data_count;
 	unsigned long nominal_volt;
 	u8 cmdval_reg;
@@ -785,11 +808,18 @@ static void __init vdd_data_configure(struct omap_vdd_info *vdd)
 	struct dentry *vdd_debug;
 	char name[16];
 #endif
+
 	if (cpu_is_omap34xx())
 		omap3_vdd_data_configure(vdd);
 	else if (cpu_is_omap44xx())
 		omap4_vdd_data_configure(vdd);
 
+	/* Init the plist */
+	spin_lock_init(&vdd->user_lock);
+	plist_head_init(&vdd->user_list, &vdd->user_lock);
+	/* Init the DVFS mutex */
+	mutex_init(&vdd->scaling_mutex);
+
 #ifdef CONFIG_PM_DEBUG
 	strcpy(name, "vdd_");
 	strcat(name, vdd->voltdm.name);
@@ -1142,6 +1172,70 @@ unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm)
 }
 
 /**
+ * omap_voltage_add_userreq : API to keep track of various requests to
+ *			    scale the VDD and returns the best possible
+ *			    voltage the VDD can be put to.
+ * @volt_domain: pointer to the voltage domain.
+ * @dev : the device pointer.
+ * @volt : the voltage which is requested by the device.
+ *
+ * This API is to be called before the actual voltage scaling is
+ * done to determine what is the best possible voltage the VDD can
+ * be put to. This API adds the device <dev> in the user list of the
+ * vdd <volt_domain> with <volt> as the requested voltage. The user list
+ * is a plist with the priority element absolute voltage values.
+ * The API then finds the maximum of all the requested voltages for
+ * the VDD and returns it back through <volt> pointer itself.
+ * Returns error value in case of any errors.
+ */
+int omap_voltage_add_userreq(struct voltagedomain *voltdm, struct device *dev,
+		unsigned long *volt)
+{
+	struct omap_vdd_info *vdd;
+	struct omap_vdd_user_list *user;
+	struct plist_node *node;
+	int found = 0;
+
+	if (!voltdm || IS_ERR(voltdm)) {
+		pr_warning("%s: VDD specified does not exist!\n", __func__);
+		return -EINVAL;
+	}
+
+	vdd = container_of(voltdm, struct omap_vdd_info, voltdm);
+
+	mutex_lock(&vdd->scaling_mutex);
+
+	plist_for_each_entry(user, &vdd->user_list, node) {
+		if (user->dev == dev) {
+			found = 1;
+			break;
+		}
+	}
+
+	if (!found) {
+		user = kzalloc(sizeof(struct omap_vdd_user_list), GFP_KERNEL);
+		if (!user) {
+			pr_err("%s: Unable to creat a new user for vdd_%s\n",
+				__func__, voltdm->name);
+			mutex_unlock(&vdd->scaling_mutex);
+			return -ENOMEM;
+		}
+		user->dev = dev;
+	} else {
+		plist_del(&user->node, &vdd->user_list);
+	}
+
+	plist_node_init(&user->node, *volt);
+	plist_add(&user->node, &vdd->user_list);
+	node = plist_first(&vdd->user_list);
+	*volt = node->prio;
+
+	mutex_unlock(&vdd->scaling_mutex);
+
+	return 0;
+}
+
+/**
  * omap_vp_enable : API to enable a particular VP
  * @voltdm: pointer to the VDD whose VP is to be enabled.
  *
arch/arm/plat-omap/include/plat/voltage.h +2 -0
index 3e8cf03..fffd086 100644
@@ -144,6 +144,8 @@ struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
 		unsigned long volt);
 void omap_voltage_register_pmic(struct omap_volt_pmic_info *pmic_info);
 unsigned long omap_voltage_get_nom_volt(struct voltagedomain *voltdm);
+int omap_voltage_add_userreq(struct voltagedomain *voltdm, struct device *dev,
+		unsigned long *volt);
 #ifdef CONFIG_PM
 void omap_voltage_init_vc(struct omap_volt_vc_data *setup_vc);
 void omap_change_voltscale_method(int voltscale_method);
Signature · 1 line
1.7.1.GIT
#2 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Quoted 101 lines · Thara Gopinath

This patch introduces a user list of devices associated with each voltage domain instance. The user list is implemented using plist structure with priority node populated with the voltage values. This patch also adds an API which will take in a device and requested voltage as parameters, adds the info to the user list and returns back the maximum voltage requested by all the user devices. This can be used anytime to get the voltage that the voltage domain instance can be transitioned into.

---
 arch/arm/mach-omap2/voltage.c             |   94 +++++++++++++++++++++++++++++
 arch/arm/plat-omap/include/plat/voltage.h |    2 +
 2 files changed, 96 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/voltage.c +38 -0
index 6a07fe9..4624250 100644
@@ -24,6 +24,9 @@
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/debugfs.h>
+#include <linux/spinlock.h>
+#include <linux/plist.h>
+#include <linux/slab.h>
 
 #include <plat/omap-pm.h>
 #include <plat/omap34xx.h>
@@ -95,6 +98,20 @@ struct vp_reg_val {
 };
 
 /**
+ * omap_vdd_user_list	- The per vdd user list
+ *
+ * @dev		: The device asking for the vdd to be set at a particular
+ *		  voltage
+ * @node	: The list head entry
+ * @volt	: The voltage requested by the device <dev>
+ */
+struct omap_vdd_user_list {
+	struct device *dev;
+	struct plist_node node;
+	u32 volt;
+};
+
+/**
  * omap_vdd_info - Per Voltage Domain info
  *
  * @volt_data		: voltage table having the distinct voltages supported
@@ -105,6 +122,9 @@ struct vp_reg_val {
  *			  vp registers
  * @volt_clk		: the clock associated with the vdd.
  * @opp_dev		: the 'struct device' associated with this vdd.
+ * @user_lock		: the lock to be used by the plist user_list
+ * @user_list		: the list head maintaining the various users
+ *			  of this vdd with the voltage requested by each user.
  * @volt_data_count	: Number of distinct voltages supported by this vdd.
  * @nominal_volt	: Nominal voltaged for this vdd.
  * cmdval_reg		: Voltage controller cmdval register.
@@ -117,6 +137,9 @@ struct omap_vdd_info{
 	struct clk *volt_clk;
 	struct device *opp_dev;
 	struct voltagedomain voltdm;
+	spinlock_t user_lock;
+	struct plist_head user_list;
+	struct mutex scaling_mutex;
 	int volt_data_count;
 	unsigned long nominal_volt;
 	u8 cmdval_reg;
@@ -785,11 +808,18 @@ static void __init vdd_data_configure(struct omap_vdd_info *vdd)
 	struct dentry *vdd_debug;
 	char name[16];
 #endif
+
 	if (cpu_is_omap34xx())
 		omap3_vdd_data_configure(vdd);
 	else if (cpu_is_omap44xx())
 		omap4_vdd_data_configure(vdd);
 
+	/* Init the plist */
+	spin_lock_init(&vdd->user_lock);
+	plist_head_init(&vdd->user_list, &vdd->user_lock);
+	/* Init the DVFS mutex */
+	mutex_init(&vdd->scaling_mutex);
+
 #ifdef CONFIG_PM_DEBUG
 	strcpy(name, "vdd_");
 	strcat(name, vdd->voltdm.name);
@@ -1142,6 +1172,70 @@ unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm)
 }
 
 /**
+ * omap_voltage_add_userreq : API to keep track of various requests to
+ *			    scale the VDD and returns the best possible
+ *			    voltage the VDD can be put to.
+ * @volt_domain: pointer to the voltage domain.
+ * @dev : the device pointer.
+ * @volt : the voltage which is requested by the device.
+ *
+ * This API is to be called before the actual voltage scaling is

arch/arm/mach-omap2/voltage.c unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm) · line 1192

Quoted 10 lines
arch/arm/mach-omap2/voltage.c +10 -0
+ * done to determine what is the best possible voltage the VDD can
+ * be put to. This API adds the device <dev> in the user list of the
+ * vdd <volt_domain> with <volt> as the requested voltage. The user list
+ * is a plist with the priority element absolute voltage values.
+ * The API then finds the maximum of all the requested voltages for
+ * the VDD and returns it back through <volt> pointer itself.
+ * Returns error value in case of any errors.
+ */
+int omap_voltage_add_userreq(struct voltagedomain *voltdm, struct device *dev,
+		unsigned long *volt)

How about just omap_voltage_add_request()

Also, do we need both voltdm and dev? With your other patches, can't we look up the voltm based on dev? Or, is there a need for a device to add a request in a voltage domain other than the one to which it belongs?

Also, how does one remove a voltage request?

Quoted 11 lines
arch/arm/mach-omap2/voltage.c +11 -0
+{
+	struct omap_vdd_info *vdd;
+	struct omap_vdd_user_list *user;
+	struct plist_node *node;
+	int found = 0;
+
+	if (!voltdm || IS_ERR(voltdm)) {
+		pr_warning("%s: VDD specified does not exist!\n", __func__);
+		return -EINVAL;
+	}
+

arch/arm/mach-omap2/voltage.c unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm) · line 1213

Quoted 10 lines
arch/arm/mach-omap2/voltage.c +10 -0
+	vdd = container_of(voltdm, struct omap_vdd_info, voltdm);
+
+	mutex_lock(&vdd->scaling_mutex);
+
+	plist_for_each_entry(user, &vdd->user_list, node) {
+		if (user->dev == dev) {
+			found = 1;
+			break;
+		}
+	}

Minor: I'm not crazy about the 'found' flag. IMO, readability is improved if you init 'user = NULL' above, use a tmp pointer to walk the list, and rather than 'found = 1', do 'user = tmp_user' when you find the match.

arch/arm/mach-omap2/voltage.c unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm) · line 1215

Quoted 2 lines
arch/arm/mach-omap2/voltage.c +2 -0
+
+	if (!found) {

and here, do if (!user)

arch/arm/mach-omap2/voltage.c unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm) · line 1225

Quoted 10 lines
arch/arm/mach-omap2/voltage.c +10 -0
+		user = kzalloc(sizeof(struct omap_vdd_user_list), GFP_KERNEL);
+		if (!user) {
+			pr_err("%s: Unable to creat a new user for vdd_%s\n",
+				__func__, voltdm->name);
+			mutex_unlock(&vdd->scaling_mutex);
+			return -ENOMEM;
+		}
+		user->dev = dev;
+	} else {
+		plist_del(&user->node, &vdd->user_list);

hmm... if we get here, we didn't find a match, so 'user' points to the last element in the list (which is the highest voltage request, I guess), or even NULL if the list is empty. Then, this node is deleted.

-ECONFUSED

arch/arm/mach-omap2/voltage.c unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm) · line 1236

Quoted 11 lines
arch/arm/mach-omap2/voltage.c +11 -0
+	}
+
+	plist_node_init(&user->node, *volt);
+	plist_add(&user->node, &vdd->user_list);
+	node = plist_first(&vdd->user_list);
+	*volt = node->prio;
+
+	mutex_unlock(&vdd->scaling_mutex);
+
+	return 0;
+}

Can't think of a use-case now (cuz it's Friday), but would we ever want to add multiple requests per device?

The current approch will only track one request per device.

Kevin

Quoted 17 lines
arch/arm/mach-omap2/voltage.c +1 -0
+/**
  * omap_vp_enable : API to enable a particular VP
  * @voltdm: pointer to the VDD whose VP is to be enabled.
  *
arch/arm/plat-omap/include/plat/voltage.h +2 -0
index 3e8cf03..fffd086 100644
@@ -144,6 +144,8 @@ struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
 		unsigned long volt);
 void omap_voltage_register_pmic(struct omap_volt_pmic_info *pmic_info);
 unsigned long omap_voltage_get_nom_volt(struct voltagedomain *voltdm);
+int omap_voltage_add_userreq(struct voltagedomain *voltdm, struct device *dev,
+		unsigned long *volt);
 #ifdef CONFIG_PM
 void omap_voltage_init_vc(struct omap_volt_vc_data *setup_vc);
 void omap_change_voltscale_method(int voltscale_method);
#3 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Quoted 16 lines · Kevin Hilman

arch/arm/mach-omap2/voltage.c unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm) · line 1225

Quoted 11 lines
arch/arm/mach-omap2/voltage.c +11 -0
+	if (!found) {
+		user = kzalloc(sizeof(struct omap_vdd_user_list), GFP_KERNEL);
+		if (!user) {
+			pr_err("%s: Unable to creat a new user for vdd_%s\n",
+				__func__, voltdm->name);
+			mutex_unlock(&vdd->scaling_mutex);
+			return -ENOMEM;
+		}
+		user->dev = dev;
+	} else {
+		plist_del(&user->node, &vdd->user_list);

hmm... if we get here, we didn't find a match, so 'user' points to the last element in the list (which is the highest voltage request, I guess), or even NULL if the list is empty. Then, this node is deleted.

Quoted 1 line

-ECONFUSED

OK, I'm a bit dense.

It took me a few reads, now I think I know what's going on here.

If we get here, we found a match, and you delete the existing value for that device so that inserting a new one (with a new voltage) will be kept in the right order. Right?

Some comments might help clarify things here.

Kevin

#4 lore raw

RE: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

In reply to Kevin Hilman
Quoted 126 lines
Quoted 126 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Saturday, August 28, 2010 5:23 AM
To: Gopinath, Thara
Cc: [email protected]; [email protected]; Sripathy, Vishwanath; Sawant, Anand; Cousson, Benoit
Subject: Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Quoted 101 lines · Thara Gopinath

This patch introduces a user list of devices associated with each voltage domain instance. The user list is implemented using plist structure with priority node populated with the voltage values. This patch also adds an API which will take in a device and requested voltage as parameters, adds the info to the user list and returns back the maximum voltage requested by all the user devices. This can be used anytime to get the voltage that the voltage domain instance can be transitioned into.

---
 arch/arm/mach-omap2/voltage.c             |   94 +++++++++++++++++++++++++++++
 arch/arm/plat-omap/include/plat/voltage.h |    2 +
 2 files changed, 96 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/voltage.c +38 -0
index 6a07fe9..4624250 100644
@@ -24,6 +24,9 @@
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/debugfs.h>
+#include <linux/spinlock.h>
+#include <linux/plist.h>
+#include <linux/slab.h>
 
 #include <plat/omap-pm.h>
 #include <plat/omap34xx.h>
@@ -95,6 +98,20 @@ struct vp_reg_val {
 };
 
 /**
+ * omap_vdd_user_list	- The per vdd user list
+ *
+ * @dev		: The device asking for the vdd to be set at a particular
+ *		  voltage
+ * @node	: The list head entry
+ * @volt	: The voltage requested by the device <dev>
+ */
+struct omap_vdd_user_list {
+	struct device *dev;
+	struct plist_node node;
+	u32 volt;
+};
+
+/**
  * omap_vdd_info - Per Voltage Domain info
  *
  * @volt_data		: voltage table having the distinct voltages supported
@@ -105,6 +122,9 @@ struct vp_reg_val {
  *			  vp registers
  * @volt_clk		: the clock associated with the vdd.
  * @opp_dev		: the 'struct device' associated with this vdd.
+ * @user_lock		: the lock to be used by the plist user_list
+ * @user_list		: the list head maintaining the various users
+ *			  of this vdd with the voltage requested by each user.
  * @volt_data_count	: Number of distinct voltages supported by this vdd.
  * @nominal_volt	: Nominal voltaged for this vdd.
  * cmdval_reg		: Voltage controller cmdval register.
@@ -117,6 +137,9 @@ struct omap_vdd_info{
 	struct clk *volt_clk;
 	struct device *opp_dev;
 	struct voltagedomain voltdm;
+	spinlock_t user_lock;
+	struct plist_head user_list;
+	struct mutex scaling_mutex;
 	int volt_data_count;
 	unsigned long nominal_volt;
 	u8 cmdval_reg;
@@ -785,11 +808,18 @@ static void __init vdd_data_configure(struct omap_vdd_info *vdd)
 	struct dentry *vdd_debug;
 	char name[16];
 #endif
+
 	if (cpu_is_omap34xx())
 		omap3_vdd_data_configure(vdd);
 	else if (cpu_is_omap44xx())
 		omap4_vdd_data_configure(vdd);
 
+	/* Init the plist */
+	spin_lock_init(&vdd->user_lock);
+	plist_head_init(&vdd->user_list, &vdd->user_lock);
+	/* Init the DVFS mutex */
+	mutex_init(&vdd->scaling_mutex);
+
 #ifdef CONFIG_PM_DEBUG
 	strcpy(name, "vdd_");
 	strcat(name, vdd->voltdm.name);
@@ -1142,6 +1172,70 @@ unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm)
 }
 
 /**
+ * omap_voltage_add_userreq : API to keep track of various requests to
+ *			    scale the VDD and returns the best possible
+ *			    voltage the VDD can be put to.
+ * @volt_domain: pointer to the voltage domain.
+ * @dev : the device pointer.
+ * @volt : the voltage which is requested by the device.
+ *
+ * This API is to be called before the actual voltage scaling is

arch/arm/mach-omap2/voltage.c unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm) · line 1192

Quoted 10 lines
arch/arm/mach-omap2/voltage.c +10 -0
+ * done to determine what is the best possible voltage the VDD can
+ * be put to. This API adds the device <dev> in the user list of the
+ * vdd <volt_domain> with <volt> as the requested voltage. The user list
+ * is a plist with the priority element absolute voltage values.
+ * The API then finds the maximum of all the requested voltages for
+ * the VDD and returns it back through <volt> pointer itself.
+ * Returns error value in case of any errors.
+ */
+int omap_voltage_add_userreq(struct voltagedomain *voltdm, struct device *dev,
+		unsigned long *volt)

How about just omap_voltage_add_request()

Quoted 5 lines
Quoted 5 lines

Also, do we need both voltdm and dev? With your other patches, can't we look up the voltm based on dev? Or, is there a need for a device to add a request in a voltage domain other than the one to which it belongs?

Also, how does one remove a voltage request?

Hello Kevin,

I could rename this API to what you have suggested. Yes we do need voltdm and dev. Let us say I have three devices in a voltdm and I need to maintain a request for each of these devices.

When a omap_device_set_rate API is called by the device to lower its rate the voltage request will automatically get lowered.

Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
arch/arm/mach-omap2/voltage.c +18 -0
+{
+	struct omap_vdd_info *vdd;
+	struct omap_vdd_user_list *user;
+	struct plist_node *node;
+	int found = 0;
+
+	if (!voltdm || IS_ERR(voltdm)) {
+		pr_warning("%s: VDD specified does not exist!\n", __func__);
+		return -EINVAL;
+	}
+
+	vdd = container_of(voltdm, struct omap_vdd_info, voltdm);
+
+	mutex_lock(&vdd->scaling_mutex);
+
+	plist_for_each_entry(user, &vdd->user_list, node) {
+		if (user->dev == dev) {
+			found = 1;
Quoted 8 lines
Quoted 8 lines

arch/arm/mach-omap2/voltage.c unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm) · line 1213

Quoted 3 lines
arch/arm/mach-omap2/voltage.c +3 -0
+			break;
+		}
+	}

Minor: I'm not crazy about the 'found' flag. IMO, readability is improved if you init 'user = NULL' above, use a tmp pointer to walk the list, and rather than 'found = 1', do 'user = tmp_user' when you find the match.

Ok will do.

Quoted 21 lines
Quoted 21 lines

arch/arm/mach-omap2/voltage.c unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm) · line 1215

Quoted 3 lines
arch/arm/mach-omap2/voltage.c +2 -0
+
+	if (!found) {

and here, do if (!user)

arch/arm/mach-omap2/voltage.c unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm) · line 1225

Quoted 10 lines
arch/arm/mach-omap2/voltage.c +10 -0
+		user = kzalloc(sizeof(struct omap_vdd_user_list), GFP_KERNEL);
+		if (!user) {
+			pr_err("%s: Unable to creat a new user for vdd_%s\n",
+				__func__, voltdm->name);
+			mutex_unlock(&vdd->scaling_mutex);
+			return -ENOMEM;
+		}
+		user->dev = dev;
+	} else {
+		plist_del(&user->node, &vdd->user_list);

hmm... if we get here, we didn't find a match, so 'user' points to the last element in the list (which is the highest voltage request, I guess), or even NULL if the list is empty. Then, this node is deleted.

Quoted 1 line
Quoted 1 line

-ECONFUSED

I do not understand this comment. But I will surely look into this part of code. Btw this code is now more tested out with OMAP4 internally.

Quoted 16 lines
Quoted 16 lines

arch/arm/mach-omap2/voltage.c unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm) · line 1236

Quoted 12 lines
arch/arm/mach-omap2/voltage.c +11 -0
+	}
+
+	plist_node_init(&user->node, *volt);
+	plist_add(&user->node, &vdd->user_list);
+	node = plist_first(&vdd->user_list);
+	*volt = node->prio;
+
+	mutex_unlock(&vdd->scaling_mutex);
+
+	return 0;
+}

Can't think of a use-case now (cuz it's Friday), but would we ever want to add multiple requests per device?

Quoted 1 line
Quoted 1 line

The current approch will only track one request per device.

IMHO only as of now only one request per device needs to be tracked. A device the volt domain to be at only one particular voltage at any instance.

Regards
Thara

#5 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

"Gopinath, Thara" <[email protected]> writes:

[...]

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 16 lines

+ * omap_voltage_add_userreq : API to keep track of various requests to
+ * scale the VDD and returns the best possible
+ * voltage the VDD can be put to.
+ * @volt_domain: pointer to the voltage domain.
+ * @dev : the device pointer.
+ * @volt : the voltage which is requested by the device.
+ *
+ * This API is to be called before the actual voltage scaling is
+ * done to determine what is the best possible voltage the VDD can
+ * be put to. This API adds the device <dev> in the user list of the
+ * vdd <volt_domain> with <volt> as the requested voltage. The user list
+ * is a plist with the priority element absolute voltage values.
+ * The API then finds the maximum of all the requested voltages for
+ * the VDD and returns it back through <volt> pointer itself.
+ * Returns error value in case of any errors.
+ */

arch/arm/mach-omap2/voltage.c unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm) · line 1192

Quoted 2 lines
arch/arm/mach-omap2/voltage.c +2 -0
+int omap_voltage_add_userreq(struct voltagedomain *voltdm, struct device *dev,
+		unsigned long *volt)

How about just omap_voltage_add_request()

Also, do we need both voltdm and dev? With your other patches, can't we look up the voltm based on dev? Or, is there a need for a device to add a request in a voltage domain other than the one to which it belongs?

Quoted 7 lines
Quoted 1 line
Quoted 1 line

Also, how does one remove a voltage request?

Hello Kevin,

I could rename this API to what you have suggested. Yes we do need voltdm and dev. Let us say I have three devices in a voltdm and I need to maintain a request for each of these devices.

OK, thanks for clarifying.

Quoted 2 lines

When a omap_device_set_rate API is called by the device to lower its rate the voltage request will automatically get lowered.

OK, but what about removing a request when a device no longer has any voltage constraints.

[...]

Kevin

#6 lore raw

RE: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Quoted 47 lines
Quoted 47 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Thursday, September 16, 2010 8:50 PM
To: Gopinath, Thara
Cc: [email protected]; [email protected]; Sripathy, Vishwanath; Sawant, Anand; Cousson, Benoit
Subject: Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

"Gopinath, Thara" <[email protected]> writes:

[...]

Quoted 32 lines
Quoted 21 lines
Quoted 21 lines
Quoted 16 lines

+ * omap_voltage_add_userreq : API to keep track of various requests to
+ * scale the VDD and returns the best possible
+ * voltage the VDD can be put to.
+ * @volt_domain: pointer to the voltage domain.
+ * @dev : the device pointer.
+ * @volt : the voltage which is requested by the device.
+ *
+ * This API is to be called before the actual voltage scaling is
+ * done to determine what is the best possible voltage the VDD can
+ * be put to. This API adds the device <dev> in the user list of the
+ * vdd <volt_domain> with <volt> as the requested voltage. The user list
+ * is a plist with the priority element absolute voltage values.
+ * The API then finds the maximum of all the requested voltages for
+ * the VDD and returns it back through <volt> pointer itself.
+ * Returns error value in case of any errors.
+ */

arch/arm/mach-omap2/voltage.c unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm) · line 1192

Quoted 2 lines
arch/arm/mach-omap2/voltage.c +2 -0
+int omap_voltage_add_userreq(struct voltagedomain *voltdm, struct device *dev,
+		unsigned long *volt)

How about just omap_voltage_add_request()

Quoted 5 lines
Quoted 5 lines

Also, do we need both voltdm and dev? With your other patches, can't we look up the voltm based on dev? Or, is there a need for a device to add a request in a voltage domain other than the one to which it belongs?

Also, how does one remove a voltage request?

Hello Kevin,

I could rename this API to what you have suggested. Yes we do need voltdm and dev. Let us say I have three devices in a voltdm and I need to maintain a request for each of these devices.

Quoted 7 lines
Quoted 7 lines

OK, thanks for clarifying.

Quoted 2 lines

When a omap_device_set_rate API is called by the device to lower its rate the voltage request will automatically get lowered.

OK, but what about removing a request when a device no longer has any voltage constraints.

Hi Kevin,

The devices will use omap_device_set_rate to lower their frequency. This will in turn call the use counting API in voltage layer and add which in turn will remove the old request for the device and add the new request which will be for a lower voltage. Hence releasing gets taken care of.

Regards
Thara

#7 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

In reply to Thara Gopinath
Quoted 10 lines · Thara Gopinath

This patch introduces a user list of devices associated with each voltage domain instance. The user list is implemented using plist structure with priority node populated with the voltage values. This patch also adds an API which will take in a device and requested voltage as parameters, adds the info to the user list and returns back the maximum voltage requested by all the user devices. This can be used anytime to get the voltage that the voltage domain instance can be transitioned into.

Looking closer at this, keeping track of a list of devices and constraints is what the regulator framework does as well.

Before we get too far down this path, we need to start working with Thomas Petazzoni to better understand how we can use the regulator framework for much of the management levels of the voltage layer.

I'd rather not re-invent some of the management/constraints management that could be done by the regulator framework.

Basically, I think

r = regulator_get(dev, voltdm->name)
regulator_set_voltage(r, volt)

would basially be the equivalent of

  omap_voltage_add_userreq(voldm, dev, &volt);
  omap_scale_voltage(voltdm, volt)

The regulator framework not only provides management of the users and constraints, but also provides post-change notifiers where things like dependent voltages could be handled.

Kevin

#8 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Hello,

Quoted 6 lines · On Wed, 01 Sep 2010 15:51:40 -0700 Kevin Hilman <[email protected]>…

Looking closer at this, keeping track of a list of devices and constraints is what the regulator framework does as well.

Before we get too far down this path, we need to start working with Thomas Petazzoni to better understand how we can use the regulator framework for much of the management levels of the voltage layer.

Yes, as discussed on IRC with Kevin, I think that some of this voltage layer mechanisms would benefit from using the existing kernel regulator framework.

The regulator framework already keeps tracks of consumers (in your patch set called "vdd users"), and for each consumer, keeps track of the requested voltage. The maximum requested voltage is then applied to the regulator. It seems to fit quite well some of the mechanisms you're introducing in this patch set.

Regards,

Thomas

Signature · 4 lines
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
#9 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Thomas Petazzoni had written, on 09/02/2010 02:43 AM, the following:

Quoted 16 lines

Hello,

Quoted 6 lines · On Wed, 01 Sep 2010 15:51:40 -0700 Kevin Hilman <[email protected]>…

Looking closer at this, keeping track of a list of devices and constraints is what the regulator framework does as well.

Before we get too far down this path, we need to start working with Thomas Petazzoni to better understand how we can use the regulator framework for much of the management levels of the voltage layer.

Yes, as discussed on IRC with Kevin, I think that some of this voltage layer mechanisms would benefit from using the existing kernel regulator framework.

Quoted 5 lines

The regulator framework already keeps tracks of consumers (in your patch set called "vdd users"), and for each consumer, keeps track of the requested voltage. The maximum requested voltage is then applied to the regulator. It seems to fit quite well some of the mechanisms you're introducing in this patch set.

Just brainstorming -> if we use the regulator framework - there are potential benefits - agreed. BUT, consider the cpuidle path -> currently we disable SR while hitting off/ret for class3, this is done in irq locked context while the regulator framework uses locks by itself - we would probably have to evolve an entirely different mechanism to handle this.

SR by itself can easily be represented I believe and my thoughts when i initialy looked at that option had been:
a) latency overheads
b) flexibility we achieve vs complexity in s/w implementation
c) lock handling - esp impact on omap_sram_idle paths..

Signature · 4 lines
Regards,
Nishanth Menon

PS:personally though concept of latency additions when scaling voltages, disabling SR etc should be a parameter in userspace governor decisions (the fact that cpuidle and cpufreq are independent statemachine is not my personal fav either). But this is a larger topic of discussion not pertinent to this thread..
#10 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Quoted 5 lines · Nishanth Menon

Just brainstorming -> if we use the regulator framework - there are potential benefits - agreed. BUT, consider the cpuidle path -> currently

we disable SR while hitting off/ret for class3, this is done in irq locked context while the regulator framework uses locks by itself - we

wouldn't it be enough to:

spin_unlock(&sr_lock);
call_whatever_regulator_api();
spin_lock(&sr_lock);

[...]

spin_unlock_irqrestore(&sr_lock, flags);

??

otherwise we will have yet another OMAP-only API to maintain.

Signature · 1 line
balbi
#11 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Felipe Balbi had written, on 09/02/2010 05:00 AM, the following:

Quoted 11 lines · Nishanth Menon
Quoted 3 lines

Just brainstorming -> if we use the regulator framework - there are potential benefits - agreed. BUT, consider the cpuidle path -> currently

we disable SR while hitting off/ret for class3, this is done in irq locked context while the regulator framework uses locks by itself - we

wouldn't it be enough to:

spin_unlock(&sr_lock);
call_whatever_regulator_api();
spin_lock(&sr_lock);

Quoted 8 lines

[...]

spin_unlock_irqrestore(&sr_lock, flags);

??

otherwise we will have yet another OMAP-only API to maintain.

unfortunately no. look at omap_sram_idle function in arch/arm/mach-omap2/pm34xx.c

we do irq_lock_save to prevent interrupts from messing up our decision logic

apply a lot of checks to translate C state to mean which domain is going to go to which OMAP domain state mode - ret/off/inactive etc..

add a bunch of erratas on top of it

finally see if the core/mpu domains (in case of omap4 ivahd domain as well) is going to ret/off state - if yes, SR is disabled for that domain.

note - if we allow unlock of irqs at this point, we cannot predictably progress down the logic.

the option is to move up the sr disable out of omap_sram_idle into yet to be determined logic where irqs are enabled, c state is decided and if c state is lower than a threshold (meaning if mpu OR core OR ivahd can go to lower power states), disable SR.. not efficient and without looking deeper at logic and considering multiple omap generations not sure if this will scale either..

Signature · 2 lines
Regards,
Nishanth Menon
#12 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Hi,

Quoted 2 lines · Nishanth Menon

note - if we allow unlock of irqs at this point, we cannot predictably progress down the logic.

spin_unlock() would not re-enable IRQs, would it ? Isn't it so that spin_unlock_irq() would be the one re-enabling IRQ ?

Signature · 1 line
balbi
#13 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Felipe Balbi had written, on 09/02/2010 05:28 AM, the following:

Quoted 8 lines

Hi,

Quoted 1 line · Nishanth Menon

note - if we allow unlock of irqs at this point, we cannot predictably progress down the logic.

spin_unlock() would not re-enable IRQs, would it ? Isn't it so that spin_unlock_irq() would be the one re-enabling IRQ ?

oopss.. my bad.. if we were to do regulator based implementation of voltage framework, looking closer at the code, driver/regulator/core.c -> rdev->mutex is held for set_voltage, set_mode and all entry functions for regulator operations -> this would be the only concern i have.. I may be barking up the wrong tree here, but i think if i read Documentation/mutex-design.txt right, "contexts such as tasklets and timers" and "mutexes may not be used in hardware or software interrupt" means to me dont do this in irq locked context such as the sitn in omap_sram_idle?

Signature · 2 lines
Regards,
Nishanth Menon
#14 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Hi,

Quoted 15 lines · Nishanth Menon

Felipe Balbi had written, on 09/02/2010 05:28 AM, the following:

Quoted 10 lines

Hi,

Quoted 3 lines · Nishanth Menon

note - if we allow unlock of irqs at this point, we cannot predictably

progress down the logic.

spin_unlock() would not re-enable IRQs, would it ? Isn't it so that spin_unlock_irq() would be the one re-enabling IRQ ?

oopss.. my bad.. if we were to do regulator based implementation of voltage framework, looking closer at the code, driver/regulator/core.c -> rdev->mutex is held for set_voltage, set_mode and all entry functions

Quoted 6 lines

for regulator operations -> this would be the only concern i have.. I may be barking up the wrong tree here, but i think if i read Documentation/mutex-design.txt right, "contexts such as tasklets and timers" and "mutexes may not be used in hardware or software interrupt" means to me dont do this in irq locked context such as the sitn in omap_sram_idle?

true, some re-work would have to be done if you want to use requlator framework.

Signature · 1 line
balbi
#15 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

In reply to Nishanth Menon
Quoted 30 lines · Nishanth Menon

Thomas Petazzoni had written, on 09/02/2010 02:43 AM, the following:

Quoted 16 lines

Hello,

Quoted 6 lines · On Wed, 01 Sep 2010 15:51:40 -0700 Kevin Hilman <[email protected]>…

Looking closer at this, keeping track of a list of devices and constraints is what the regulator framework does as well.

Before we get too far down this path, we need to start working with Thomas Petazzoni to better understand how we can use the regulator framework for much of the management levels of the voltage layer.

Yes, as discussed on IRC with Kevin, I think that some of this voltage layer mechanisms would benefit from using the existing kernel regulator framework.

Quoted 5 lines

The regulator framework already keeps tracks of consumers (in your patch set called "vdd users"), and for each consumer, keeps track of the requested voltage. The maximum requested voltage is then applied to the regulator. It seems to fit quite well some of the mechanisms you're introducing in this patch set.

Just brainstorming -> if we use the regulator framework - there are potential benefits - agreed. BUT, consider the cpuidle path -> currently we disable SR while hitting off/ret for class3, this is done in irq locked context while the regulator framework uses locks by itself - we would probably have to evolve an entirely different mechanism to handle this.

Quoted 5 lines

SR by itself can easily be represented I believe and my thoughts when i initialy looked at that option had been:
a) latency overheads
b) flexibility we achieve vs complexity in s/w implementation
c) lock handling - esp impact on omap_sram_idle paths..

If you look at the current PM branch (specifically pm-sr), you'll see that with the updated SR layer, there is no SR enable/disable in the idle path because there is no voltage scaling during idle.

That being said, even if this is add later, the idle path can potentialy call the SR API directly if needed for the enable/disable.

The concern Thomas and I are raising is that we don't want to re-invent regulator framework functionality in the OMAP voltage layer. Rather, we should keep the OMAP voltage layer as the part that touches the HW, but use the regulator framework for the higher-level management of users and constraints.

Performance issues can be addressed as we hit them, but at this level of the design, I want to make sure the frameworks make sense.

Kevin

#16 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Kevin Hilman had written, on 09/02/2010 12:47 PM, the following:

Quoted 36 lines
Quoted 28 lines · Nishanth Menon

Thomas Petazzoni had written, on 09/02/2010 02:43 AM, the following:

Quoted 15 lines

Hello,

Quoted 6 lines · On Wed, 01 Sep 2010 15:51:40 -0700 Kevin Hilman <[email protected]>…

Looking closer at this, keeping track of a list of devices and constraints is what the regulator framework does as well.

Before we get too far down this path, we need to start working with Thomas Petazzoni to better understand how we can use the regulator framework for much of the management levels of the voltage layer.

Yes, as discussed on IRC with Kevin, I think that some of this voltage layer mechanisms would benefit from using the existing kernel regulator framework.

Quoted 5 lines

The regulator framework already keeps tracks of consumers (in your patch set called "vdd users"), and for each consumer, keeps track of the requested voltage. The maximum requested voltage is then applied to the regulator. It seems to fit quite well some of the mechanisms you're introducing in this patch set.

Just brainstorming -> if we use the regulator framework - there are potential benefits - agreed. BUT, consider the cpuidle path -> currently we disable SR while hitting off/ret for class3, this is done in irq locked context while the regulator framework uses locks by itself - we would probably have to evolve an entirely different mechanism to handle this.

Quoted 5 lines

SR by itself can easily be represented I believe and my thoughts when i initialy looked at that option had been:
a) latency overheads
b) flexibility we achieve vs complexity in s/w implementation
c) lock handling - esp impact on omap_sram_idle paths..

Quoted 3 lines

If you look at the current PM branch (specifically pm-sr), you'll see that with the updated SR layer, there is no SR enable/disable in the idle path because there is no voltage scaling during idle.

This is interesting and I wonder if it works in reality, class 3 operation:
you enable SR h/w monitoring loop as part of dvfs, and when you hit cpuidle and you discover that domain x is going to idle, you'd do:

omap_sram_idle() {
	figureout a lot of stuff
	if (core_next_state == OFF)
		disable_sr(core);
	if (mpu_next_state == OFF)
		disable_sr(mpu);
	__omap_sram_idle()
	if (core_next_state == OFF)
		enable_sr(core);
	if (mpu_next_state == OFF)
		enable_sr(mpu);

}

disable_sr(domain){
disable hw loop
forceupdate to nominal voltage
}
enable_sr(domain){
enable hw loop
}

in the days of SRF, we used to have a patch as well.. see one of the first versions:
http://marc.info/?l=linux-omap&m=122000411826768&w=2

Quoted 3 lines

That being said, even if this is add later, the idle path can potentialy call the SR API directly if needed for the enable/disable.

not clean if it was directly implemented by regulator framework

Quoted 6 lines

The concern Thomas and I are raising is that we don't want to re-invent regulator framework functionality in the OMAP voltage layer. Rather, we should keep the OMAP voltage layer as the part that touches the HW, but use the regulator framework for the higher-level management of users and constraints.

I completely like the idea of going down the regulator path for voltage management, only brainstorming on how to make that happen.

btw, I was playing around with something(attached) that "might" show how it might be done by enhancing the regulator framework for folks who may want to manage their own exclusivity.. e.g. see attachment..

note: I am not saying this is the way to do it, just that: we need to allow regulator operations in irq_locked context if we want to do SR operations (including voltage transitions)

Quoted 3 lines

Performance issues can be addressed as we hit them, but at this level of the design, I want to make sure the frameworks make sense.

I agree.

Quoted 3 lines

Kevin

Signature · 2 lines
Regards,
Nishanth Menon
Quoted 1 line

From 296cd903f0ce5b70e23a052515d8de1ebb9a15cd Mon Sep 17 00:00:00 2001

From: Nishanth Menon <[email protected]>
Date: Thu, 2 Sep 2010 13:24:35 -0500
Subject: {HACK}[PATCH 1/2] regulator: core: change exclusive to flags

we currently use an int for exclusivity, instead change it to a flag based usage. this allows us to extend this to additional flags as well

---
this patch is meant to be for demonstration purposes only.

 drivers/regulator/core.c         |    6 +++---
 include/linux/regulator/driver.h |    4 +++-
 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/regulator/core.c +3 -3
index 422a709..0a1e199 100644
@@ -1127,7 +1127,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
 	return regulator;
 
 found:
-	if (rdev->exclusive) {
+	if (rdev->flags & REGULATOR_EXCLUSIVE_FLAG) {
 		regulator = ERR_PTR(-EPERM);
 		goto out;
 	}
@@ -1148,7 +1148,7 @@ found:
 
 	rdev->open_count++;
 	if (exclusive) {
-		rdev->exclusive = 1;
+		rdev->flags |= REGULATOR_EXCLUSIVE_FLAG;
 
 		ret = _regulator_is_enabled(rdev);
 		if (ret > 0)
@@ -1238,7 +1238,7 @@ void regulator_put(struct regulator *regulator)
 	kfree(regulator);
 
 	rdev->open_count--;
-	rdev->exclusive = 0;
+	rdev->flags &= ~REGULATOR_EXCLUSIVE_FLAG;
 
 	module_put(rdev->owner);
 	mutex_unlock(&regulator_list_mutex);
include/linux/regulator/driver.h +3 -1
index 592cd7c..6397ab3 100644
@@ -156,6 +156,8 @@ struct regulator_desc {
 	struct module *owner;
 };
 
+#define REGULATOR_EXCLUSIVE_FLAG	(0x1 << 1)
+
 /*
  * struct regulator_dev
  *
@@ -170,7 +172,7 @@ struct regulator_dev {
 	struct regulator_desc *desc;
 	int use_count;
 	int open_count;
-	int exclusive;
+	unsigned int flags;
 
 	/* lists we belong to */
 	struct list_head list; /* list of all regulators */
Signature · 1 line
1.6.3.3
Quoted 1 line

From 3145fa45029fbdbfed2b2a2a6e335a72f8c47d36 Mon Sep 17 00:00:00 2001

From: Nishanth Menon <[email protected]>
Date: Thu, 2 Sep 2010 13:40:40 -0500
Subject: {HACK}[PATCH 2/2] regulator: core: introduce unsafe operations

introduce unsafe operations for consumers who can manage their own operation sequencing and dont want core to bother locking out multiple accesses exclusive of each other.

---
this patch is for demonstration purpose only

 drivers/regulator/core.c           |  121 ++++++++++++++++++++++++++----------
 include/linux/regulator/consumer.h |    2 +
 include/linux/regulator/driver.h   |    1 +
 3 files changed, 91 insertions(+), 33 deletions(-)
drivers/regulator/core.c +88 -33

306 lines not on this page · raw message

include/linux/regulator/consumer.h +2 -0
index ebd7472..c071992 100644
@@ -131,6 +131,8 @@ struct regulator *__must_check regulator_get(struct device *dev,
 					     const char *id);
 struct regulator *__must_check regulator_get_exclusive(struct device *dev,
 						       const char *id);
+struct regulator *__must_check regulator_get_exclusive_unsafe(struct device *dev,
+						       const char *id);
 void regulator_put(struct regulator *regulator);
 
 /* regulator output control and status */
include/linux/regulator/driver.h +1 -0
index 6397ab3..6d117d9 100644
@@ -157,6 +157,7 @@ struct regulator_desc {
 };
 
 #define REGULATOR_EXCLUSIVE_FLAG	(0x1 << 1)
+#define REGULATOR_UNSAFEOPS_FLAG	(0x2 << 1)
 
 /*
  * struct regulator_dev
Signature · 1 line
1.6.3.3
#17 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Quoted 1 line · Nishanth Menon

Kevin Hilman had written, on 09/02/2010 12:47 PM, the following:

[...]

Quoted 4 lines
Quoted 4 lines

If you look at the current PM branch (specifically pm-sr), you'll see that with the updated SR layer, there is no SR enable/disable in the idle path because there is no voltage scaling during idle.

[...]

Quoted 6 lines
Quoted 3 lines

That being said, even if this is add later, the idle path can potentialy call the SR API directly if needed for the enable/disable.

not clean if it was directly implemented by regulator framework

The idea (so far) is that there will still be a low-level SmartReflex API, and just a regulator "wrapper." Thomas P. is experimenting with extending the regulator framework to be able to call into external low-level code which does the heavy lifting. He can probably post an RFC soon.

Kevin

#18 lore raw

RE: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

In reply to Kevin Hilman
Quoted 36 lines
Quoted 36 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Thursday, September 02, 2010 4:22 AM
To: Gopinath, Thara
Cc: [email protected]; [email protected]; Sripathy, Vishwanath; Sawant, Anand; Cousson, Benoit; [email protected]
Subject: Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Quoted 10 lines · Thara Gopinath

This patch introduces a user list of devices associated with each voltage domain instance. The user list is implemented using plist structure with priority node populated with the voltage values. This patch also adds an API which will take in a device and requested voltage as parameters, adds the info to the user list and returns back the maximum voltage requested by all the user devices. This can be used anytime to get the voltage that the voltage domain instance can be transitioned into.

Looking closer at this, keeping track of a list of devices and constraints is what the regulator framework does as well.

Before we get too far down this path, we need to start working with Thomas Petazzoni to better understand how we can use the regulator framework for much of the management levels of the voltage layer.

I'd rather not re-invent some of the management/constraints management that could be done by the regulator framework.

Basically, I think

Quoted 7 lines
Quoted 7 lines

r = regulator_get(dev, voltdm->name)
regulator_set_voltage(r, volt)

would basially be the equivalent of

omap_voltage_add_userreq(voldm, dev, &volt);
omap_scale_voltage(voltdm, volt)

Hello Kevin,

Let me startr off by saying that I am not an expert on regulator framework and hence my assessment below could be wrong.
I agree probably regulator framework would be
the best place for this but then IMO regulator framework needs a lot of changes to support the kind of use-counting we need in the voltage layer. To start with regulator_get keeps the use counting only for enabling or disabling a regulator. It does not have a mechanism of adding the requested voltage to a list and picking out the highest among the added values. regulator_set_voltage could be used to route the call to omap_scale_voltage but then it is just a wrapper.

Regards
Thara

#19 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

+ Mark, Liam for regulator questions, thread in archives here:
http://marc.info/?l=linux-omap&m=128349777617270&w=2

Quoted 44 lines · Thara
Quoted 34 lines
Quoted 34 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Thursday, September 02, 2010 4:22 AM
To: Gopinath, Thara
Cc: [email protected]; [email protected]; Sripathy, Vishwanath; Sawant, Anand; Cousson, Benoit; [email protected]
Subject: Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Quoted 10 lines · Thara Gopinath

This patch introduces a user list of devices associated with each voltage domain instance. The user list is implemented using plist structure with priority node populated with the voltage values. This patch also adds an API which will take in a device and requested voltage as parameters, adds the info to the user list and returns back the maximum voltage requested by all the user devices. This can be used anytime to get the voltage that the voltage domain instance can be transitioned into.

Looking closer at this, keeping track of a list of devices and constraints is what the regulator framework does as well.

Before we get too far down this path, we need to start working with Thomas Petazzoni to better understand how we can use the regulator framework for much of the management levels of the voltage layer.

I'd rather not re-invent some of the management/constraints management that could be done by the regulator framework.

Basically, I think

Quoted 7 lines
Quoted 7 lines

r = regulator_get(dev, voltdm->name)
regulator_set_voltage(r, volt)

would basially be the equivalent of

omap_voltage_add_userreq(voldm, dev, &volt);
omap_scale_voltage(voltdm, volt)

Hello Kevin,

Quoted 8 lines

Let me startr off by saying that I am not an expert on regulator framework and hence my assessment below could be wrong.
I agree probably regulator framework would be
the best place for this but then IMO regulator framework needs a lot of changes to support the kind of use-counting we need in the voltage layer. To start with regulator_get keeps the use counting only for enabling or disabling a regulator. It does not have a mechanism of adding the requested voltage to a list and picking out the highest among the added values.

Like you, I'm no expert on the regulator framework internals, but it appears to have a pretty thorough system of constraints management that upon first glance seems to be a good fit for what we need. It may need to be extended, but I would rather see us enhance the regulator framework than re-invent the constraints management.

Quoted 2 lines

regulator_set_voltage could be used to route the call to omap_scale_voltage but then it is just a wrapper.

Yes, just a wrapper, but users would be then using a a well defined and well documented API.

Kevin

#20 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Quoted 5 lines · Kevin Hilman

Like you, I'm no expert on the regulator framework internals, but it appears to have a pretty thorough system of constraints management that upon first glance seems to be a good fit for what we need. It may need to be extended, but I would rather see us enhance the regulator framework than re-invent the constraints management.

This seems reasonable, the only thing I'm wary of with this stuff is adding things to manage anything outside voltages since I'm not convinced that the requirements of different processors for other things are sufficiently well understood to make a simple abstraction.

The only thing I can think you might need to do if this is just straight voltage setting is re-add support for multiple consumers setting voltages simultaneously (there was someone from Qualcomm talking about that as well but I didn't see any patches from him) but the API side is all there and the core support ought to be relatively straightforward.

#21 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Quoted 8 lines · Mark Brown
Quoted 5 lines · Kevin Hilman

Like you, I'm no expert on the regulator framework internals, but it appears to have a pretty thorough system of constraints management that upon first glance seems to be a good fit for what we need. It may need to be extended, but I would rather see us enhance the regulator framework than re-invent the constraints management.

Quoted 4 lines

This seems reasonable, the only thing I'm wary of with this stuff is adding things to manage anything outside voltages since I'm not convinced that the requirements of different processors for other things are sufficiently well understood to make a simple abstraction.

Mark, thanks for your input.

For now, at least on OMAP, we're only thinking of managing voltages for the primary voltage rails on chip.

We already have well defined layers for managing our power domains and clockdomains and prefer to keep that as OMAP-internal code, as it's nothing that drivers really need to be aware of.

Quoted 3 lines

The only thing I can think you might need to do if this is just straight voltage setting is re-add support for multiple consumers setting voltages simultaneously

Yeah, that sounds like what we need.

re-add? was it there at one point and removed? Any pointers to the old code?

Quoted 3 lines

(there was someone from Qualcomm talking about
that as well but I didn't see any patches from him) but the API side is all there and the core support ought to be relatively straightforward.

OK, thanks for the feedback.

Kevin

#22 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Quoted 10 lines · Kevin Hilman
Quoted 3 lines · Mark Brown

The only thing I can think you might need to do if this is just straight voltage setting is re-add support for multiple consumers setting voltages simultaneously

Yeah, that sounds like what we need.

re-add? was it there at one point and removed? Any pointers to the old code?

It was present in the pre-merge regulator API which you can find in the bowels of:

git://opensource.wolfsonmicro.com/linux-2.6-audioplus

but was removed to simplify review during the merge. It's fairly simple to do, it's just that there's been no demand.

Essentially all that needs doing is that when regulator_set_voltage() is called instead of merging with the machine constraints and applying the setting immediately we store the constraints that are specified in the consumer then iterate over all enabled consumers applying all the constraints that they've set in addition to those from the machine. This results in a configuration which is the lowest possible voltage which satisfies all the constraints that have been supplied and for supplies with only one consumer it gives the same behaviour as we have currently.

#23 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Hello,

Quoted 20 lines · Mark Brown
Quoted 10 lines · Kevin Hilman
Quoted 3 lines · Mark Brown

The only thing I can think you might need to do if this is just straight voltage setting is re-add support for multiple consumers setting voltages simultaneously

Yeah, that sounds like what we need.

re-add? was it there at one point and removed? Any pointers to the old code?

It was present in the pre-merge regulator API which you can find in the bowels of:

git://opensource.wolfsonmicro.com/linux-2.6-audioplus

but was removed to simplify review during the merge. It's fairly simple to do, it's just that there's been no demand.

Quoted 9 lines

Essentially all that needs doing is that when regulator_set_voltage() is called instead of merging with the machine constraints and applying the setting immediately we store the constraints that are specified in the consumer then iterate over all enabled consumers applying all the constraints that they've set in addition to those from the machine. This results in a configuration which is the lowest possible voltage which satisfies all the constraints that have been supplied and for supplies with only one consumer it gives the same behaviour as we have currently.

How about taking Thara's proposal of using priority lists?

I mean, it could make more sense to keep the constraints into a priority list, instead of "iterate over all enabled consumers"?

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

---
Eduardo Valentin

#24 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Quoted 33 lines · Eduardo Valentin

Hello,

Quoted 20 lines · Mark Brown
Quoted 10 lines · Kevin Hilman
Quoted 3 lines · Mark Brown

The only thing I can think you might need to do if this is just straight voltage setting is re-add support for multiple consumers setting voltages simultaneously

Yeah, that sounds like what we need.

re-add? was it there at one point and removed? Any pointers to the old code?

It was present in the pre-merge regulator API which you can find in the bowels of:

git://opensource.wolfsonmicro.com/linux-2.6-audioplus

but was removed to simplify review during the merge. It's fairly simple to do, it's just that there's been no demand.

Quoted 9 lines

Essentially all that needs doing is that when regulator_set_voltage() is called instead of merging with the machine constraints and applying the setting immediately we store the constraints that are specified in the consumer then iterate over all enabled consumers applying all the constraints that they've set in addition to those from the machine. This results in a configuration which is the lowest possible voltage which satisfies all the constraints that have been supplied and for supplies with only one consumer it gives the same behaviour as we have currently.

Quoted 5 lines

How about taking Thara's proposal of using priority lists?

I mean, it could make more sense to keep the constraints into a priority list, instead of "iterate over all enabled consumers"?

You've not really explained why you think a priority list makes more sense in this case ?

Liam

Signature · 3 lines
Freelance Developer, SlimLogic Ltd
ASoC and Voltage Regulator Maintainer.
http://www.slimlogic.co.uk
#25 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

In reply to Eduardo Valentin
Quoted 8 lines · Eduardo Valentin
Quoted 5 lines · Mark Brown

Essentially all that needs doing is that when regulator_set_voltage() is called instead of merging with the machine constraints and applying the setting immediately we store the constraints that are specified in the consumer then iterate over all enabled consumers applying all the constraints that they've set in addition to those from the machine.

Quoted 4 lines

How about taking Thara's proposal of using priority lists?

I mean, it could make more sense to keep the constraints into a priority list, instead of "iterate over all enabled consumers"?

Partly just that the lists tend to be short enough that it's hardly worth bothering with the more complex algorithm, partly because the fact that you have both a minimum constraint and a maximum constraint makes it into two priority lists you need to maintain.

#26 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

In reply to Mark Brown

Hello Mark,

Quoted 10 lines · On Fri, 3 Sep 2010 19:20:52 +0100 Mark Brown…
Quoted 2 lines

re-add? was it there at one point and removed? Any pointers to the old code?

It was present in the pre-merge regulator API which you can find in the bowels of:

git://opensource.wolfsonmicro.com/linux-2.6-audioplus

but was removed to simplify review during the merge. It's fairly simple to do, it's just that there's been no demand.

I'm finally taking the time to look more closely into this. I've tried to find the original implementation of multi-consumer tracking, but couldn't find it in the different branches of the linux-2.6-audioplus. Do you have a more specific pointer ?

Thanks,

Thomas

Signature · 4 lines
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
#27 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

In reply to Mark Brown

Hello Mark,

Quoted 9 lines · On Fri, 3 Sep 2010 19:20:52 +0100 Mark Brown…

Essentially all that needs doing is that when regulator_set_voltage() is called instead of merging with the machine constraints and applying the setting immediately we store the constraints that are specified in the consumer then iterate over all enabled consumers applying all the constraints that they've set in addition to those from the machine. This results in a configuration which is the lowest possible voltage which satisfies all the constraints that have been supplied and for supplies with only one consumer it gives the same behaviour as we have currently.

I went ahead and implemented this (without looking at previous existing code since I couldn't find it). What about the following patch ?

I've tested it with a dummy platform driver and a dummy regulator driver, making sure that the correct voltage gets set at the regulator level. My testing had a device requesting a voltage [830000, 833000] and another device [822000, 831000]. Without the patch, as the regulator_set_voltage() gets called for the second device last, the voltage is set at 822000 which is not acceptable for the first device. With the patch, the 830000 voltage is kept, since it satisfies both consumers. If the second device had [822000,828000] has its voltage requirements, then regulator_set_voltage() would fail with -EINVAL since it is not possible to find a voltage level that satisfies both consumers.

If you're ok with it, I'll submit it the proper way.

Thanks,

Thomas

Quoted 1 line

From fa0edfc1a4428aead4502fcba248084c1194da53 Mon Sep 17 00:00:00 2001

From: Thomas Petazzoni <[email protected]>
Date: Wed, 24 Nov 2010 10:34:35 +0100
Subject: [PATCH] regulator: Take into account the requirements of all consumers

Extend the regulator_set_voltage() function to take into account the voltage requirements of all consumers of the regulator being changed, in order to set the voltage to the minimum voltage acceptable to all consumers. The existing behaviour was that the latest regulator_set_voltage() call would win over previous regulator_set_voltage() calls even if setting the voltage to a non-acceptable level from other consumers.

---
 drivers/regulator/core.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
drivers/regulator/core.c +27 -0
index f1d10c9..12a1cae 100644
@@ -132,6 +132,28 @@ static int regulator_check_voltage(struct regulator_dev *rdev,
 	return 0;
 }
 
+/* Make sure we select a voltage that suits the needs of all
+ * regulator consumers
+ */
+static int regulator_check_consumers(struct regulator_dev *rdev,
+				     int *min_uV, int *max_uV)
+{
+	struct regulator *regulator;
+
+	list_for_each_entry(regulator, &rdev->consumer_list, list)
+	{
+		if (*max_uV > regulator->max_uV)
+			*max_uV = regulator->max_uV;
+		if (*min_uV < regulator->min_uV)
+			*min_uV = regulator->min_uV;
+	}
+
+	if (*min_uV > *max_uV)
+		return -EINVAL;
+
+	return 0;
+}
+
 /* current constraint check */
 static int regulator_check_current_limit(struct regulator_dev *rdev,
 					int *min_uA, int *max_uA)
@@ -1636,6 +1658,11 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
 		goto out;
 	regulator->min_uV = min_uV;
 	regulator->max_uV = max_uV;
+
+	ret = regulator_check_consumers(rdev, &min_uV, &max_uV);
+	if (ret < 0)
+		goto out;
+
 	ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV);
 
 out:
Signature · 9 lines
1.7.0.4



-- 
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
#28 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Quoted 2 lines · Thomas Petazzoni

I went ahead and implemented this (without looking at previous existing code since I couldn't find it). What about the following patch ?

That's pretty much exactly what the old code did - told you it was trivial :)

#29 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

In reply to Gopinath, Thara

"Gopinath, Thara" <[email protected]> writes:

[...]

Quoted 8 lines

I agree probably regulator framework would be
the best place for this but then IMO regulator framework needs a lot of changes to support the kind of use-counting we need in the voltage layer. To start with regulator_get keeps the use counting only for enabling or disabling a regulator. It does not have a mechanism of adding the requested voltage to a list and picking out the highest among the added values. regulator_set_voltage could be used to route the call to omap_scale_voltage but then it is just a wrapper.

Hi Thara,

Based on feedback from regulator folks (and also remembering that we agreed to use the regulator framework as a later phase) let's keep your current approach as an interim solution, but knowing that we will eventually switch to use the regulator framework for handling multiple requests.

In the background Thomas and I will continue to research the changes needed in the regulator framework.

Thanks,

Kevin

#30 lore raw

Re: [PATCH 01/13] OMAP: Introduce a user list for each voltage domain instance in the voltage driver.

Quoted 2 lines · Kevin Hilman

In the background Thomas and I will continue to research the changes needed in the regulator framework.

These really are fairly straightforward, the algorithm I outlined in my last mail will do the trick.

#31 lore raw

PATCH 2/13 OMAP: Introduce API in the OPP layer to find the opp entry corresponding to a voltage.

In reply to Thara Gopinath

This patch adds an API in the opp layer to get the opp table entry corresponding to the voltage passed as the parameter.

---
 arch/arm/plat-omap/include/plat/opp.h |    8 ++++++++
 arch/arm/plat-omap/opp.c              |   28 ++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)
arch/arm/plat-omap/include/plat/opp.h +8 -0
index 997b56e..0e580ed 100644
@@ -76,6 +76,8 @@ struct omap_opp *opp_find_freq_floor(struct device *dev, unsigned long *freq);
 
 struct omap_opp *opp_find_freq_ceil(struct device *dev, unsigned long *freq);
 
+struct omap_opp *opp_find_voltage(struct device *dev, unsigned long volt);
+
 int opp_add(const struct omap_opp_def *opp_def);
 
 int opp_enable(struct omap_opp *opp);
@@ -119,6 +121,12 @@ static inline struct omap_opp *opp_find_freq_ceil(struct omap_opp *oppl,
 	return ERR_PTR(-EINVAL);
 }
 
+static inline struct omap_opp *opp_find_voltage(struct device *dev,
+						unsigned long volt)
+{
+	return ERR_PTR(-EINVAL);
+}
+
 static inline struct omap_opp *opp_add(struct omap_opp *oppl,
 				       const struct omap_opp_def *opp_def)
 {
arch/arm/plat-omap/opp.c +28 -0
index 5a86bdd..a3dea82 100644
@@ -290,6 +290,34 @@ struct omap_opp *opp_find_freq_floor(struct device *dev, unsigned long *freq)
 	return opp;
 }
 
+/**
+ * opp_find_voltage() - search for an exact voltage
+ * @dev:	device pointer associated with the opp type
+ * @volt:	voltage to search for
+ *
+ * Searches for exact match in the opp list and returns handle to the matching
+ * opp if found, else returns ERR_PTR in case of error and should be handled
+ * using IS_ERR.
+ */
+struct omap_opp *opp_find_voltage(struct device *dev, unsigned long volt)
+{
+	struct device_opp *dev_opp;
+	struct omap_opp *temp_opp, *opp = ERR_PTR(-ENODEV);
+
+	dev_opp = find_device_opp(dev);
+	if (IS_ERR(dev_opp))
+		return opp;
+
+	list_for_each_entry(temp_opp, &dev_opp->opp_list, node) {
+		if (temp_opp->enabled && temp_opp->u_volt == volt) {
+			opp = temp_opp;
+			break;
+		}
+	}
+
+	return opp;
+}
+
 /* wrapper to reuse converting opp_def to opp struct */
 static void omap_opp_populate(struct omap_opp *opp,
 			      const struct omap_opp_def *opp_def)
Signature · 1 line
1.7.1.GIT
#32 lore raw

PATCH 3/13 OMAP: Introduce voltage domain information in the hwmod structures

In reply to Thara Gopinath

This patch extends the device hwmod structure to contain info about the voltage domain to which the device belongs to. This is needed to support a device based DVFS where the device knows which voltage domain it belongs to.

---
 arch/arm/plat-omap/include/plat/omap_hwmod.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
arch/arm/plat-omap/include/plat/omap_hwmod.h +5 -0
index cab4a68..367b7ca 100644
@@ -36,6 +36,7 @@
 #include <linux/list.h>
 #include <linux/ioport.h>
 #include <plat/cpu.h>
+#include <plat/voltage.h>
 
 struct omap_device;
 
@@ -415,6 +416,8 @@ struct omap_hwmod_class {
  * @main_clk: main clock: OMAP clock name
  * @_clk: pointer to the main struct clk (filled in at runtime)
  * @opt_clks: other device clocks that drivers can request (0..*)
+ * @vdd_name: voltage domain name
+ * @voltdm: pointer to voltage domain (filled in at runtime)
  * @masters: ptr to array of OCP ifs that this hwmod can initiate on
  * @slaves: ptr to array of OCP ifs that this hwmod can respond on
  * @dev_attr: arbitrary device attributes that can be passed to the driver
@@ -456,6 +459,8 @@ struct omap_hwmod {
 	const char			*main_clk;
 	struct clk			*_clk;
 	struct omap_hwmod_opt_clk	*opt_clks;
+	const char			*vdd_name;
+	struct voltagedomain		*voltdm;
 	struct omap_hwmod_ocp_if	**masters; /* connect to *_IA */
 	struct omap_hwmod_ocp_if	**slaves;  /* connect to *_TA */
 	void				*dev_attr;
Signature · 1 line
1.7.1.GIT
#33 lore raw

PATCH 4/13 OMAP: Introduce API to return a device list associated with a voltage domain

In reply to Thara Gopinath

This patch adds an API in the opp layer that
can be used by the voltage layer to get a list of all the scalable devices belonging to a particular voltage domain. This API is to be typically called only once by the voltage layer per voltage domain instance and the device list should be stored. This approach makes it easy during dvfs to scale all the devices associated with a voltage domain and then scale the voltage domain.

---
 arch/arm/plat-omap/include/plat/opp.h |    9 +++++++++
 arch/arm/plat-omap/opp.c              |   28 ++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)
arch/arm/plat-omap/include/plat/opp.h +9 -0
index 0e580ed..a4c1669 100644
@@ -18,6 +18,7 @@
 #include <linux/cpufreq.h>
 
 #include <plat/common.h>
+#include <plat/voltage.h>
 
 /**
  * struct omap_opp_def - OMAP OPP Definition
@@ -86,6 +87,9 @@ int opp_disable(struct omap_opp *opp);
 
 void opp_init_cpufreq_table(struct device *dev,
 			    struct cpufreq_frequency_table **table);
+
+struct device **opp_init_voltage_params(struct voltagedomain *voltdm,
+					int *dev_count);
 #else
 static inline unsigned long opp_get_voltage(const struct omap_opp *opp)
 {
@@ -149,5 +153,10 @@ void opp_init_cpufreq_table(struct omap_opp *opps,
 {
 }
 
+static inline struct device **opp_init_voltage_params(
+			struct voltagedomain *voltdm, int *dev_count)
+{
+}
+
 #endif		/* CONFIG_PM */
 #endif		/* __ASM_ARM_OMAP_OPP_H */
arch/arm/plat-omap/opp.c +28 -0
index a3dea82..72dd62a 100644
@@ -502,3 +502,31 @@ void opp_init_cpufreq_table(struct device *dev,
 
 	*table = &freq_table[0];
 }
+
+struct device **opp_init_voltage_params(struct voltagedomain *voltdm,
+					int *dev_count)
+{
+	struct device_opp *dev_opp;
+	struct device **dev_list;
+	int count = 0, i = 0;
+
+	list_for_each_entry(dev_opp, &dev_opp_list, node) {
+		if (!dev_opp->oh->vdd_name)
+			continue;
+
+		if (!strcmp(dev_opp->oh->vdd_name, voltdm->name)) {
+			dev_opp->oh->voltdm = voltdm;
+			count++;
+		}
+	}
+
+	dev_list = kzalloc(sizeof(struct device *) * count, GFP_KERNEL);
+
+	list_for_each_entry(dev_opp, &dev_opp_list, node) {
+		if (dev_opp->oh->voltdm == voltdm)
+			dev_list[i++] = dev_opp->dev;
+	}
+
+	*dev_count = count;
+	return dev_list;
+}
Signature · 1 line
1.7.1.GIT
#34 lore raw

Re: [PATCH 04/13] OMAP: Introduce API to return a device list associated with a voltage domain

Quoted 10 lines · Thara Gopinath

This patch adds an API in the opp layer that
can be used by the voltage layer to get a list of all the scalable devices belonging to a particular voltage domain. This API is to be typically called only once by the voltage layer per voltage domain instance and the device list should be stored. This approach makes it easy during dvfs to scale all the devices associated with a voltage domain and then scale the voltage domain.

I think this should be done in two steps.

During init, each OPP

Quoted 50 lines
---
 arch/arm/plat-omap/include/plat/opp.h |    9 +++++++++
 arch/arm/plat-omap/opp.c              |   28 ++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)
arch/arm/plat-omap/include/plat/opp.h +9 -0
index 0e580ed..a4c1669 100644
@@ -18,6 +18,7 @@
 #include <linux/cpufreq.h>
 
 #include <plat/common.h>
+#include <plat/voltage.h>
 
 /**
  * struct omap_opp_def - OMAP OPP Definition
@@ -86,6 +87,9 @@ int opp_disable(struct omap_opp *opp);
 
 void opp_init_cpufreq_table(struct device *dev,
 			    struct cpufreq_frequency_table **table);
+
+struct device **opp_init_voltage_params(struct voltagedomain *voltdm,
+					int *dev_count);
 #else
 static inline unsigned long opp_get_voltage(const struct omap_opp *opp)
 {
@@ -149,5 +153,10 @@ void opp_init_cpufreq_table(struct omap_opp *opps,
 {
 }
 
+static inline struct device **opp_init_voltage_params(
+			struct voltagedomain *voltdm, int *dev_count)
+{
+}
+
 #endif		/* CONFIG_PM */
 #endif		/* __ASM_ARM_OMAP_OPP_H */
arch/arm/plat-omap/opp.c +4 -0
index a3dea82..72dd62a 100644
@@ -502,3 +502,31 @@ void opp_init_cpufreq_table(struct device *dev,
 
 	*table = &freq_table[0];
 }
+
+struct device **opp_init_voltage_params(struct voltagedomain *voltdm,
+					int *dev_count)
+{

arch/arm/plat-omap/opp.c void opp_init_cpufreq_table(struct device *dev, · line 518

Quoted 10 lines
arch/arm/plat-omap/opp.c +10 -0
+	struct device_opp *dev_opp;
+	struct device **dev_list;
+	int count = 0, i = 0;
+
+	list_for_each_entry(dev_opp, &dev_opp_list, node) {
+		if (!dev_opp->oh->vdd_name)
+			continue;
+
+		if (!strcmp(dev_opp->oh->vdd_name, voltdm->name)) {
+			dev_opp->oh->voltdm = voltdm;

Couldn't we assign the voltdm at opp_add() time since you added it as part of the hwmod?

arch/arm/plat-omap/opp.c void opp_init_cpufreq_table(struct device *dev, · line 521

Quoted 3 lines
arch/arm/plat-omap/opp.c +3 -0
+			count++;
+		}
+	}

So the above could be done at opp_add() time, leaving only the rest for this function.

arch/arm/plat-omap/opp.c void opp_init_cpufreq_table(struct device *dev, · line 532

Quoted 10 lines
arch/arm/plat-omap/opp.c +10 -0
+	dev_list = kzalloc(sizeof(struct device *) * count, GFP_KERNEL);
+
+	list_for_each_entry(dev_opp, &dev_opp_list, node) {
+		if (dev_opp->oh->voltdm == voltdm)
+			dev_list[i++] = dev_opp->dev;
+	}
+
+	*dev_count = count;
+	return dev_list;
+}

Kevin

#35 lore raw

Re: [PATCH 04/13] OMAP: Introduce API to return a device list associated with a voltage domain

Quoted 11 lines · Kevin Hilman
Quoted 9 lines · Thara Gopinath

This patch adds an API in the opp layer that
can be used by the voltage layer to get a list of all the scalable devices belonging to a particular voltage domain. This API is to be typically called only once by the voltage layer per voltage domain instance and the device list should be stored. This approach makes it easy during dvfs to scale all the devices associated with a voltage domain and then scale the voltage domain.

Quoted 5 lines
Quoted 1 line

I think this should be done in two steps.

During init, each OPP

oops, ignore this part. pushed send too soon. Only comments below are relevant.

Kevin

#36 lore raw

RE: [PATCH 04/13] OMAP: Introduce API to return a device list associated with a voltage domain

In reply to Kevin Hilman
Quoted 82 lines
Quoted 82 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Saturday, August 28, 2010 6:23 AM
To: Gopinath, Thara
Cc: [email protected]; [email protected]; Sripathy, Vishwanath; Sawant, Anand; Cousson, Benoit
Subject: Re: [PATCH 04/13] OMAP: Introduce API to return a device list associated with a voltage domain

Quoted 10 lines · Thara Gopinath

This patch adds an API in the opp layer that
can be used by the voltage layer to get a list of all the scalable devices belonging to a particular voltage domain. This API is to be typically called only once by the voltage layer per voltage domain instance and the device list should be stored. This approach makes it easy during dvfs to scale all the devices associated with a voltage domain and then scale the voltage domain.

I think this should be done in two steps.

During init, each OPP

Quoted 55 lines
---
 arch/arm/plat-omap/include/plat/opp.h |    9 +++++++++
 arch/arm/plat-omap/opp.c              |   28 ++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)
arch/arm/plat-omap/include/plat/opp.h +9 -0
index 0e580ed..a4c1669 100644
@@ -18,6 +18,7 @@
 #include <linux/cpufreq.h>
 
 #include <plat/common.h>
+#include <plat/voltage.h>
 
 /**
  * struct omap_opp_def - OMAP OPP Definition
@@ -86,6 +87,9 @@ int opp_disable(struct omap_opp *opp);
 
 void opp_init_cpufreq_table(struct device *dev,
 			    struct cpufreq_frequency_table **table);
+
+struct device **opp_init_voltage_params(struct voltagedomain *voltdm,
+					int *dev_count);
 #else
 static inline unsigned long opp_get_voltage(const struct omap_opp *opp)
 {
@@ -149,5 +153,10 @@ void opp_init_cpufreq_table(struct omap_opp *opps,
 {
 }
 
+static inline struct device **opp_init_voltage_params(
+			struct voltagedomain *voltdm, int *dev_count)
+{
+}
+
 #endif		/* CONFIG_PM */
 #endif		/* __ASM_ARM_OMAP_OPP_H */
arch/arm/plat-omap/opp.c +9 -0
index a3dea82..72dd62a 100644
@@ -502,3 +502,31 @@ void opp_init_cpufreq_table(struct device *dev,
 
 	*table = &freq_table[0];
 }
+
+struct device **opp_init_voltage_params(struct voltagedomain *voltdm,
+					int *dev_count)
+{
+	struct device_opp *dev_opp;
+	struct device **dev_list;
+	int count = 0, i = 0;
+
+	list_for_each_entry(dev_opp, &dev_opp_list, node) {
Quoted 8 lines
Quoted 8 lines

arch/arm/plat-omap/opp.c void opp_init_cpufreq_table(struct device *dev, · line 518

Quoted 5 lines
arch/arm/plat-omap/opp.c +5 -0
+		if (!dev_opp->oh->vdd_name)
+			continue;
+
+		if (!strcmp(dev_opp->oh->vdd_name, voltdm->name)) {
+			dev_opp->oh->voltdm = voltdm;

Couldn't we assign the voltdm at opp_add() time since you added it as part of the hwmod?

We cannot as the voltage layer is not initialized at the point of opp_add. Having said this, today voltage layer is dependent on opp layer only to figure out the current nominal voltage from the opp table. If that can be some how decoupled we can initialize voltage layer early on and implement this.

Regards
Thara

#37 lore raw

Re: [PATCH 04/13] OMAP: Introduce API to return a device list associated with a voltage domain

"Gopinath, Thara" <[email protected]> writes:

[...]

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
arch/arm/plat-omap/opp.c +8 -0
+struct device **opp_init_voltage_params(struct voltagedomain *voltdm,
+					int *dev_count)
+{
+	struct device_opp *dev_opp;
+	struct device **dev_list;
+	int count = 0, i = 0;
+
+	list_for_each_entry(dev_opp, &dev_opp_list, node) {
Quoted 8 lines
Quoted 8 lines

arch/arm/plat-omap/opp.c void opp_init_cpufreq_table(struct device *dev, · line 518

Quoted 5 lines
arch/arm/plat-omap/opp.c +5 -0
+		if (!dev_opp->oh->vdd_name)
+			continue;
+
+		if (!strcmp(dev_opp->oh->vdd_name, voltdm->name)) {
+			dev_opp->oh->voltdm = voltdm;

Couldn't we assign the voltdm at opp_add() time since you added it as part of the hwmod?

Quoted 4 lines

We cannot as the voltage layer is not initialized at the point of opp_add. Having said this, today voltage layer is dependent on opp layer only to figure out the current nominal voltage from the opp table. If that can be some how decoupled we can initialize voltage layer early on and implement this.

We could decouple the voltage init into and early init and late init to handle this.

Kevin

#38 lore raw

RE: [PATCH 04/13] OMAP: Introduce API to return a device list associated with a voltage domain

Quoted 31 lines
Quoted 31 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Thursday, September 16, 2010 8:52 PM
To: Gopinath, Thara
Cc: [email protected]; [email protected]; Sripathy, Vishwanath; Sawant, Anand; Cousson, Benoit
Subject: Re: [PATCH 04/13] OMAP: Introduce API to return a device list associated with a voltage domain

"Gopinath, Thara" <[email protected]> writes:

[...]

Quoted 17 lines
Quoted 16 lines
Quoted 16 lines

arch/arm/plat-omap/opp.c void opp_init_cpufreq_table(struct device *dev, · line 518

Quoted 13 lines
arch/arm/plat-omap/opp.c +13 -0
+struct device **opp_init_voltage_params(struct voltagedomain *voltdm,
+					int *dev_count)
+{
+	struct device_opp *dev_opp;
+	struct device **dev_list;
+	int count = 0, i = 0;
+
+	list_for_each_entry(dev_opp, &dev_opp_list, node) {
+		if (!dev_opp->oh->vdd_name)
+			continue;
+
+		if (!strcmp(dev_opp->oh->vdd_name, voltdm->name)) {
+			dev_opp->oh->voltdm = voltdm;

Couldn't we assign the voltdm at opp_add() time since you added it as part of the hwmod?

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

We cannot as the voltage layer is not initialized at the point of opp_add. Having said this, today voltage layer is dependent on opp layer only to figure out the current nominal voltage from the opp table. If that can be some how decoupled we can initialize voltage layer early on and implement this.

We could decouple the voltage init into and early init and late init to handle this.

Hello Kevin,

Yes we could. In fact I do not like the idea of voltage layer dependent
on opp layer itself. So here is my proposal. Maintain a variable in the main per vdd structure omap_vdd_info curr_volt which will get updated each time a voltage scale is attempted. Now the only issue is during boot up how does the voltage layer know what voltage each vdd should be put into ? A piece of code can be implemented in pm34xx.c/pm44xx.c init functions to read the clock rate associated with each vdd , call into the opp layer to get the corresponding
voltage ( basically the sequence we do today everytime in voltage layer when the API to get nominal voltage is called) and call omap_voltage_scale_vdd with the corresponding voltage. This way we can fully decouple voltage laye from opp layer and make voltage init an early_initcall. We might still need a late_initcall to register debugfs entries though.
What is your take on this ?

Regards
Thara

Quoted 2 lines
Quoted 2 lines

Kevin

#39 lore raw

Re: [PATCH 04/13] OMAP: Introduce API to return a device list associated with a voltage domain

Quoted 37 lines · Thara
Quoted 29 lines
Quoted 29 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Thursday, September 16, 2010 8:52 PM
To: Gopinath, Thara
Cc: [email protected]; [email protected]; Sripathy, Vishwanath; Sawant, Anand; Cousson, Benoit
Subject: Re: [PATCH 04/13] OMAP: Introduce API to return a device list associated with a voltage domain

"Gopinath, Thara" <[email protected]> writes:

[...]

Quoted 17 lines
Quoted 16 lines
Quoted 16 lines

arch/arm/plat-omap/opp.c void opp_init_cpufreq_table(struct device *dev, · line 518

Quoted 13 lines
arch/arm/plat-omap/opp.c +13 -0
+struct device **opp_init_voltage_params(struct voltagedomain *voltdm,
+					int *dev_count)
+{
+	struct device_opp *dev_opp;
+	struct device **dev_list;
+	int count = 0, i = 0;
+
+	list_for_each_entry(dev_opp, &dev_opp_list, node) {
+		if (!dev_opp->oh->vdd_name)
+			continue;
+
+		if (!strcmp(dev_opp->oh->vdd_name, voltdm->name)) {
+			dev_opp->oh->voltdm = voltdm;

Couldn't we assign the voltdm at opp_add() time since you added it as part of the hwmod?

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

We cannot as the voltage layer is not initialized at the point of opp_add. Having said this, today voltage layer is dependent on opp layer only to figure out the current nominal voltage from the opp table. If that can be some how decoupled we can initialize voltage layer early on and implement this.

We could decouple the voltage init into and early init and late init to handle this.

Quoted 6 lines

Hello Kevin,

Yes we could. In fact I do not like the idea of voltage layer dependent on opp layer itself. So here is my proposal. Maintain a variable in the main per vdd structure omap_vdd_info curr_volt which will get updated each time a voltage scale is attempted.

OK

Quoted 10 lines

Now the only issue is during boot up how does the voltage layer know what voltage each vdd should be put into ? A piece of code can be implemented in pm34xx.c/pm44xx.c init functions to read the clock rate associated with each vdd , call into the opp layer to get the corresponding voltage ( basically the sequence we do today everytime in voltage layer when the API to get nominal voltage is called) and call omap_voltage_scale_vdd with the corresponding voltage. This way we can fully decouple voltage laye from opp layer and make voltage init an early_initcall. We might still need a late_initcall to register debugfs entries though. What is your take on this ?

Not sure I fully follow this suggestions, but why not just wait until both OPP and voltage late init are fully done before allowing any voltage scaling?

Alternatively, I just did a quick experiment and the device_initcall in pm.c (that initializes the MPU, IVA/DSP and L3 devices, as well as does the OPP layer init) could be made a subsys_initcall, so that by the time SR + voltage are init'd (using device_initcall), OPP layer is fully initialized.

Kevin

#40 lore raw

Re: [PATCH 04/13] OMAP: Introduce API to return a device list associated with a voltage domain

In reply to Thara Gopinath
Quoted 10 lines · Thara Gopinath

This patch adds an API in the opp layer that
can be used by the voltage layer to get a list of all the scalable devices belonging to a particular voltage domain. This API is to be typically called only once by the voltage layer per voltage domain instance and the device list should be stored. This approach makes it easy during dvfs to scale all the devices associated with a voltage domain and then scale the voltage domain.

I don't think the OPP layer is the right place for this after all.

How about something like this in the voltage layer:

omap_voltage_add_device(struct voltagedomain *voltdm, struct device *dev)

During omap_device_build(), if the hwmod has a voltage domain, it calls this function to register it with the voltage layer.

This function then creates a list (internal to voltage layer) of all the devices in a voltage domain rather than having to query the OPP layer for it.

Kevin

Quoted 74 lines
---
 arch/arm/plat-omap/include/plat/opp.h |    9 +++++++++
 arch/arm/plat-omap/opp.c              |   28 ++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)
arch/arm/plat-omap/include/plat/opp.h +9 -0
index 0e580ed..a4c1669 100644
@@ -18,6 +18,7 @@
 #include <linux/cpufreq.h>
 
 #include <plat/common.h>
+#include <plat/voltage.h>
 
 /**
  * struct omap_opp_def - OMAP OPP Definition
@@ -86,6 +87,9 @@ int opp_disable(struct omap_opp *opp);
 
 void opp_init_cpufreq_table(struct device *dev,
 			    struct cpufreq_frequency_table **table);
+
+struct device **opp_init_voltage_params(struct voltagedomain *voltdm,
+					int *dev_count);
 #else
 static inline unsigned long opp_get_voltage(const struct omap_opp *opp)
 {
@@ -149,5 +153,10 @@ void opp_init_cpufreq_table(struct omap_opp *opps,
 {
 }
 
+static inline struct device **opp_init_voltage_params(
+			struct voltagedomain *voltdm, int *dev_count)
+{
+}
+
 #endif		/* CONFIG_PM */
 #endif		/* __ASM_ARM_OMAP_OPP_H */
arch/arm/plat-omap/opp.c +28 -0
index a3dea82..72dd62a 100644
@@ -502,3 +502,31 @@ void opp_init_cpufreq_table(struct device *dev,
 
 	*table = &freq_table[0];
 }
+
+struct device **opp_init_voltage_params(struct voltagedomain *voltdm,
+					int *dev_count)
+{
+	struct device_opp *dev_opp;
+	struct device **dev_list;
+	int count = 0, i = 0;
+
+	list_for_each_entry(dev_opp, &dev_opp_list, node) {
+		if (!dev_opp->oh->vdd_name)
+			continue;
+
+		if (!strcmp(dev_opp->oh->vdd_name, voltdm->name)) {
+			dev_opp->oh->voltdm = voltdm;
+			count++;
+		}
+	}
+
+	dev_list = kzalloc(sizeof(struct device *) * count, GFP_KERNEL);
+
+	list_for_each_entry(dev_opp, &dev_opp_list, node) {
+		if (dev_opp->oh->voltdm == voltdm)
+			dev_list[i++] = dev_opp->dev;
+	}
+
+	*dev_count = count;
+	return dev_list;
+}
#41 lore raw

RE: [PATCH 04/13] OMAP: Introduce API to return a device list associated with a voltage domain

Quoted 23 lines
Quoted 23 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Thursday, September 02, 2010 6:04 AM
To: Gopinath, Thara
Cc: [email protected]; [email protected]; Sripathy, Vishwanath; Sawant, Anand; Cousson, Benoit
Subject: Re: [PATCH 04/13] OMAP: Introduce API to return a device list associated with a voltage domain

Quoted 10 lines · Thara Gopinath

This patch adds an API in the opp layer that
can be used by the voltage layer to get a list of all the scalable devices belonging to a particular voltage domain. This API is to be typically called only once by the voltage layer per voltage domain instance and the device list should be stored. This approach makes it easy during dvfs to scale all the devices associated with a voltage domain and then scale the voltage domain.

Quoted 8 lines
Quoted 8 lines

I don't think the OPP layer is the right place for this after all.

How about something like this in the voltage layer:

omap_voltage_add_device(struct voltagedomain *voltdm, struct device *dev)

During omap_device_build(), if the hwmod has a voltage domain, it calls this function to register it with the voltage layer.

This mandates voltage layer to be initialized before the first omap_device_build has happened. I think that is going to be a very confusing sequencing. Also today voltage layer init happens later in the system.

Quoted 81 lines
Quoted 81 lines

This function then creates a list (internal to voltage layer) of all the devices in a voltage domain rather than having to query the OPP layer for it.

Kevin

Quoted 74 lines
---
 arch/arm/plat-omap/include/plat/opp.h |    9 +++++++++
 arch/arm/plat-omap/opp.c              |   28 ++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)
arch/arm/plat-omap/include/plat/opp.h +9 -0
index 0e580ed..a4c1669 100644
@@ -18,6 +18,7 @@
 #include <linux/cpufreq.h>
 
 #include <plat/common.h>
+#include <plat/voltage.h>
 
 /**
  * struct omap_opp_def - OMAP OPP Definition
@@ -86,6 +87,9 @@ int opp_disable(struct omap_opp *opp);
 
 void opp_init_cpufreq_table(struct device *dev,
 			    struct cpufreq_frequency_table **table);
+
+struct device **opp_init_voltage_params(struct voltagedomain *voltdm,
+					int *dev_count);
 #else
 static inline unsigned long opp_get_voltage(const struct omap_opp *opp)
 {
@@ -149,5 +153,10 @@ void opp_init_cpufreq_table(struct omap_opp *opps,
 {
 }
 
+static inline struct device **opp_init_voltage_params(
+			struct voltagedomain *voltdm, int *dev_count)
+{
+}
+
 #endif		/* CONFIG_PM */
 #endif		/* __ASM_ARM_OMAP_OPP_H */
arch/arm/plat-omap/opp.c +28 -0
index a3dea82..72dd62a 100644
@@ -502,3 +502,31 @@ void opp_init_cpufreq_table(struct device *dev,
 
 	*table = &freq_table[0];
 }
+
+struct device **opp_init_voltage_params(struct voltagedomain *voltdm,
+					int *dev_count)
+{
+	struct device_opp *dev_opp;
+	struct device **dev_list;
+	int count = 0, i = 0;
+
+	list_for_each_entry(dev_opp, &dev_opp_list, node) {
+		if (!dev_opp->oh->vdd_name)
+			continue;
+
+		if (!strcmp(dev_opp->oh->vdd_name, voltdm->name)) {
+			dev_opp->oh->voltdm = voltdm;
+			count++;
+		}
+	}
+
+	dev_list = kzalloc(sizeof(struct device *) * count, GFP_KERNEL);
+
+	list_for_each_entry(dev_opp, &dev_opp_list, node) {
+		if (dev_opp->oh->voltdm == voltdm)
+			dev_list[i++] = dev_opp->dev;
+	}
+
+	*dev_count = count;
+	return dev_list;
+}
#42 lore raw

Re: [PATCH 04/13] OMAP: Introduce API to return a device list associated with a voltage domain

Quoted 25 lines · Thara
Quoted 25 lines
Quoted 25 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Thursday, September 02, 2010 6:04 AM
To: Gopinath, Thara
Cc: [email protected]; [email protected]; Sripathy, Vishwanath; Sawant, Anand; Cousson, Benoit
Subject: Re: [PATCH 04/13] OMAP: Introduce API to return a device list associated with a voltage domain

Quoted 10 lines · Thara Gopinath

This patch adds an API in the opp layer that
can be used by the voltage layer to get a list of all the scalable devices belonging to a particular voltage domain. This API is to be typically called only once by the voltage layer per voltage domain instance and the device list should be stored. This approach makes it easy during dvfs to scale all the devices associated with a voltage domain and then scale the voltage domain.

I don't think the OPP layer is the right place for this after all.

How about something like this in the voltage layer:

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

omap_voltage_add_device(struct voltagedomain *voltdm, struct device *dev)

During omap_device_build(), if the hwmod has a voltage domain, it calls this function to register it with the voltage layer.

This mandates voltage layer to be initialized before the first omap_device_build has happened. I think that is going to be a very confusing sequencing. Also today voltage layer init happens later in the system.

If we split into an early and late init, that would help here too.

Kevin

#43 lore raw

PATCH 5/13 OMAP: Introduce device specific set rate and get rate in device opp structures.

In reply to Thara Gopinath

This patch extends the device opp structure to contain pointers to scale the operating rate of the
device and to retrieve the operating rate of the device. This patch also adds the three new APIs in the opp layer namely opp_set_rate that can be called to set a new operating rate for a device, opp_get_rate that can be called to retrieve the operating frequency for a device and opp_populate_rate_fns to populte the device specific set_rate and get_rate API's. The opp_set_rate and opp_get_rate does some routine error checks and finally calls into the device specific set_rate and get_rate APIs populated through opp_populate_rate_fns.

---
 arch/arm/plat-omap/include/plat/opp.h |   28 +++++++++-
 arch/arm/plat-omap/opp.c              |  103 +++++++++++++++++++++++++++++++++
 2 files changed, 130 insertions(+), 1 deletions(-)
arch/arm/plat-omap/include/plat/opp.h +27 -1
index a4c1669..604914d 100644
@@ -16,6 +16,7 @@
 
 #include <linux/err.h>
 #include <linux/cpufreq.h>
+#include <linux/clk.h>
 
 #include <plat/common.h>
 #include <plat/voltage.h>
@@ -52,7 +53,7 @@ struct omap_opp_def {
  * To point at the end of a terminator of a list of OPPs,
  * use OMAP_OPP_DEF(NULL, 0, 0, 0)
  */
-#define OMAP_OPP_DEF(_hwmod_name, _enabled, _freq, _uv)	\
+#define OMAP_OPP_DEF(_hwmod_name, _enabled, _freq, _uv) \
 {						\
 	.hwmod_name	= _hwmod_name,		\
 	.enabled	= _enabled,		\
@@ -79,6 +80,14 @@ struct omap_opp *opp_find_freq_ceil(struct device *dev, unsigned long *freq);
 
 struct omap_opp *opp_find_voltage(struct device *dev, unsigned long volt);
 
+int opp_set_rate(struct device *dev, unsigned long freq);
+
+unsigned long opp_get_rate(struct device *dev);
+
+void opp_populate_rate_fns(struct device *dev,
+		int (*set_rate)(struct device *dev, unsigned long rate),
+		unsigned long (*get_rate) (struct device *dev));
+
 int opp_add(const struct omap_opp_def *opp_def);
 
 int opp_enable(struct omap_opp *opp);
@@ -131,6 +140,23 @@ static inline struct omap_opp *opp_find_voltage(struct device *dev,
 	return ERR_PTR(-EINVAL);
 }
 
+static inline int opp_set_rate(struct device *dev, unsigned long freq)
+{
+	return -EINVAL;
+}
+
+static inline unsigned long opp_get_rate(struct device *dev)
+{
+	return 0;
+}
+
+static inline void opp_populate_rate_fns(struct device *dev,
+		int (*set_rate)(struct device *dev, unsigned long rate)
+		unsigned long (*get_rate) (struct device *dev))
+{
+	return;
+}
+
 static inline struct omap_opp *opp_add(struct omap_opp *oppl,
 				       const struct omap_opp_def *opp_def)
 {
arch/arm/plat-omap/opp.c +103 -0

121 lines not on this page · raw message

Signature · 1 line
1.7.1.GIT
#44 lore raw

Re: [PATCH 05/13] OMAP: Introduce device specific set rate and get rate in device opp structures.

Quoted 12 lines · Thara Gopinath

This patch extends the device opp structure to contain pointers to scale the operating rate of the
device and to retrieve the operating rate of the device. This patch also adds the three new APIs in the opp layer namely opp_set_rate that can be called to set a new operating rate for a device, opp_get_rate that can be called to retrieve the operating frequency for a device and opp_populate_rate_fns to populte the device specific set_rate and get_rate API's. The opp_set_rate and opp_get_rate does some routine error checks and finally calls into the device specific set_rate and get_rate APIs populated through opp_populate_rate_fns.

Quoted 1 line

As I think about this more, I'm not sure the OPP layer is the right layer for the get/set rate functions. The OPP layer is currently just the data store for OPP data. To me, these set/get functions are better associated directly with an omap_device instead of an OPP.

For instance, the new OPP APIs are a bit confusing in terms of OPPs. e.g: opp_get_rate(). What is the "rate" of an OPP, and what's the difference with opp_get_freq()?

What's really happening is the rate is being changed for a device, and the need for specific hooks are at the device level, not the OPP level. For example, this current approach would not scale if you needed multiple devices in the same domain that each needed custom set_rate/get_rate hooks.

So instead, what about adding custom hooks at the omap_device level? They could be registered at omap_device_build() time in the device specific code.

Kevin

#45 lore raw

RE: [PATCH 05/13] OMAP: Introduce device specific set rate and get rate in device opp structures.

Quoted 41 lines
Quoted 41 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Friday, September 03, 2010 5:12 AM
To: Gopinath, Thara
Cc: [email protected]; [email protected]; Sripathy, Vishwanath; Sawant, Anand; Cousson, Benoit
Subject: Re: [PATCH 05/13] OMAP: Introduce device specific set rate and get rate in device opp structures.

Quoted 12 lines · Thara Gopinath

This patch extends the device opp structure to contain pointers to scale the operating rate of the
device and to retrieve the operating rate of the device. This patch also adds the three new APIs in the opp layer namely opp_set_rate that can be called to set a new operating rate for a device, opp_get_rate that can be called to retrieve the operating frequency for a device and opp_populate_rate_fns to populte the device specific set_rate and get_rate API's. The opp_set_rate and opp_get_rate does some routine error checks and finally calls into the device specific set_rate and get_rate APIs populated through opp_populate_rate_fns.

Quoted 1 line

As I think about this more, I'm not sure the OPP layer is the right layer for the get/set rate functions. The OPP layer is currently just the data store for OPP data. To me, these set/get functions are better associated directly with an omap_device instead of an OPP.

For instance, the new OPP APIs are a bit confusing in terms of OPPs. e.g: opp_get_rate(). What is the "rate" of an OPP, and what's the difference with opp_get_freq()?

What's really happening is the rate is being changed for a device, and the need for specific hooks are at the device level, not the OPP level. For example, this current approach would not scale if you needed multiple devices in the same domain that each needed custom set_rate/get_rate hooks.

Quoted 3 lines
Quoted 3 lines

So instead, what about adding custom hooks at the omap_device level? They could be registered at omap_device_build() time in the device specific code.

This is exactly what I had in my mind when I started implementing this.
But then Paul said hwmod or omap_device is not the place to keep it. Also I do not want the set rate get rate APIs for devices that require changes dividers in the PRCM clock module to be spread out in the system. Makes it very very difficult to debug. If we agree to add the set_rate and get_rate in the omap_device structure, I would like to have one more API in the omap_device layer to register these APIs device wise. Thus we can keep these set rate and get rate APIs in one single file.

Also if we move these hooks to omap_device struct we will need to rename the current omap_device_set_rate (the main API) to omap_device_scale and introduce a new omap_device_set_rate which just finds out the omap device from the passed dev pointer and does a od->set_rate. Similarly for get rate also.

Regards
Thara

#46 lore raw

Re: [PATCH 05/13] OMAP: Introduce device specific set rate and get rate in device opp structures.

Quoted 39 lines · Thara
Quoted 39 lines
Quoted 39 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Friday, September 03, 2010 5:12 AM
To: Gopinath, Thara
Cc: [email protected]; [email protected]; Sripathy, Vishwanath; Sawant, Anand; Cousson, Benoit
Subject: Re: [PATCH 05/13] OMAP: Introduce device specific set rate and get rate in device opp structures.

Quoted 12 lines · Thara Gopinath

This patch extends the device opp structure to contain pointers to scale the operating rate of the
device and to retrieve the operating rate of the device. This patch also adds the three new APIs in the opp layer namely opp_set_rate that can be called to set a new operating rate for a device, opp_get_rate that can be called to retrieve the operating frequency for a device and opp_populate_rate_fns to populte the device specific set_rate and get_rate API's. The opp_set_rate and opp_get_rate does some routine error checks and finally calls into the device specific set_rate and get_rate APIs populated through opp_populate_rate_fns.

Quoted 1 line

As I think about this more, I'm not sure the OPP layer is the right layer for the get/set rate functions. The OPP layer is currently just the data store for OPP data. To me, these set/get functions are better associated directly with an omap_device instead of an OPP.

For instance, the new OPP APIs are a bit confusing in terms of OPPs. e.g: opp_get_rate(). What is the "rate" of an OPP, and what's the difference with opp_get_freq()?

What's really happening is the rate is being changed for a device, and the need for specific hooks are at the device level, not the OPP level. For example, this current approach would not scale if you needed multiple devices in the same domain that each needed custom set_rate/get_rate hooks.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

So instead, what about adding custom hooks at the omap_device level? They could be registered at omap_device_build() time in the device specific code.

This is exactly what I had in my mind when I started implementing this. But then Paul said hwmod or omap_device is not the place to keep it.

IIRC, Paul's concern was that *hwmod* was not the right place for this (and I agree.) However, I think omap_device is the right place for this.

Paul?

Quoted 7 lines

Also I do not want the set rate get rate APIs for devices that require changes dividers in the PRCM clock module to be spread out in the system. Makes it very very difficult to debug. If we agree to add the set_rate and get_rate in the omap_device structure, I would like to have one more API in the omap_device layer to register these APIs device wise. Thus we can keep these set rate and get rate APIs in one single file.

Agreed. And those functions should be in the respective device-specific file, where the omap_device_build() etc are done for that device.

Quoted 5 lines

Also if we move these hooks to omap_device struct we will need to rename the current omap_device_set_rate (the main API) to omap_device_scale and introduce a new omap_device_set_rate which just finds out the omap device from the passed dev pointer and does a od->set_rate. Similarly for get rate also.

Yes, that's what I was thinking.

Kevin

#47 lore raw

RE: [PATCH 05/13] OMAP: Introduce device specific set rate and get rate in device opp structures.

Quoted 73 lines
Quoted 73 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Thursday, September 16, 2010 8:58 PM
To: Gopinath, Thara; Paul Walmsley
Cc: [email protected]; Sripathy, Vishwanath; Sawant, Anand; Cousson, Benoit
Subject: Re: [PATCH 05/13] OMAP: Introduce device specific set rate and get rate in device opp structures.

Quoted 5 lines · Thara
Quoted 5 lines
Quoted 5 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Friday, September 03, 2010 5:12 AM
To: Gopinath, Thara
Cc: [email protected]; [email protected]; Sripathy, Vishwanath; Sawant, Anand; Cousson,

Benoit

Quoted 34 lines
Quoted 34 lines
Quoted 34 lines

Subject: Re: [PATCH 05/13] OMAP: Introduce device specific set rate and get rate in device opp structures.

Quoted 12 lines · Thara Gopinath

This patch extends the device opp structure to contain pointers to scale the operating rate of the
device and to retrieve the operating rate of the device. This patch also adds the three new APIs in the opp layer namely opp_set_rate that can be called to set a new operating rate for a device, opp_get_rate that can be called to retrieve the operating frequency for a device and opp_populate_rate_fns to populte the device specific set_rate and get_rate API's. The opp_set_rate and opp_get_rate does some routine error checks and finally calls into the device specific set_rate and get_rate APIs populated through opp_populate_rate_fns.

Quoted 1 line

As I think about this more, I'm not sure the OPP layer is the right layer for the get/set rate functions. The OPP layer is currently just the data store for OPP data. To me, these set/get functions are better associated directly with an omap_device instead of an OPP.

For instance, the new OPP APIs are a bit confusing in terms of OPPs. e.g: opp_get_rate(). What is the "rate" of an OPP, and what's the difference with opp_get_freq()?

What's really happening is the rate is being changed for a device, and the need for specific hooks are at the device level, not the OPP level. For example, this current approach would not scale if you needed multiple devices in the same domain that each needed custom set_rate/get_rate hooks.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

So instead, what about adding custom hooks at the omap_device level? They could be registered at omap_device_build() time in the device specific code.

This is exactly what I had in my mind when I started implementing this. But then Paul said hwmod or omap_device is not the place to keep it.

IIRC, Paul's concern was that *hwmod* was not the right place for this (and I agree.) However, I think omap_device is the right place for this.

Paul?

Quoted 7 lines

Also I do not want the set rate get rate APIs for devices that require changes dividers in the PRCM clock module to be spread out in the system. Makes it very very difficult to debug. If we agree to add the set_rate and get_rate in the omap_device structure, I would like to have one more API in the omap_device layer to register these APIs device wise. Thus we can keep these set rate and get rate APIs in one single file.

Quoted 3 lines
Quoted 3 lines

Agreed. And those functions should be in the respective device-specific file, where the omap_device_build() etc are done for that device.

Hello Kevin,

I basically agree with all your other suggestions except this. I do not think device files are the correct place for this. For starters definitely mpu, l3 and iva devices are not built from any device file. I do not like the idea of device set rate APIs spread across different files.
What I am proposing is like we have opp_populate_rate_fns(which I have introduced) we should have something like omap_device_populate_rate_fns. This can be then called from one file to register the set_rate and get_rate APIs for all the relevant devices for a Soc. This will be done through an init function. And the device specific set_rate and get_rate can be implemented in this file. I am not sure which is this file at this point of time. Maybe for OMAP3 opp3xxx_data.c or pm34xx.c. What do you think about this?

Regards
Thara

Quoted 10 lines
Quoted 10 lines
Quoted 6 lines

Also if we move these hooks to omap_device struct we will need to rename the current omap_device_set_rate (the main API) to omap_device_scale and introduce a new omap_device_set_rate which just finds out the omap device from the passed dev pointer and does a od->set_rate. Similarly for get rate also.

Yes, that's what I was thinking.

Kevin

#48 lore raw

Re: [PATCH 05/13] OMAP: Introduce device specific set rate and get rate in device opp structures.

Hi Thara,

Quoted 65 lines · Thara
Quoted 61 lines
Quoted 61 lines

From: Kevin Hilman [mailto:[email protected]]
Sent: Thursday, September 16, 2010 8:58 PM

Quoted 34 lines · Thara
Quoted 34 lines
Quoted 34 lines

From: Kevin Hilman [mailto:[email protected]]
Sent: Friday, September 03, 2010 5:12 AM

Quoted 12 lines · Thara Gopinath

This patch extends the device opp structure to contain pointers to scale the operating rate of the
device and to retrieve the operating rate of the device. This patch also adds the three new APIs in the opp layer namely opp_set_rate that can be called to set a new operating rate for a device, opp_get_rate that can be called to retrieve the operating frequency for a device and opp_populate_rate_fns to populte the device specific set_rate and get_rate API's. The opp_set_rate and opp_get_rate does some routine error checks and finally calls into the device specific set_rate and get_rate APIs populated through opp_populate_rate_fns.

Quoted 1 line

As I think about this more, I'm not sure the OPP layer is the right layer for the get/set rate functions. The OPP layer is currently just the data store for OPP data. To me, these set/get functions are better associated directly with an omap_device instead of an OPP.

For instance, the new OPP APIs are a bit confusing in terms of OPPs. e.g: opp_get_rate(). What is the "rate" of an OPP, and what's the difference with opp_get_freq()?

What's really happening is the rate is being changed for a device, and the need for specific hooks are at the device level, not the OPP level. For example, this current approach would not scale if you needed multiple devices in the same domain that each needed custom set_rate/get_rate hooks.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

So instead, what about adding custom hooks at the omap_device level? They could be registered at omap_device_build() time in the device specific code.

This is exactly what I had in my mind when I started implementing this. But then Paul said hwmod or omap_device is not the place to keep it.

IIRC, Paul's concern was that *hwmod* was not the right place for this (and I agree.) However, I think omap_device is the right place for this.

Paul?

Quoted 7 lines

Also I do not want the set rate get rate APIs for devices that require changes dividers in the PRCM clock module to be spread out in the system. Makes it very very difficult to debug. If we agree to add the set_rate and get_rate in the omap_device structure, I would like to have one more API in the omap_device layer to register these APIs device wise. Thus we can keep these set rate and get rate APIs in one single file.

Quoted 3 lines
Quoted 3 lines

Agreed. And those functions should be in the respective device-specific file, where the omap_device_build() etc are done for that device.

Quoted 6 lines

Hello Kevin,

I basically agree with all your other suggestions except this. I do not think device files are the correct place for this. For starters definitely mpu, l3 and iva devices are not built from any device file. I do not like the idea of device set rate APIs spread across different files.

I don't not understand the reason?
If we need to add specific device function for mpu, l3, or iva, we can easily add a file to contain that.
BTW, thanks to work done by Santosh and Felipe we will probably soon introduce a l3 driver that will allow to handle interconnect errors. We will thus have a real device for l3 as well.

A device set_rate is clearly device specific. If a device will have to play with its own internal dividers along with PRCM dividers, that code still belong to the device.

I do not see the need nor the advantage to centralize that? You will end-up with a huge file that every driver owners will have to hack in order to add set_rate support for their device.

At device build time, IP with set_rate support will just add non-null parameters to the omap_device_build(), et voila.

For the debug point of view, you can just add a new sysfs entry for scalable devices that will allow you to track scalable device vs regular ones.

Regards,
Benoit

Quoted 21 lines

What I am proposing is like we have opp_populate_rate_fns(which I have introduced) we should have something like omap_device_populate_rate_fns. This can be then called from one file to register the set_rate and get_rate APIs for all the relevant devices for a Soc. This will be done through an init function. And the device specific set_rate and get_rate can be implemented in this file. I am not sure which is this file at this point of time. Maybe for OMAP3 opp3xxx_data.c or pm34xx.c. What do you think about this?

Regards
Thara

Quoted 10 lines
Quoted 10 lines
Quoted 6 lines

Also if we move these hooks to omap_device struct we will need to rename the current omap_device_set_rate (the main API) to omap_device_scale and introduce a new omap_device_set_rate which just finds out the omap device from the passed dev pointer and does a od->set_rate. Similarly for get rate also.

Yes, that's what I was thinking.

Kevin

#49 lore raw

Re: [PATCH 05/13] OMAP: Introduce device specific set rate and get rate in device opp structures.

Quoted 90 lines · Benoit

Hi Thara,

Quoted 65 lines · Thara
Quoted 61 lines
Quoted 61 lines

From: Kevin Hilman [mailto:[email protected]]
Sent: Thursday, September 16, 2010 8:58 PM

Quoted 34 lines · Thara
Quoted 34 lines
Quoted 34 lines

From: Kevin Hilman [mailto:[email protected]]
Sent: Friday, September 03, 2010 5:12 AM

Quoted 12 lines · Thara Gopinath

This patch extends the device opp structure to contain pointers to scale the operating rate of the
device and to retrieve the operating rate of the device. This patch also adds the three new APIs in the opp layer namely opp_set_rate that can be called to set a new operating rate for a device, opp_get_rate that can be called to retrieve the operating frequency for a device and opp_populate_rate_fns to populte the device specific set_rate and get_rate API's. The opp_set_rate and opp_get_rate does some routine error checks and finally calls into the device specific set_rate and get_rate APIs populated through opp_populate_rate_fns.

Quoted 1 line

As I think about this more, I'm not sure the OPP layer is the right layer for the get/set rate functions. The OPP layer is currently just the data store for OPP data. To me, these set/get functions are better associated directly with an omap_device instead of an OPP.

For instance, the new OPP APIs are a bit confusing in terms of OPPs. e.g: opp_get_rate(). What is the "rate" of an OPP, and what's the difference with opp_get_freq()?

What's really happening is the rate is being changed for a device, and the need for specific hooks are at the device level, not the OPP level. For example, this current approach would not scale if you needed multiple devices in the same domain that each needed custom set_rate/get_rate hooks.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

So instead, what about adding custom hooks at the omap_device level? They could be registered at omap_device_build() time in the device specific code.

This is exactly what I had in my mind when I started implementing this. But then Paul said hwmod or omap_device is not the place to keep it.

IIRC, Paul's concern was that *hwmod* was not the right place for this (and I agree.) However, I think omap_device is the right place for this.

Paul?

Quoted 7 lines

Also I do not want the set rate get rate APIs for devices that require changes dividers in the PRCM clock module to be spread out in the system. Makes it very very difficult to debug. If we agree to add the set_rate and get_rate in the omap_device structure, I would like to have one more API in the omap_device layer to register these APIs device wise. Thus we can keep these set rate and get rate APIs in one single file.

Quoted 3 lines
Quoted 3 lines

Agreed. And those functions should be in the respective device-specific file, where the omap_device_build() etc are done for that device.

Quoted 6 lines

Hello Kevin,

I basically agree with all your other suggestions except this. I do not think device files are the correct place for this. For starters definitely mpu, l3 and iva devices are not built from any device file. I do not like the idea of device set rate APIs spread across different files.

I don't not understand the reason?
If we need to add specific device function for mpu, l3, or iva, we can easily add a file to contain that.
BTW, thanks to work done by Santosh and Felipe we will probably soon introduce a l3 driver that will allow to handle interconnect errors. We will thus have a real device for l3 as well.

A device set_rate is clearly device specific. If a device will have to play with its own internal dividers along with PRCM dividers, that code still belong to the device.

I do not see the need nor the advantage to centralize that? You will end-up with a huge file that every driver owners will have to hack in order to add set_rate support for their device.

Quoted 6 lines

At device build time, IP with set_rate support will just add non-null parameters to the omap_device_build(), et voila.

For the debug point of view, you can just add a new sysfs entry for scalable devices that will allow you to track scalable device vs regular ones.

I agree with Benoit.

For MPU, IVA/DSP, L3, they are currently done in pm.c because they have
not device init or device file associate with them. For those, the
new rate functions belong there, since that' where the omap_device_build is done.

For all others, they should stay in device specific init.

Kevin

Quoted 21 lines
Quoted 21 lines

What I am proposing is like we have opp_populate_rate_fns(which I have introduced) we should have something like omap_device_populate_rate_fns. This can be then called from one file to register the set_rate and get_rate APIs for all the relevant devices for a Soc. This will be done through an init function. And the device specific set_rate and get_rate can be implemented in this file. I am not sure which is this file at this point of time. Maybe for OMAP3 opp3xxx_data.c or pm34xx.c. What do you think about this?

Regards
Thara

Quoted 10 lines
Quoted 10 lines
Quoted 6 lines

Also if we move these hooks to omap_device struct we will need to rename the current omap_device_set_rate (the main API) to omap_device_scale and introduce a new omap_device_set_rate which just finds out the omap device from the passed dev pointer and does a od->set_rate. Similarly for get rate also.

Yes, that's what I was thinking.

Kevin

#50 lore raw

RE: [PATCH 05/13] OMAP: Introduce device specific set rate and get rate in device opp structures.

In reply to Cousson, Benoit
Quoted 104 lines
Quoted 104 lines

-----Original Message-----
From: Cousson, Benoit
Sent: Saturday, September 18, 2010 3:43 PM
To: Gopinath, Thara
Cc: Kevin Hilman; Paul Walmsley; [email protected]; Sripathy, Vishwanath; Sawant, Anand
Subject: Re: [PATCH 05/13] OMAP: Introduce device specific set rate and get rate in device opp structures.

Hi Thara,

Quoted 30 lines · Thara
Quoted 30 lines
Quoted 30 lines

From: Kevin Hilman [mailto:[email protected]]
Sent: Thursday, September 16, 2010 8:58 PM

Quoted 24 lines · Thara
Quoted 24 lines
Quoted 24 lines

From: Kevin Hilman [mailto:[email protected]]
Sent: Friday, September 03, 2010 5:12 AM

Quoted 12 lines · Thara Gopinath

This patch extends the device opp structure to contain pointers to scale the operating rate of the
device and to retrieve the operating rate of the device. This patch also adds the three new APIs in the opp layer namely opp_set_rate that can be called to set a new operating rate for a device, opp_get_rate that can be called to retrieve the operating frequency for a device and opp_populate_rate_fns to populte the device specific set_rate and get_rate API's. The opp_set_rate and opp_get_rate does some routine error checks and finally calls into the device specific set_rate and get_rate APIs populated through opp_populate_rate_fns.

Quoted 1 line

As I think about this more, I'm not sure the OPP layer is the right layer for the get/set rate functions. The OPP layer is currently just the data store for OPP data. To me, these set/get functions are better associated directly with an omap_device instead of an OPP.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

For instance, the new OPP APIs are a bit confusing in terms of OPPs. e.g: opp_get_rate(). What is the "rate" of an OPP, and what's the difference with opp_get_freq()?

What's really happening is the rate is being changed for a device, and the need for specific hooks are at the device level, not the OPP

level.

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 10 lines
Quoted 7 lines
Quoted 7 lines

For example, this current approach would not scale if you needed multiple devices in the same domain that each needed custom set_rate/get_rate hooks.

So instead, what about adding custom hooks at the omap_device level? They could be registered at omap_device_build() time in the device specific code.

This is exactly what I had in my mind when I started implementing this. But then Paul said hwmod or omap_device is not the place to keep it.

IIRC, Paul's concern was that *hwmod* was not the right place for this (and I agree.) However, I think omap_device is the right place for this.

Paul?

Quoted 7 lines

Also I do not want the set rate get rate APIs for devices that require changes dividers in the PRCM clock module to be spread out in the system. Makes it very very difficult to debug. If we agree to add the set_rate and get_rate in the omap_device structure, I would like to have one more API in the omap_device layer to register these APIs device wise. Thus we can keep these set rate and get rate APIs in one single file.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Agreed. And those functions should be in the respective device-specific file, where the omap_device_build() etc are done for that device.

Hello Kevin,

I basically agree with all your other suggestions except this. I do not think device files are the correct place for this. For starters definitely

mpu,

Quoted 1 line

l3 and iva devices are not built from any device file. I do not like the

idea

Quoted 1 line

of device set rate APIs spread across different files.

I don't not understand the reason?
If we need to add specific device function for mpu, l3, or iva, we can easily add a file to contain that.
BTW, thanks to work done by Santosh and Felipe we will probably soon introduce a l3 driver that will allow to handle interconnect errors. We will thus have a real device for l3 as well.

A device set_rate is clearly device specific. If a device will have to play with its own internal dividers along with PRCM dividers, that code still belong to the device.

I do not see the need nor the advantage to centralize that? You will end-up with a huge file that every driver owners will have to hack in order to add set_rate support for their device.

Quoted 6 lines
Quoted 6 lines

At device build time, IP with set_rate support will just add non-null parameters to the omap_device_build(), et voila.

For the debug point of view, you can just add a new sysfs entry for scalable devices that will allow you to track scalable device vs regular ones.

Hello Benoit/Kevin,

Most of the devices need not scale any internal dividers. For devices that
need to scale internal dividers, I agree that the set_rate and get_rate should come from the devices file. But for other devices that involve only PRCM dividers, I do not think they should be bothered with implementing these APIs and maintaining them.

Regards
Thara

#51 lore raw

Re: [PATCH 05/13] OMAP: Introduce device specific set rate and get rate in device opp structures.

Hi Thara,

Quoted 107 lines · Thara
Quoted 107 lines
Quoted 107 lines

-----Original Message-----
From: Cousson, Benoit
Sent: Saturday, September 18, 2010 3:43 PM
To: Gopinath, Thara
Cc: Kevin Hilman; Paul Walmsley; [email protected]; Sripathy, Vishwanath; Sawant, Anand
Subject: Re: [PATCH 05/13] OMAP: Introduce device specific set rate and get rate in device opp structures.

Hi Thara,

Quoted 30 lines · Thara
Quoted 30 lines
Quoted 30 lines

From: Kevin Hilman [mailto:[email protected]]
Sent: Thursday, September 16, 2010 8:58 PM

Quoted 24 lines · Thara
Quoted 24 lines
Quoted 24 lines

From: Kevin Hilman [mailto:[email protected]]
Sent: Friday, September 03, 2010 5:12 AM

Quoted 12 lines · Thara Gopinath

This patch extends the device opp structure to contain pointers to scale the operating rate of the
device and to retrieve the operating rate of the device. This patch also adds the three new APIs in the opp layer namely opp_set_rate that can be called to set a new operating rate for a device, opp_get_rate that can be called to retrieve the operating frequency for a device and opp_populate_rate_fns to populte the device specific set_rate and get_rate API's. The opp_set_rate and opp_get_rate does some routine error checks and finally calls into the device specific set_rate and get_rate APIs populated through opp_populate_rate_fns.

Quoted 1 line

As I think about this more, I'm not sure the OPP layer is the right layer for the get/set rate functions. The OPP layer is currently just the data store for OPP data. To me, these set/get functions are better associated directly with an omap_device instead of an OPP.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

For instance, the new OPP APIs are a bit confusing in terms of OPPs. e.g: opp_get_rate(). What is the "rate" of an OPP, and what's the difference with opp_get_freq()?

What's really happening is the rate is being changed for a device, and the need for specific hooks are at the device level, not the OPP

level.

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 10 lines
Quoted 7 lines
Quoted 7 lines

For example, this current approach would not scale if you needed multiple devices in the same domain that each needed custom set_rate/get_rate hooks.

So instead, what about adding custom hooks at the omap_device level? They could be registered at omap_device_build() time in the device specific code.

This is exactly what I had in my mind when I started implementing this. But then Paul said hwmod or omap_device is not the place to keep it.

IIRC, Paul's concern was that *hwmod* was not the right place for this (and I agree.) However, I think omap_device is the right place for this.

Paul?

Quoted 7 lines

Also I do not want the set rate get rate APIs for devices that require changes dividers in the PRCM clock module to be spread out in the system. Makes it very very difficult to debug. If we agree to add the set_rate and get_rate in the omap_device structure, I would like to have one more API in the omap_device layer to register these APIs device wise. Thus we can keep these set rate and get rate APIs in one single file.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Agreed. And those functions should be in the respective device-specific file, where the omap_device_build() etc are done for that device.

Hello Kevin,

I basically agree with all your other suggestions except this. I do not think device files are the correct place for this. For starters definitely

mpu,

Quoted 1 line

l3 and iva devices are not built from any device file. I do not like the

idea

Quoted 1 line

of device set rate APIs spread across different files.

I don't not understand the reason?
If we need to add specific device function for mpu, l3, or iva, we can easily add a file to contain that.
BTW, thanks to work done by Santosh and Felipe we will probably soon introduce a l3 driver that will allow to handle interconnect errors. We will thus have a real device for l3 as well.

A device set_rate is clearly device specific. If a device will have to play with its own internal dividers along with PRCM dividers, that code still belong to the device.

I do not see the need nor the advantage to centralize that? You will end-up with a huge file that every driver owners will have to hack in order to add set_rate support for their device.

At device build time, IP with set_rate support will just add non-null parameters to the omap_device_build(), et voila.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

For the debug point of view, you can just add a new sysfs entry for scalable devices that will allow you to track scalable device vs regular ones.

Hello Benoit/Kevin,

Most of the devices need not scale any internal dividers. For devices that
need to scale internal dividers, I agree that the set_rate and get_rate should come from the devices file. But for other devices that involve only PRCM dividers, I do not think they should be bothered with implementing these APIs and maintaining them.

But why? For dividers under PRCM control, we do have clock nodes to control them, so device can still use them.

I'm still missing your point about centralizing that.

Benoit

#52 lore raw

PATCH 6/13 OMAP: Voltage layer changes to support DVFS.

In reply to Thara Gopinath

This patch introduces a list of scalable devices associated with a particular voltage domain instance. This list is obtained from the opp layer during init. This patch also introduces an API to take in the voltage domain and the new voltage as parameter and to scale all the scalable devices associated with the the voltage domain to the rate corresponding to the new voltage and scale the voltage domain to the new voltage.

---
 arch/arm/mach-omap2/voltage.c             |   71 +++++++++++++++++++++++++++++
 arch/arm/plat-omap/include/plat/voltage.h |    2 +
 2 files changed, 73 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/voltage.c +71 -0
index 4624250..3332123 100644
@@ -141,6 +141,8 @@ struct omap_vdd_info{
 	struct plist_head user_list;
 	struct mutex scaling_mutex;
 	int volt_data_count;
+	struct device **dev_list;
+	int dev_count;
 	unsigned long nominal_volt;
 	u8 cmdval_reg;
 	u8 vdd_sr_reg;
@@ -820,6 +822,9 @@ static void __init vdd_data_configure(struct omap_vdd_info *vdd)
 	/* Init the DVFS mutex */
 	mutex_init(&vdd->scaling_mutex);
 
+	/* Get the devices associated with this VDD */
+	vdd->dev_list = opp_init_voltage_params(&vdd->voltdm, &vdd->dev_count);
+
 #ifdef CONFIG_PM_DEBUG
 	strcpy(name, "vdd_");
 	strcat(name, vdd->voltdm.name);
@@ -1578,6 +1583,72 @@ struct voltagedomain *omap_voltage_domain_get(char *name)
 }
 
 /**
+ * omap_voltage_scale : API to scale the devices associated with a
+ *			voltage domain vdd voltage.
+ * @volt_domain : the voltage domain to be scaled
+ * @volt : the new voltage for the voltage domain
+ *
+ * This API runs through the list of devices associated with the
+ * voltage domain and scales the device rates to those corresponding
+ * to the new voltage of the voltage domain. This API also scales
+ * the voltage domain voltage to the new value. Returns 0 on success
+ * else the error value.
+ */
+int omap_voltage_scale(struct voltagedomain *voltdm, unsigned long volt)
+{
+	unsigned long curr_volt;
+	int is_volt_scaled = 0, i;
+	struct omap_vdd_info *vdd;
+
+	if (!voltdm || IS_ERR(voltdm)) {
+		pr_warning("%s: VDD specified does not exist!\n", __func__);
+		return -EINVAL;
+	}
+
+	vdd = container_of(voltdm, struct omap_vdd_info, voltdm);
+
+	mutex_lock(&vdd->scaling_mutex);
+
+	curr_volt = omap_voltage_get_nom_volt(voltdm);
+
+	if (curr_volt == volt) {
+		is_volt_scaled = 1;
+	} else if (curr_volt < volt) {
+		omap_voltage_scale_vdd(voltdm, volt);
+		is_volt_scaled = 1;
+	}
+
+	for (i = 0; i < vdd->dev_count; i++) {
+		struct omap_opp *opp;
+		unsigned long freq;
+
+		opp = opp_find_voltage(vdd->dev_list[i], volt);
+		if (IS_ERR(opp)) {
+			dev_err(vdd->dev_list[i], "%s: Unable to find OPP for"
+				"volt%ld\n", __func__, volt);
+			continue;
+		}
+
+		freq = opp_get_freq(opp);
+
+		if (freq == opp_get_rate(vdd->dev_list[i])) {
+			dev_warn(vdd->dev_list[i], "%s: Already at the"
+				"requested rate %ld\n", __func__, freq);
+			continue;
+		}
+
+		opp_set_rate(vdd->dev_list[i], freq);
+	}
+
+	if (!is_volt_scaled)
+		omap_voltage_scale_vdd(voltdm, volt);
+
+	mutex_unlock(&vdd->scaling_mutex);
+
+	return 0;
+}
+
+/**
  * omap_voltage_init : Volatage init API which does VP and VC init.
  */
 static int __init omap_voltage_init(void)
arch/arm/plat-omap/include/plat/voltage.h +2 -0
index fffd086..4f8342a 100644
@@ -146,6 +146,8 @@ void omap_voltage_register_pmic(struct omap_volt_pmic_info *pmic_info);
 unsigned long omap_voltage_get_nom_volt(struct voltagedomain *voltdm);
 int omap_voltage_add_userreq(struct voltagedomain *voltdm, struct device *dev,
 		unsigned long *volt);
+int omap_voltage_scale(struct voltagedomain *voltdm, unsigned long volt);
+
 #ifdef CONFIG_PM
 void omap_voltage_init_vc(struct omap_volt_vc_data *setup_vc);
 void omap_change_voltscale_method(int voltscale_method);
Signature · 1 line
1.7.1.GIT
#53 lore raw

PATCH 7/13 OMAP: Introduce dependent voltage domain support.

In reply to Thara Gopinath

There could be dependencies between various voltage domains for maintaining system performance or hardware limitation reasons like VDD<X> should be at voltage v1 when VDD<Y> is at voltage v2. This patch introduce dependent vdd information structures in the voltage layer which can be used to populate these dependencies for a voltage domain. This patch also adds support to scale the dependent vdd and the scalable devices belonging to it during the scaling of a main vdd through omap_voltage_scale.

---
 arch/arm/mach-omap2/voltage.c |  122 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 122 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/voltage.c +122 -0
index 3332123..1a46eb0 100644
@@ -98,6 +98,36 @@ struct vp_reg_val {
 };
 
 /**
+ * omap_vdd_dep_volt - Table containing the parent vdd voltage and the
+ *			dependent vdd voltage corresponding to it.
+ *
+ * @main_vdd_volt	: The main vdd voltage
+ * @dep_vdd_volt	: The voltage at which the dependent vdd should be
+ *			  when the main vdd is at <main_vdd_volt> voltage
+ */
+struct omap_vdd_dep_volt {
+	u32 main_vdd_volt;
+	u32 dep_vdd_volt;
+};
+
+/**
+ * omap_vdd_dep_info - Dependent vdd info
+ *
+ * @name		: Dependent vdd name
+ * @voltdm		: Dependent vdd pointer
+ * @dep_table		: Table containing the dependent vdd voltage
+ *			  corresponding to every main vdd voltage.
+ * @cur_dep_volt	: The voltage to which dependent vdd should be put
+ *			  to for the current main vdd voltage.
+ */
+struct omap_vdd_dep_info{
+	char *name;
+	struct voltagedomain *voltdm;
+	struct omap_vdd_dep_volt *dep_table;
+	unsigned long cur_dep_volt;
+};
+
+/**
  * omap_vdd_user_list	- The per vdd user list
  *
  * @dev		: The device asking for the vdd to be set at a particular
@@ -137,10 +167,12 @@ struct omap_vdd_info{
 	struct clk *volt_clk;
 	struct device *opp_dev;
 	struct voltagedomain voltdm;
+	struct omap_vdd_dep_info *dep_vdd_info;
 	spinlock_t user_lock;
 	struct plist_head user_list;
 	struct mutex scaling_mutex;
 	int volt_data_count;
+	int nr_dep_vdd;
 	struct device **dev_list;
 	int dev_count;
 	unsigned long nominal_volt;
@@ -1114,6 +1146,80 @@ static int vp_forceupdate_scale_voltage(struct omap_vdd_info *vdd,
 	return 0;
 }
 
+static int calc_dep_vdd_volt(struct device *dev,
+		struct omap_vdd_info *main_vdd, unsigned long main_volt)
+{
+	struct omap_vdd_dep_info *dep_vdds;
+	int i, ret = 0;
+
+	if (!main_vdd->dep_vdd_info) {
+		pr_debug("%s: No dependent VDD's for vdd_%s\n",
+			__func__, main_vdd->voltdm.name);
+		return 0;
+	}
+
+	dep_vdds = main_vdd->dep_vdd_info;
+
+	for (i = 0; i < main_vdd->nr_dep_vdd; i++) {
+		struct omap_vdd_dep_volt *volt_table = dep_vdds[i].dep_table;
+		int nr_volt = 0;
+		unsigned long dep_volt = 0, act_volt = 0;
+
+		while (volt_table[nr_volt].main_vdd_volt != 0) {
+			if (volt_table[nr_volt].main_vdd_volt == main_volt) {
+				dep_volt = volt_table[nr_volt].dep_vdd_volt;
+				break;
+			}
+			nr_volt++;
+		}
+		if (!dep_volt) {
+			pr_warning("%s: Not able to find a matching volt for"
+				"vdd_%s corresponding to vdd_%s %ld volt\n",
+				__func__, dep_vdds[i].name,
+				main_vdd->voltdm.name, main_volt);
+			ret = -EINVAL;
+			continue;
+		}
+
+		if (!dep_vdds[i].voltdm)
+			dep_vdds[i].voltdm =
+				omap_voltage_domain_get(dep_vdds[i].name);
+
+		act_volt = dep_volt;
+
+		/* See if dep_volt is possible for the vdd*/
+		ret = omap_voltage_add_userreq(dep_vdds[i].voltdm, dev,
+				&act_volt);
+
+		/*
+		 * Currently we do not bother if the dep volt and act volt are
+		 * different. We could add a check if needed.
+		 */
+		dep_vdds[i].cur_dep_volt = act_volt;
+	}
+
+	return ret;
+}
+
+static int scale_dep_vdd(struct omap_vdd_info *main_vdd)
+{
+	struct omap_vdd_dep_info *dep_vdds;
+	int i;
+
+	if (!main_vdd->dep_vdd_info) {
+		pr_debug("%s: No dependent VDD's for vdd_%s\n",
+			__func__, main_vdd->voltdm.name);
+		return 0;
+	}
+
+	dep_vdds = main_vdd->dep_vdd_info;
+
+	for (i = 0; i < main_vdd->nr_dep_vdd; i++)
+		omap_voltage_scale(dep_vdds[i].voltdm,
+				dep_vdds[i].cur_dep_volt);
+	return 0;
+}
+
 /* Public functions */
 /**
  * omap_voltage_get_nom_volt : Gets the current non-auto-compensated voltage
@@ -1599,6 +1705,8 @@ int omap_voltage_scale(struct voltagedomain *voltdm, unsigned long volt)
 	unsigned long curr_volt;
 	int is_volt_scaled = 0, i;
 	struct omap_vdd_info *vdd;
+	struct plist_node *node;
+	struct omap_vdd_user_list *user;
 
 	if (!voltdm || IS_ERR(voltdm)) {
 		pr_warning("%s: VDD specified does not exist!\n", __func__);
@@ -1611,6 +1719,17 @@ int omap_voltage_scale(struct voltagedomain *voltdm, unsigned long volt)
 
 	curr_volt = omap_voltage_get_nom_volt(voltdm);
 
+	/* Find the device requesting the voltage scaling */
+	node = plist_first(&vdd->user_list);
+	user = container_of(node, struct omap_vdd_user_list, node);
+
+	/* calculate the voltages for dependent vdd's */
+	if (calc_dep_vdd_volt(user->dev, vdd, volt)) {
+		pr_warning("%s: Error in calculating dependent vdd voltages"
+			"for vdd_%s\n", __func__, voltdm->name);
+		return -EINVAL;
+	}
+
 	if (curr_volt == volt) {
 		is_volt_scaled = 1;
 	} else if (curr_volt < volt) {
@@ -1645,6 +1764,9 @@ int omap_voltage_scale(struct voltagedomain *voltdm, unsigned long volt)
 
 	mutex_unlock(&vdd->scaling_mutex);
 
+	/* Scale dependent vdds */
+	scale_dep_vdd(vdd);
+
 	return 0;
 }
 
Signature · 1 line
1.7.1.GIT
#54 lore raw

PATCH 8/13 OMAP: Introduce device set_rate and get_rate.

In reply to Thara Gopinath

This patch adds omap_device_set_rate and omap_device_get_rate API's which can be used to generic device rate scaling.

---
 arch/arm/plat-omap/include/plat/omap_device.h |    3 +
 arch/arm/plat-omap/omap_device.c              |   74 +++++++++++++++++++++++++
 2 files changed, 77 insertions(+), 0 deletions(-)
arch/arm/plat-omap/include/plat/omap_device.h +3 -0
index 25cd9ac..2ebf2e2 100644
@@ -116,6 +116,9 @@ int omap_device_enable_hwmods(struct omap_device *od);
 int omap_device_disable_clocks(struct omap_device *od);
 int omap_device_enable_clocks(struct omap_device *od);
 
+int omap_device_set_rate(struct device *req_dev, struct device *dev,
+			 unsigned long rate);
+unsigned long omap_device_get_rate(struct device *dev);
 
 /*
  * Entries should be kept in latency order ascending
arch/arm/plat-omap/omap_device.c +74 -0

83 lines not on this page · raw message

Signature · 1 line
1.7.1.GIT
#55 lore raw

PATCH 9/13 OMAP: Disable smartreflex across DVFS

In reply to Thara Gopinath

This patch disables smartreflex for a particular voltage domain when the the voltage domain and the devices belonging to it is being scaled and re-enables it back once the scaling is done.

---
 arch/arm/mach-omap2/voltage.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/voltage.c +7 -0
index 1a46eb0..2fd644a 100644
@@ -35,6 +35,7 @@
 #include <plat/clock.h>
 #include <plat/common.h>
 #include <plat/voltage.h>
+#include <plat/smartreflex.h>
 
 #include "prm-regbits-34xx.h"
 #include "prm44xx.h"
@@ -1730,6 +1731,9 @@ int omap_voltage_scale(struct voltagedomain *voltdm, unsigned long volt)
 		return -EINVAL;
 	}
 
+	/* Disable smartreflex module across voltage and frequency scaling */
+	omap_smartreflex_disable(voltdm);
+
 	if (curr_volt == volt) {
 		is_volt_scaled = 1;
 	} else if (curr_volt < volt) {
@@ -1764,6 +1768,9 @@ int omap_voltage_scale(struct voltagedomain *voltdm, unsigned long volt)
 
 	mutex_unlock(&vdd->scaling_mutex);
 
+	/* Enable Smartreflex module */
+	omap_smartreflex_enable(voltdm);
+
 	/* Scale dependent vdds */
 	scale_dep_vdd(vdd);
 
Signature · 1 line
1.7.1.GIT
#56 lore raw

PATCH 10/13 OMAP3: Introduce custom set rate and get rate APIs for scalable devices

In reply to Thara Gopinath

This patch also introduces omap3_mpu_set_rate, omap3_iva_set_rate, omap3_l3_set_rate, omap3_mpu_get_rate, omap3_iva_get_rate, omap3_l3_get_rate as device specific set rate and get rate APIs for OMAP3 mpu, iva and l3_main devices. This patch also calls into opp_populate_rate_fns during system init to register various set_rate and get_rate APIs with the generic opp framework.

---
 arch/arm/mach-omap2/cpufreq34xx.c |  104 +++++++++++++++++++++++++++++++++++++
 1 files changed, 104 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/cpufreq34xx.c +104 -0
index 195b5bc..8b9ef72 100644
@@ -24,8 +24,22 @@
 
 #include <plat/opp.h>
 #include <plat/cpu.h>
+#include <plat/clock.h>
+
+#include "cm-regbits-34xx.h"
+#include "prm.h"
 #include "omap3-opp.h"
 
+static int omap3_mpu_set_rate(struct device *dev, unsigned long rate);
+static int omap3_iva_set_rate(struct device *dev, unsigned long rate);
+static int omap3_l3_set_rate(struct device *dev, unsigned long rate);
+
+static unsigned long omap3_mpu_get_rate(struct device *dev);
+static unsigned long omap3_iva_get_rate(struct device *dev);
+static unsigned long omap3_l3_get_rate(struct device *dev);
+
+struct clk *dpll1_clk, *dpll2_clk, *dpll3_clk;
+
 static struct omap_opp_def __initdata omap34xx_opp_def_list[] = {
 	/* MPU OPP1 */
 	OMAP_OPP_DEF("mpu", true, 125000000, 975000),
@@ -92,12 +106,82 @@ static struct omap_opp_def __initdata omap36xx_opp_def_list[] = {
 };
 static u32 omap36xx_opp_def_size = ARRAY_SIZE(omap36xx_opp_def_list);
 
+
+static int omap3_mpu_set_rate(struct device *dev, unsigned long rate)
+{
+	unsigned long cur_rate = omap3_mpu_get_rate(dev);
+	int ret;
+
+#ifdef CONFIG_CPU_FREQ
+	struct cpufreq_freqs freqs_notify;
+
+	freqs_notify.old = cur_rate / 1000;
+	freqs_notify.new = rate / 1000;
+	freqs_notify.cpu = 0;
+	/* Send pre notification to CPUFreq */
+	cpufreq_notify_transition(&freqs_notify, CPUFREQ_PRECHANGE);
+#endif
+	ret = clk_set_rate(dpll1_clk, rate);
+	if (ret) {
+		dev_warn(dev, "%s: Unable to set rate to %ld\n",
+			__func__, rate);
+		return ret;
+	}
+
+#ifdef CONFIG_CPU_FREQ
+	/* Send a post notification to CPUFreq */
+	cpufreq_notify_transition(&freqs_notify, CPUFREQ_POSTCHANGE);
+#endif
+
+#ifndef CONFIG_CPU_FREQ
+	/*Update loops_per_jiffy if processor speed is being changed*/
+	loops_per_jiffy = compute_lpj(loops_per_jiffy,
+			cur_rate / 1000, rate / 1000);
+#endif
+	return 0;
+}
+
+static unsigned long omap3_mpu_get_rate(struct device *dev)
+{
+	return dpll1_clk->rate;
+}
+
+static int omap3_iva_set_rate(struct device *dev, unsigned long rate)
+{
+	return clk_set_rate(dpll2_clk, rate);
+}
+
+static unsigned long omap3_iva_get_rate(struct device *dev)
+{
+	return dpll2_clk->rate;
+}
+
+static int omap3_l3_set_rate(struct device *dev, unsigned long rate)
+{
+	int l3_div;
+
+	l3_div = cm_read_mod_reg(CORE_MOD, CM_CLKSEL) &
+			OMAP3430_CLKSEL_L3_MASK;
+
+	return clk_set_rate(dpll3_clk, rate * l3_div);
+}
+
+static unsigned long omap3_l3_get_rate(struct device *dev)
+{
+	int l3_div;
+
+	l3_div = cm_read_mod_reg(CORE_MOD, CM_CLKSEL) &
+			OMAP3430_CLKSEL_L3_MASK;
+	return dpll3_clk->rate / l3_div;
+}
+
 /* Temp variable to allow multiple calls */
 static u8 __initdata omap3_table_init;
 
 int __init omap3_pm_init_opp_table(void)
 {
 	struct omap_opp_def *opp_def, *omap3_opp_def_list;
+	struct device *dev;
 	u32 omap3_opp_def_size;
 	int i, r;
 
@@ -122,6 +206,26 @@ int __init omap3_pm_init_opp_table(void)
 			       opp_def->freq, opp_def->hwmod_name);
 	}
 
+	dpll1_clk = clk_get(NULL, "dpll1_ck");
+	dpll2_clk = clk_get(NULL, "dpll2_ck");
+	dpll3_clk = clk_get(NULL, "dpll3_m2_ck");
+
+	/* Populate the set rate and get rate for mpu, iva and l3 device */
+	dev = omap2_get_mpuss_device();
+	if (dev)
+		opp_populate_rate_fns(dev, omap3_mpu_set_rate,
+				omap3_mpu_get_rate);
+
+	dev = omap2_get_iva_device();
+	if (dev)
+		opp_populate_rate_fns(dev, omap3_iva_set_rate,
+				omap3_iva_get_rate);
+
+	dev = omap2_get_l3_device();
+	if (dev)
+		opp_populate_rate_fns(dev, omap3_l3_set_rate,
+				omap3_l3_get_rate);
+
 	return 0;
 }
 
Signature · 1 line
1.7.1.GIT
#57 lore raw

Re: [PATCH 10/13] OMAP3: Introduce custom set rate and get rate APIs for scalable devices

Quoted 8 lines · Thara Gopinath

This patch also introduces omap3_mpu_set_rate, omap3_iva_set_rate, omap3_l3_set_rate, omap3_mpu_get_rate, omap3_iva_get_rate, omap3_l3_get_rate as device specific set rate and get rate APIs for OMAP3 mpu, iva and l3_main devices. This patch also calls into opp_populate_rate_fns during system init to register various set_rate and get_rate APIs with the generic opp framework.

Quoted 4 lines
---
 arch/arm/mach-omap2/cpufreq34xx.c |  104 +++++++++++++++++++++++++++++++++++++
 1 files changed, 104 insertions(+), 0 deletions(-)

These don't belong in cpufreq34xx.c (now known as opp3xxx_data.c) This file is only for the OPP data itself. Any SoC specific code should go into pm34xx.c.

Kevin

Quoted 136 lines
arch/arm/mach-omap2/cpufreq34xx.c +104 -0
index 195b5bc..8b9ef72 100644
@@ -24,8 +24,22 @@
 
 #include <plat/opp.h>
 #include <plat/cpu.h>
+#include <plat/clock.h>
+
+#include "cm-regbits-34xx.h"
+#include "prm.h"
 #include "omap3-opp.h"
 
+static int omap3_mpu_set_rate(struct device *dev, unsigned long rate);
+static int omap3_iva_set_rate(struct device *dev, unsigned long rate);
+static int omap3_l3_set_rate(struct device *dev, unsigned long rate);
+
+static unsigned long omap3_mpu_get_rate(struct device *dev);
+static unsigned long omap3_iva_get_rate(struct device *dev);
+static unsigned long omap3_l3_get_rate(struct device *dev);
+
+struct clk *dpll1_clk, *dpll2_clk, *dpll3_clk;
+
 static struct omap_opp_def __initdata omap34xx_opp_def_list[] = {
 	/* MPU OPP1 */
 	OMAP_OPP_DEF("mpu", true, 125000000, 975000),
@@ -92,12 +106,82 @@ static struct omap_opp_def __initdata omap36xx_opp_def_list[] = {
 };
 static u32 omap36xx_opp_def_size = ARRAY_SIZE(omap36xx_opp_def_list);
 
+
+static int omap3_mpu_set_rate(struct device *dev, unsigned long rate)
+{
+	unsigned long cur_rate = omap3_mpu_get_rate(dev);
+	int ret;
+
+#ifdef CONFIG_CPU_FREQ
+	struct cpufreq_freqs freqs_notify;
+
+	freqs_notify.old = cur_rate / 1000;
+	freqs_notify.new = rate / 1000;
+	freqs_notify.cpu = 0;
+	/* Send pre notification to CPUFreq */
+	cpufreq_notify_transition(&freqs_notify, CPUFREQ_PRECHANGE);
+#endif
+	ret = clk_set_rate(dpll1_clk, rate);
+	if (ret) {
+		dev_warn(dev, "%s: Unable to set rate to %ld\n",
+			__func__, rate);
+		return ret;
+	}
+
+#ifdef CONFIG_CPU_FREQ
+	/* Send a post notification to CPUFreq */
+	cpufreq_notify_transition(&freqs_notify, CPUFREQ_POSTCHANGE);
+#endif
+
+#ifndef CONFIG_CPU_FREQ
+	/*Update loops_per_jiffy if processor speed is being changed*/
+	loops_per_jiffy = compute_lpj(loops_per_jiffy,
+			cur_rate / 1000, rate / 1000);
+#endif
+	return 0;
+}
+
+static unsigned long omap3_mpu_get_rate(struct device *dev)
+{
+	return dpll1_clk->rate;
+}
+
+static int omap3_iva_set_rate(struct device *dev, unsigned long rate)
+{
+	return clk_set_rate(dpll2_clk, rate);
+}
+
+static unsigned long omap3_iva_get_rate(struct device *dev)
+{
+	return dpll2_clk->rate;
+}
+
+static int omap3_l3_set_rate(struct device *dev, unsigned long rate)
+{
+	int l3_div;
+
+	l3_div = cm_read_mod_reg(CORE_MOD, CM_CLKSEL) &
+			OMAP3430_CLKSEL_L3_MASK;
+
+	return clk_set_rate(dpll3_clk, rate * l3_div);
+}
+
+static unsigned long omap3_l3_get_rate(struct device *dev)
+{
+	int l3_div;
+
+	l3_div = cm_read_mod_reg(CORE_MOD, CM_CLKSEL) &
+			OMAP3430_CLKSEL_L3_MASK;
+	return dpll3_clk->rate / l3_div;
+}
+
 /* Temp variable to allow multiple calls */
 static u8 __initdata omap3_table_init;
 
 int __init omap3_pm_init_opp_table(void)
 {
 	struct omap_opp_def *opp_def, *omap3_opp_def_list;
+	struct device *dev;
 	u32 omap3_opp_def_size;
 	int i, r;
 
@@ -122,6 +206,26 @@ int __init omap3_pm_init_opp_table(void)
 			       opp_def->freq, opp_def->hwmod_name);
 	}
 
+	dpll1_clk = clk_get(NULL, "dpll1_ck");
+	dpll2_clk = clk_get(NULL, "dpll2_ck");
+	dpll3_clk = clk_get(NULL, "dpll3_m2_ck");
+
+	/* Populate the set rate and get rate for mpu, iva and l3 device */
+	dev = omap2_get_mpuss_device();
+	if (dev)
+		opp_populate_rate_fns(dev, omap3_mpu_set_rate,
+				omap3_mpu_get_rate);
+
+	dev = omap2_get_iva_device();
+	if (dev)
+		opp_populate_rate_fns(dev, omap3_iva_set_rate,
+				omap3_iva_get_rate);
+
+	dev = omap2_get_l3_device();
+	if (dev)
+		opp_populate_rate_fns(dev, omap3_l3_set_rate,
+				omap3_l3_get_rate);
+
 	return 0;
 }
#58 lore raw

PATCH 11/13 OMAP3: Update cpufreq driver to use the new set_rate API

In reply to Thara Gopinath

This patch updates the cpufreq driver to use the device set rate API to scale the mpu frequency for OMAP3.

---
 arch/arm/plat-omap/cpu-omap.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/arm/plat-omap/cpu-omap.c +2 -1
index df08829..9232246 100644
@@ -29,6 +29,7 @@
 #include <mach/hardware.h>
 #include <plat/clock.h>
 #include <asm/system.h>
+#include <plat/omap_device.h>
 
 #if defined(CONFIG_ARCH_OMAP3) && !defined(CONFIG_OMAP_PM_NONE)
 #include <plat/omap-pm.h>
@@ -117,7 +118,7 @@ static int omap_target(struct cpufreq_policy *policy,
 #elif defined(CONFIG_ARCH_OMAP3) && !defined(CONFIG_OMAP_PM_NONE)
 	freq = target_freq * 1000;
 	if (opp_find_freq_ceil(mpu_dev, &freq))
-		omap_pm_cpu_set_freq(freq);
+		omap_device_set_rate(mpu_dev, mpu_dev, freq);
 #endif
 	return ret;
 }
Signature · 1 line
1.7.1.GIT
#59 lore raw

PATCH 12/13 OMAP3: Introduce voltage domain info in the hwmod structures.

In reply to Thara Gopinath

This patch adds voltage domain info in the relevant device hwmod structures so as to enable OMAP3 DVFS support.

---
 arch/arm/mach-omap2/omap_hwmod_3xxx_data.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/omap_hwmod_3xxx_data.c +3 -0
index c9f0948..a6a67ed 100644
@@ -77,6 +77,7 @@ static struct omap_hwmod_ocp_if *omap3xxx_l3_main_masters[] = {
 static struct omap_hwmod omap3xxx_l3_main_hwmod = {
 	.name		= "l3_main",
 	.class		= &l3_hwmod_class,
+	.vdd_name	= "core",
 	.masters	= omap3xxx_l3_main_masters,
 	.masters_cnt	= ARRAY_SIZE(omap3xxx_l3_main_masters),
 	.slaves		= omap3xxx_l3_main_slaves,
@@ -206,6 +207,7 @@ static struct omap_hwmod omap3xxx_mpu_hwmod = {
 	.name		= "mpu",
 	.class		= &mpu_hwmod_class,
 	.main_clk	= "arm_fck",
+	.vdd_name	= "mpu",
 	.masters	= omap3xxx_mpu_masters,
 	.masters_cnt	= ARRAY_SIZE(omap3xxx_mpu_masters),
 	.omap_chip	= OMAP_CHIP_INIT(CHIP_IS_OMAP3430),
@@ -234,6 +236,7 @@ static struct omap_hwmod_ocp_if *omap3xxx_iva_masters[] = {
 static struct omap_hwmod omap3xxx_iva_hwmod = {
 	.name		= "iva",
 	.class		= &iva_hwmod_class,
+	.vdd_name	= "mpu",
 	.masters	= omap3xxx_iva_masters,
 	.masters_cnt	= ARRAY_SIZE(omap3xxx_iva_masters),
 	.omap_chip	= OMAP_CHIP_INIT(CHIP_IS_OMAP3430)
Signature · 1 line
1.7.1.GIT
#60 lore raw

PATCH 13/13 OMAP3: Add voltage dependency table for VDD1.

In reply to Thara Gopinath

In OMAP3, for perfomrance reasons when VDD1 is at voltage above 1.075V, VDD2 should be at 1.15V for perfomrance reasons. This patch introduce this cross VDD dependency for OMAP3 VDD1.

---
 arch/arm/mach-omap2/voltage.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/voltage.c +19 -0
index 2fd644a..3c990d0 100644
@@ -348,6 +348,23 @@ static struct omap_volt_data omap44xx_vdd_core_volt_data[] = {
 	{.volt_nominal = 1100000, .sr_errminlimit = 0xF9, .vp_errgain = 0x16},
 };
 
+/* OMAP 3430 MPU Core VDD dependency table */
+static struct omap_vdd_dep_volt omap34xx_vdd1_vdd2_data[] = {
+	{.main_vdd_volt = 975000, .dep_vdd_volt = 1050000},
+	{.main_vdd_volt = 1075000, .dep_vdd_volt = 1050000},
+	{.main_vdd_volt = 1200000, .dep_vdd_volt = 1150000},
+	{.main_vdd_volt = 1270000, .dep_vdd_volt = 1150000},
+	{.main_vdd_volt = 1350000, .dep_vdd_volt = 1150000},
+	{.main_vdd_volt = 0, .dep_vdd_volt = 0},
+};
+
+static struct omap_vdd_dep_info omap34xx_vdd1_dep_info[] = {
+	{
+		.name	= "core",
+		.dep_table = omap34xx_vdd1_vdd2_data,
+	},
+};
+
 /* By default VPFORCEUPDATE is the chosen method of voltage scaling */
 static bool voltscale_vpforceupdate = true;
 
@@ -523,6 +540,8 @@ static void __init omap3_vdd_data_configure(struct omap_vdd_info *vdd)
 			vdd->volt_data = omap34xx_vdd1_volt_data;
 			vdd->volt_data_count =
 					ARRAY_SIZE(omap34xx_vdd1_volt_data);
+			vdd->dep_vdd_info = omap34xx_vdd1_dep_info;
+			vdd->nr_dep_vdd = ARRAY_SIZE(omap34xx_vdd1_dep_info);
 		}
 		vdd->volt_clk = clk_get(NULL, "dpll1_ck");
 		vdd->opp_dev = omap2_get_mpuss_device();
Signature · 1 line
1.7.1.GIT