Merge back earlier 'pm-domains' material for v4.5.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
obj-$(CONFIG_PM) += sysfs.o generic_ops.o common.o qos.o runtime.o wakeirq.o
|
||||
obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o
|
||||
obj-$(CONFIG_PM_TRACE_RTC) += trace.o
|
||||
obj-$(CONFIG_PM_OPP) += opp.o
|
||||
obj-$(CONFIG_PM_OPP) += opp/
|
||||
obj-$(CONFIG_PM_GENERIC_DOMAINS) += domain.o domain_governor.o
|
||||
obj-$(CONFIG_HAVE_CLK) += clock_ops.o
|
||||
|
||||
|
@@ -17,7 +17,7 @@
|
||||
#include <linux/err.h>
|
||||
#include <linux/pm_runtime.h>
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
#ifdef CONFIG_PM_CLK
|
||||
|
||||
enum pce_status {
|
||||
PCE_STATUS_NONE = 0,
|
||||
@@ -93,7 +93,7 @@ static int __pm_clk_add(struct device *dev, const char *con_id,
|
||||
return -ENOMEM;
|
||||
}
|
||||
} else {
|
||||
if (IS_ERR(clk) || !__clk_get(clk)) {
|
||||
if (IS_ERR(clk)) {
|
||||
kfree(ce);
|
||||
return -ENOENT;
|
||||
}
|
||||
@@ -127,7 +127,9 @@ int pm_clk_add(struct device *dev, const char *con_id)
|
||||
* @clk: Clock pointer
|
||||
*
|
||||
* Add the clock to the list of clocks used for the power management of @dev.
|
||||
* It will increment refcount on clock pointer, use clk_put() on it when done.
|
||||
* The power-management code will take control of the clock reference, so
|
||||
* callers should not call clk_put() on @clk after this function sucessfully
|
||||
* returned.
|
||||
*/
|
||||
int pm_clk_add_clk(struct device *dev, struct clk *clk)
|
||||
{
|
||||
@@ -404,7 +406,7 @@ int pm_clk_runtime_resume(struct device *dev)
|
||||
return pm_generic_runtime_resume(dev);
|
||||
}
|
||||
|
||||
#else /* !CONFIG_PM */
|
||||
#else /* !CONFIG_PM_CLK */
|
||||
|
||||
/**
|
||||
* enable_clock - Enable a device clock.
|
||||
@@ -484,7 +486,7 @@ static int pm_clk_notify(struct notifier_block *nb,
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* !CONFIG_PM */
|
||||
#endif /* !CONFIG_PM_CLK */
|
||||
|
||||
/**
|
||||
* pm_clk_add_notifier - Add bus type notifier for power management clocks.
|
||||
|
@@ -1263,6 +1263,7 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(__pm_genpd_add_device);
|
||||
|
||||
/**
|
||||
* pm_genpd_remove_device - Remove a device from an I/O PM domain.
|
||||
@@ -1313,6 +1314,7 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd,
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(pm_genpd_remove_device);
|
||||
|
||||
/**
|
||||
* pm_genpd_add_subdomain - Add a subdomain to an I/O PM domain.
|
||||
@@ -1363,6 +1365,7 @@ int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
|
||||
kfree(link);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(pm_genpd_add_subdomain);
|
||||
|
||||
/**
|
||||
* pm_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain.
|
||||
@@ -1410,6 +1413,7 @@ out:
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(pm_genpd_remove_subdomain);
|
||||
|
||||
/* Default device callbacks for generic PM domains. */
|
||||
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#include <linux/pm.h>
|
||||
#include <linux/pm_runtime.h>
|
||||
#include <linux/export.h>
|
||||
#include <linux/suspend.h>
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
/**
|
||||
@@ -296,11 +297,27 @@ void pm_generic_complete(struct device *dev)
|
||||
|
||||
if (drv && drv->pm && drv->pm->complete)
|
||||
drv->pm->complete(dev);
|
||||
|
||||
/*
|
||||
* Let runtime PM try to suspend devices that haven't been in use before
|
||||
* going into the system-wide sleep state we're resuming from.
|
||||
*/
|
||||
pm_request_idle(dev);
|
||||
}
|
||||
|
||||
/**
|
||||
* pm_complete_with_resume_check - Complete a device power transition.
|
||||
* @dev: Device to handle.
|
||||
*
|
||||
* Complete a device power transition during a system-wide power transition and
|
||||
* optionally schedule a runtime resume of the device if the system resume in
|
||||
* progress has been initated by the platform firmware and the device had its
|
||||
* power.direct_complete flag set.
|
||||
*/
|
||||
void pm_complete_with_resume_check(struct device *dev)
|
||||
{
|
||||
pm_generic_complete(dev);
|
||||
/*
|
||||
* If the device had been runtime-suspended before the system went into
|
||||
* the sleep state it is going out of and it has never been resumed till
|
||||
* now, resume it in case the firmware powered it up.
|
||||
*/
|
||||
if (dev->power.direct_complete && pm_resume_via_firmware())
|
||||
pm_request_resume(dev);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(pm_complete_with_resume_check);
|
||||
#endif /* CONFIG_PM_SLEEP */
|
||||
|
2
drivers/base/power/opp/Makefile
Normal file
2
drivers/base/power/opp/Makefile
Normal file
@@ -0,0 +1,2 @@
|
||||
ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
|
||||
obj-y += core.o cpu.o
|
@@ -11,131 +11,16 @@
|
||||
* published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#include <linux/cpu.h>
|
||||
#include <linux/kernel.h>
|
||||
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
||||
|
||||
#include <linux/errno.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/rculist.h>
|
||||
#include <linux/rcupdate.h>
|
||||
#include <linux/pm_opp.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/export.h>
|
||||
|
||||
/*
|
||||
* Internal data structure organization with the OPP layer library is as
|
||||
* follows:
|
||||
* dev_opp_list (root)
|
||||
* |- device 1 (represents voltage domain 1)
|
||||
* | |- opp 1 (availability, freq, voltage)
|
||||
* | |- opp 2 ..
|
||||
* ... ...
|
||||
* | `- opp n ..
|
||||
* |- device 2 (represents the next voltage domain)
|
||||
* ...
|
||||
* `- device m (represents mth voltage domain)
|
||||
* device 1, 2.. are represented by dev_opp structure while each opp
|
||||
* is represented by the opp structure.
|
||||
*/
|
||||
|
||||
/**
|
||||
* struct dev_pm_opp - Generic OPP description structure
|
||||
* @node: opp list node. The nodes are maintained throughout the lifetime
|
||||
* of boot. It is expected only an optimal set of OPPs are
|
||||
* added to the library by the SoC framework.
|
||||
* RCU usage: opp list is traversed with RCU locks. node
|
||||
* modification is possible realtime, hence the modifications
|
||||
* are protected by the dev_opp_list_lock for integrity.
|
||||
* IMPORTANT: the opp nodes should be maintained in increasing
|
||||
* order.
|
||||
* @dynamic: not-created from static DT entries.
|
||||
* @available: true/false - marks if this OPP as available or not
|
||||
* @turbo: true if turbo (boost) OPP
|
||||
* @rate: Frequency in hertz
|
||||
* @u_volt: Target voltage in microvolts corresponding to this OPP
|
||||
* @u_volt_min: Minimum voltage in microvolts corresponding to this OPP
|
||||
* @u_volt_max: Maximum voltage in microvolts corresponding to this OPP
|
||||
* @u_amp: Maximum current drawn by the device in microamperes
|
||||
* @clock_latency_ns: Latency (in nanoseconds) of switching to this OPP's
|
||||
* frequency from any other OPP's frequency.
|
||||
* @dev_opp: points back to the device_opp struct this opp belongs to
|
||||
* @rcu_head: RCU callback head used for deferred freeing
|
||||
* @np: OPP's device node.
|
||||
*
|
||||
* This structure stores the OPP information for a given device.
|
||||
*/
|
||||
struct dev_pm_opp {
|
||||
struct list_head node;
|
||||
|
||||
bool available;
|
||||
bool dynamic;
|
||||
bool turbo;
|
||||
unsigned long rate;
|
||||
|
||||
unsigned long u_volt;
|
||||
unsigned long u_volt_min;
|
||||
unsigned long u_volt_max;
|
||||
unsigned long u_amp;
|
||||
unsigned long clock_latency_ns;
|
||||
|
||||
struct device_opp *dev_opp;
|
||||
struct rcu_head rcu_head;
|
||||
|
||||
struct device_node *np;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct device_list_opp - devices managed by 'struct device_opp'
|
||||
* @node: list node
|
||||
* @dev: device to which the struct object belongs
|
||||
* @rcu_head: RCU callback head used for deferred freeing
|
||||
*
|
||||
* This is an internal data structure maintaining the list of devices that are
|
||||
* managed by 'struct device_opp'.
|
||||
*/
|
||||
struct device_list_opp {
|
||||
struct list_head node;
|
||||
const struct device *dev;
|
||||
struct rcu_head rcu_head;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct device_opp - Device opp structure
|
||||
* @node: list node - contains the devices with OPPs that
|
||||
* have been registered. Nodes once added are not modified in this
|
||||
* list.
|
||||
* RCU usage: nodes are not modified in the list of device_opp,
|
||||
* however addition is possible and is secured by dev_opp_list_lock
|
||||
* @srcu_head: notifier head to notify the OPP availability changes.
|
||||
* @rcu_head: RCU callback head used for deferred freeing
|
||||
* @dev_list: list of devices that share these OPPs
|
||||
* @opp_list: list of opps
|
||||
* @np: struct device_node pointer for opp's DT node.
|
||||
* @shared_opp: OPP is shared between multiple devices.
|
||||
*
|
||||
* This is an internal data structure maintaining the link to opps attached to
|
||||
* a device. This structure is not meant to be shared to users as it is
|
||||
* meant for book keeping and private to OPP library.
|
||||
*
|
||||
* Because the opp structures can be used from both rcu and srcu readers, we
|
||||
* need to wait for the grace period of both of them before freeing any
|
||||
* resources. And so we have used kfree_rcu() from within call_srcu() handlers.
|
||||
*/
|
||||
struct device_opp {
|
||||
struct list_head node;
|
||||
|
||||
struct srcu_notifier_head srcu_head;
|
||||
struct rcu_head rcu_head;
|
||||
struct list_head dev_list;
|
||||
struct list_head opp_list;
|
||||
|
||||
struct device_node *np;
|
||||
unsigned long clock_latency_ns_max;
|
||||
bool shared_opp;
|
||||
struct dev_pm_opp *suspend_opp;
|
||||
};
|
||||
#include "opp.h"
|
||||
|
||||
/*
|
||||
* The root of the list of all devices. All device_opp structures branch off
|
||||
@@ -144,7 +29,7 @@ struct device_opp {
|
||||
*/
|
||||
static LIST_HEAD(dev_opp_list);
|
||||
/* Lock to allow exclusive modification to the device and opp lists */
|
||||
static DEFINE_MUTEX(dev_opp_list_lock);
|
||||
DEFINE_MUTEX(dev_opp_list_lock);
|
||||
|
||||
#define opp_rcu_lockdep_assert() \
|
||||
do { \
|
||||
@@ -196,14 +81,18 @@ static struct device_opp *_managed_opp(const struct device_node *np)
|
||||
* Return: pointer to 'struct device_opp' if found, otherwise -ENODEV or
|
||||
* -EINVAL based on type of error.
|
||||
*
|
||||
* Locking: This function must be called under rcu_read_lock(). device_opp
|
||||
* is a RCU protected pointer. This means that device_opp is valid as long
|
||||
* as we are under RCU lock.
|
||||
* Locking: For readers, this function must be called under rcu_read_lock().
|
||||
* device_opp is a RCU protected pointer, which means that device_opp is valid
|
||||
* as long as we are under RCU lock.
|
||||
*
|
||||
* For Writers, this function must be called with dev_opp_list_lock held.
|
||||
*/
|
||||
static struct device_opp *_find_device_opp(struct device *dev)
|
||||
struct device_opp *_find_device_opp(struct device *dev)
|
||||
{
|
||||
struct device_opp *dev_opp;
|
||||
|
||||
opp_rcu_lockdep_assert();
|
||||
|
||||
if (IS_ERR_OR_NULL(dev)) {
|
||||
pr_err("%s: Invalid parameters\n", __func__);
|
||||
return ERR_PTR(-EINVAL);
|
||||
@@ -217,7 +106,7 @@ static struct device_opp *_find_device_opp(struct device *dev)
|
||||
}
|
||||
|
||||
/**
|
||||
* dev_pm_opp_get_voltage() - Gets the voltage corresponding to an available opp
|
||||
* dev_pm_opp_get_voltage() - Gets the voltage corresponding to an opp
|
||||
* @opp: opp for which voltage has to be returned for
|
||||
*
|
||||
* Return: voltage in micro volt corresponding to the opp, else
|
||||
@@ -239,7 +128,7 @@ unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
|
||||
opp_rcu_lockdep_assert();
|
||||
|
||||
tmp_opp = rcu_dereference(opp);
|
||||
if (IS_ERR_OR_NULL(tmp_opp) || !tmp_opp->available)
|
||||
if (IS_ERR_OR_NULL(tmp_opp))
|
||||
pr_err("%s: Invalid parameters\n", __func__);
|
||||
else
|
||||
v = tmp_opp->u_volt;
|
||||
@@ -579,8 +468,8 @@ static void _remove_list_dev(struct device_list_opp *list_dev,
|
||||
_kfree_list_dev_rcu);
|
||||
}
|
||||
|
||||
static struct device_list_opp *_add_list_dev(const struct device *dev,
|
||||
struct device_opp *dev_opp)
|
||||
struct device_list_opp *_add_list_dev(const struct device *dev,
|
||||
struct device_opp *dev_opp)
|
||||
{
|
||||
struct device_list_opp *list_dev;
|
||||
|
||||
@@ -818,7 +707,7 @@ static int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,
|
||||
}
|
||||
|
||||
/**
|
||||
* _opp_add_dynamic() - Allocate a dynamic OPP.
|
||||
* _opp_add_v1() - Allocate a OPP based on v1 bindings.
|
||||
* @dev: device for which we do this operation
|
||||
* @freq: Frequency in Hz for this OPP
|
||||
* @u_volt: Voltage in uVolts for this OPP
|
||||
@@ -828,8 +717,8 @@ static int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,
|
||||
* The opp is made available by default and it can be controlled using
|
||||
* dev_pm_opp_enable/disable functions and may be removed by dev_pm_opp_remove.
|
||||
*
|
||||
* NOTE: "dynamic" parameter impacts OPPs added by the of_init_opp_table and
|
||||
* freed by of_free_opp_table.
|
||||
* NOTE: "dynamic" parameter impacts OPPs added by the dev_pm_opp_of_add_table
|
||||
* and freed by dev_pm_opp_of_remove_table.
|
||||
*
|
||||
* Locking: The internal device_opp and opp structures are RCU protected.
|
||||
* Hence this function internally uses RCU updater strategy with mutex locks
|
||||
@@ -844,8 +733,8 @@ static int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,
|
||||
* Duplicate OPPs (both freq and volt are same) and !opp->available
|
||||
* -ENOMEM Memory allocation failure
|
||||
*/
|
||||
static int _opp_add_dynamic(struct device *dev, unsigned long freq,
|
||||
long u_volt, bool dynamic)
|
||||
static int _opp_add_v1(struct device *dev, unsigned long freq, long u_volt,
|
||||
bool dynamic)
|
||||
{
|
||||
struct device_opp *dev_opp;
|
||||
struct dev_pm_opp *new_opp;
|
||||
@@ -887,9 +776,10 @@ unlock:
|
||||
}
|
||||
|
||||
/* TODO: Support multiple regulators */
|
||||
static int opp_get_microvolt(struct dev_pm_opp *opp, struct device *dev)
|
||||
static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev)
|
||||
{
|
||||
u32 microvolt[3] = {0};
|
||||
u32 val;
|
||||
int count, ret;
|
||||
|
||||
/* Missing property isn't a problem, but an invalid entry is */
|
||||
@@ -922,6 +812,9 @@ static int opp_get_microvolt(struct dev_pm_opp *opp, struct device *dev)
|
||||
opp->u_volt_min = microvolt[1];
|
||||
opp->u_volt_max = microvolt[2];
|
||||
|
||||
if (!of_property_read_u32(opp->np, "opp-microamp", &val))
|
||||
opp->u_amp = val;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -986,13 +879,10 @@ static int _opp_add_static_v2(struct device *dev, struct device_node *np)
|
||||
if (!of_property_read_u32(np, "clock-latency-ns", &val))
|
||||
new_opp->clock_latency_ns = val;
|
||||
|
||||
ret = opp_get_microvolt(new_opp, dev);
|
||||
ret = opp_parse_supplies(new_opp, dev);
|
||||
if (ret)
|
||||
goto free_opp;
|
||||
|
||||
if (!of_property_read_u32(new_opp->np, "opp-microamp", &val))
|
||||
new_opp->u_amp = val;
|
||||
|
||||
ret = _opp_add(dev, new_opp, dev_opp);
|
||||
if (ret)
|
||||
goto free_opp;
|
||||
@@ -1056,7 +946,7 @@ unlock:
|
||||
*/
|
||||
int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt)
|
||||
{
|
||||
return _opp_add_dynamic(dev, freq, u_volt, true);
|
||||
return _opp_add_v1(dev, freq, u_volt, true);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dev_pm_opp_add);
|
||||
|
||||
@@ -1220,7 +1110,8 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_notifier);
|
||||
|
||||
#ifdef CONFIG_OF
|
||||
/**
|
||||
* of_free_opp_table() - Free OPP table entries created from static DT entries
|
||||
* dev_pm_opp_of_remove_table() - Free OPP table entries created from static DT
|
||||
* entries
|
||||
* @dev: device pointer used to lookup device OPPs.
|
||||
*
|
||||
* Free OPPs created using static entries present in DT.
|
||||
@@ -1231,7 +1122,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_notifier);
|
||||
* that this function is *NOT* called under RCU protection or in contexts where
|
||||
* mutex cannot be locked.
|
||||
*/
|
||||
void of_free_opp_table(struct device *dev)
|
||||
void dev_pm_opp_of_remove_table(struct device *dev)
|
||||
{
|
||||
struct device_opp *dev_opp;
|
||||
struct dev_pm_opp *opp, *tmp;
|
||||
@@ -1266,92 +1157,39 @@ void of_free_opp_table(struct device *dev)
|
||||
unlock:
|
||||
mutex_unlock(&dev_opp_list_lock);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(of_free_opp_table);
|
||||
EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table);
|
||||
|
||||
void of_cpumask_free_opp_table(cpumask_var_t cpumask)
|
||||
/* Returns opp descriptor node for a device, caller must do of_node_put() */
|
||||
struct device_node *_of_get_opp_desc_node(struct device *dev)
|
||||
{
|
||||
struct device *cpu_dev;
|
||||
int cpu;
|
||||
|
||||
WARN_ON(cpumask_empty(cpumask));
|
||||
|
||||
for_each_cpu(cpu, cpumask) {
|
||||
cpu_dev = get_cpu_device(cpu);
|
||||
if (!cpu_dev) {
|
||||
pr_err("%s: failed to get cpu%d device\n", __func__,
|
||||
cpu);
|
||||
continue;
|
||||
}
|
||||
|
||||
of_free_opp_table(cpu_dev);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(of_cpumask_free_opp_table);
|
||||
|
||||
/* Returns opp descriptor node from its phandle. Caller must do of_node_put() */
|
||||
static struct device_node *
|
||||
_of_get_opp_desc_node_from_prop(struct device *dev, const struct property *prop)
|
||||
{
|
||||
struct device_node *opp_np;
|
||||
|
||||
opp_np = of_find_node_by_phandle(be32_to_cpup(prop->value));
|
||||
if (!opp_np) {
|
||||
dev_err(dev, "%s: Prop: %s contains invalid opp desc phandle\n",
|
||||
__func__, prop->name);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
return opp_np;
|
||||
}
|
||||
|
||||
/* Returns opp descriptor node for a device. Caller must do of_node_put() */
|
||||
static struct device_node *_of_get_opp_desc_node(struct device *dev)
|
||||
{
|
||||
const struct property *prop;
|
||||
|
||||
prop = of_find_property(dev->of_node, "operating-points-v2", NULL);
|
||||
if (!prop)
|
||||
return ERR_PTR(-ENODEV);
|
||||
if (!prop->value)
|
||||
return ERR_PTR(-ENODATA);
|
||||
|
||||
/*
|
||||
* TODO: Support for multiple OPP tables.
|
||||
*
|
||||
* There should be only ONE phandle present in "operating-points-v2"
|
||||
* property.
|
||||
*/
|
||||
if (prop->length != sizeof(__be32)) {
|
||||
dev_err(dev, "%s: Invalid opp desc phandle\n", __func__);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
return _of_get_opp_desc_node_from_prop(dev, prop);
|
||||
return of_parse_phandle(dev->of_node, "operating-points-v2", 0);
|
||||
}
|
||||
|
||||
/* Initializes OPP tables based on new bindings */
|
||||
static int _of_init_opp_table_v2(struct device *dev,
|
||||
const struct property *prop)
|
||||
static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np)
|
||||
{
|
||||
struct device_node *opp_np, *np;
|
||||
struct device_node *np;
|
||||
struct device_opp *dev_opp;
|
||||
int ret = 0, count = 0;
|
||||
|
||||
if (!prop->value)
|
||||
return -ENODATA;
|
||||
|
||||
/* Get opp node */
|
||||
opp_np = _of_get_opp_desc_node_from_prop(dev, prop);
|
||||
if (IS_ERR(opp_np))
|
||||
return PTR_ERR(opp_np);
|
||||
mutex_lock(&dev_opp_list_lock);
|
||||
|
||||
dev_opp = _managed_opp(opp_np);
|
||||
if (dev_opp) {
|
||||
/* OPPs are already managed */
|
||||
if (!_add_list_dev(dev, dev_opp))
|
||||
ret = -ENOMEM;
|
||||
goto put_opp_np;
|
||||
mutex_unlock(&dev_opp_list_lock);
|
||||
return ret;
|
||||
}
|
||||
mutex_unlock(&dev_opp_list_lock);
|
||||
|
||||
/* We have opp-list node now, iterate over it and add OPPs */
|
||||
for_each_available_child_of_node(opp_np, np) {
|
||||
@@ -1366,33 +1204,33 @@ static int _of_init_opp_table_v2(struct device *dev,
|
||||
}
|
||||
|
||||
/* There should be one of more OPP defined */
|
||||
if (WARN_ON(!count)) {
|
||||
ret = -ENOENT;
|
||||
goto put_opp_np;
|
||||
}
|
||||
if (WARN_ON(!count))
|
||||
return -ENOENT;
|
||||
|
||||
mutex_lock(&dev_opp_list_lock);
|
||||
|
||||
dev_opp = _find_device_opp(dev);
|
||||
if (WARN_ON(IS_ERR(dev_opp))) {
|
||||
ret = PTR_ERR(dev_opp);
|
||||
mutex_unlock(&dev_opp_list_lock);
|
||||
goto free_table;
|
||||
}
|
||||
|
||||
dev_opp->np = opp_np;
|
||||
dev_opp->shared_opp = of_property_read_bool(opp_np, "opp-shared");
|
||||
|
||||
of_node_put(opp_np);
|
||||
mutex_unlock(&dev_opp_list_lock);
|
||||
|
||||
return 0;
|
||||
|
||||
free_table:
|
||||
of_free_opp_table(dev);
|
||||
put_opp_np:
|
||||
of_node_put(opp_np);
|
||||
dev_pm_opp_of_remove_table(dev);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Initializes OPP tables based on old-deprecated bindings */
|
||||
static int _of_init_opp_table_v1(struct device *dev)
|
||||
static int _of_add_opp_table_v1(struct device *dev)
|
||||
{
|
||||
const struct property *prop;
|
||||
const __be32 *val;
|
||||
@@ -1419,7 +1257,7 @@ static int _of_init_opp_table_v1(struct device *dev)
|
||||
unsigned long freq = be32_to_cpup(val++) * 1000;
|
||||
unsigned long volt = be32_to_cpup(val++);
|
||||
|
||||
if (_opp_add_dynamic(dev, freq, volt, false))
|
||||
if (_opp_add_v1(dev, freq, volt, false))
|
||||
dev_warn(dev, "%s: Failed to add OPP %ld\n",
|
||||
__func__, freq);
|
||||
nr -= 2;
|
||||
@@ -1429,7 +1267,7 @@ static int _of_init_opp_table_v1(struct device *dev)
|
||||
}
|
||||
|
||||
/**
|
||||
* of_init_opp_table() - Initialize opp table from device tree
|
||||
* dev_pm_opp_of_add_table() - Initialize opp table from device tree
|
||||
* @dev: device pointer used to lookup device OPPs.
|
||||
*
|
||||
* Register the initial OPP table with the OPP library for given device.
|
||||
@@ -1451,153 +1289,28 @@ static int _of_init_opp_table_v1(struct device *dev)
|
||||
* -ENODATA when empty 'operating-points' property is found
|
||||
* -EINVAL when invalid entries are found in opp-v2 table
|
||||
*/
|
||||
int of_init_opp_table(struct device *dev)
|
||||
int dev_pm_opp_of_add_table(struct device *dev)
|
||||
{
|
||||
const struct property *prop;
|
||||
struct device_node *opp_np;
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* OPPs have two version of bindings now. The older one is deprecated,
|
||||
* try for the new binding first.
|
||||
*/
|
||||
prop = of_find_property(dev->of_node, "operating-points-v2", NULL);
|
||||
if (!prop) {
|
||||
opp_np = _of_get_opp_desc_node(dev);
|
||||
if (!opp_np) {
|
||||
/*
|
||||
* Try old-deprecated bindings for backward compatibility with
|
||||
* older dtbs.
|
||||
*/
|
||||
return _of_init_opp_table_v1(dev);
|
||||
return _of_add_opp_table_v1(dev);
|
||||
}
|
||||
|
||||
return _of_init_opp_table_v2(dev, prop);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(of_init_opp_table);
|
||||
|
||||
int of_cpumask_init_opp_table(cpumask_var_t cpumask)
|
||||
{
|
||||
struct device *cpu_dev;
|
||||
int cpu, ret = 0;
|
||||
|
||||
WARN_ON(cpumask_empty(cpumask));
|
||||
|
||||
for_each_cpu(cpu, cpumask) {
|
||||
cpu_dev = get_cpu_device(cpu);
|
||||
if (!cpu_dev) {
|
||||
pr_err("%s: failed to get cpu%d device\n", __func__,
|
||||
cpu);
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = of_init_opp_table(cpu_dev);
|
||||
if (ret) {
|
||||
pr_err("%s: couldn't find opp table for cpu:%d, %d\n",
|
||||
__func__, cpu, ret);
|
||||
|
||||
/* Free all other OPPs */
|
||||
of_cpumask_free_opp_table(cpumask);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ret = _of_add_opp_table_v2(dev, opp_np);
|
||||
of_node_put(opp_np);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(of_cpumask_init_opp_table);
|
||||
|
||||
/* Required only for V1 bindings, as v2 can manage it from DT itself */
|
||||
int set_cpus_sharing_opps(struct device *cpu_dev, cpumask_var_t cpumask)
|
||||
{
|
||||
struct device_list_opp *list_dev;
|
||||
struct device_opp *dev_opp;
|
||||
struct device *dev;
|
||||
int cpu, ret = 0;
|
||||
|
||||
rcu_read_lock();
|
||||
|
||||
dev_opp = _find_device_opp(cpu_dev);
|
||||
if (IS_ERR(dev_opp)) {
|
||||
ret = -EINVAL;
|
||||
goto out_rcu_read_unlock;
|
||||
}
|
||||
|
||||
for_each_cpu(cpu, cpumask) {
|
||||
if (cpu == cpu_dev->id)
|
||||
continue;
|
||||
|
||||
dev = get_cpu_device(cpu);
|
||||
if (!dev) {
|
||||
dev_err(cpu_dev, "%s: failed to get cpu%d device\n",
|
||||
__func__, cpu);
|
||||
continue;
|
||||
}
|
||||
|
||||
list_dev = _add_list_dev(dev, dev_opp);
|
||||
if (!list_dev) {
|
||||
dev_err(dev, "%s: failed to add list-dev for cpu%d device\n",
|
||||
__func__, cpu);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
out_rcu_read_unlock:
|
||||
rcu_read_unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(set_cpus_sharing_opps);
|
||||
|
||||
/*
|
||||
* Works only for OPP v2 bindings.
|
||||
*
|
||||
* cpumask should be already set to mask of cpu_dev->id.
|
||||
* Returns -ENOENT if operating-points-v2 bindings aren't supported.
|
||||
*/
|
||||
int of_get_cpus_sharing_opps(struct device *cpu_dev, cpumask_var_t cpumask)
|
||||
{
|
||||
struct device_node *np, *tmp_np;
|
||||
struct device *tcpu_dev;
|
||||
int cpu, ret = 0;
|
||||
|
||||
/* Get OPP descriptor node */
|
||||
np = _of_get_opp_desc_node(cpu_dev);
|
||||
if (IS_ERR(np)) {
|
||||
dev_dbg(cpu_dev, "%s: Couldn't find opp node: %ld\n", __func__,
|
||||
PTR_ERR(np));
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* OPPs are shared ? */
|
||||
if (!of_property_read_bool(np, "opp-shared"))
|
||||
goto put_cpu_node;
|
||||
|
||||
for_each_possible_cpu(cpu) {
|
||||
if (cpu == cpu_dev->id)
|
||||
continue;
|
||||
|
||||
tcpu_dev = get_cpu_device(cpu);
|
||||
if (!tcpu_dev) {
|
||||
dev_err(cpu_dev, "%s: failed to get cpu%d device\n",
|
||||
__func__, cpu);
|
||||
ret = -ENODEV;
|
||||
goto put_cpu_node;
|
||||
}
|
||||
|
||||
/* Get OPP descriptor node */
|
||||
tmp_np = _of_get_opp_desc_node(tcpu_dev);
|
||||
if (IS_ERR(tmp_np)) {
|
||||
dev_err(tcpu_dev, "%s: Couldn't find opp node: %ld\n",
|
||||
__func__, PTR_ERR(tmp_np));
|
||||
ret = PTR_ERR(tmp_np);
|
||||
goto put_cpu_node;
|
||||
}
|
||||
|
||||
/* CPUs are sharing opp node */
|
||||
if (np == tmp_np)
|
||||
cpumask_set_cpu(cpu, cpumask);
|
||||
|
||||
of_node_put(tmp_np);
|
||||
}
|
||||
|
||||
put_cpu_node:
|
||||
of_node_put(np);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(of_get_cpus_sharing_opps);
|
||||
EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table);
|
||||
#endif
|
270
drivers/base/power/opp/cpu.c
Normal file
270
drivers/base/power/opp/cpu.c
Normal file
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
* Generic OPP helper interface for CPU device
|
||||
*
|
||||
* Copyright (C) 2009-2014 Texas Instruments Incorporated.
|
||||
* Nishanth Menon
|
||||
* Romit Dasgupta
|
||||
* Kevin Hilman
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
||||
|
||||
#include <linux/cpu.h>
|
||||
#include <linux/cpufreq.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/export.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#include "opp.h"
|
||||
|
||||
#ifdef CONFIG_CPU_FREQ
|
||||
|
||||
/**
|
||||
* dev_pm_opp_init_cpufreq_table() - create a cpufreq table for a device
|
||||
* @dev: device for which we do this operation
|
||||
* @table: Cpufreq table returned back to caller
|
||||
*
|
||||
* Generate a cpufreq table for a provided device- this assumes that the
|
||||
* opp list is already initialized and ready for usage.
|
||||
*
|
||||
* This function allocates required memory for the cpufreq table. It is
|
||||
* expected that the caller does the required maintenance such as freeing
|
||||
* the table as required.
|
||||
*
|
||||
* Returns -EINVAL for bad pointers, -ENODEV if the device is not found, -ENOMEM
|
||||
* if no memory available for the operation (table is not populated), returns 0
|
||||
* if successful and table is populated.
|
||||
*
|
||||
* WARNING: It is important for the callers to ensure refreshing their copy of
|
||||
* the table if any of the mentioned functions have been invoked in the interim.
|
||||
*
|
||||
* Locking: The internal device_opp and opp structures are RCU protected.
|
||||
* Since we just use the regular accessor functions to access the internal data
|
||||
* structures, we use RCU read lock inside this function. As a result, users of
|
||||
* this function DONOT need to use explicit locks for invoking.
|
||||
*/
|
||||
int dev_pm_opp_init_cpufreq_table(struct device *dev,
|
||||
struct cpufreq_frequency_table **table)
|
||||
{
|
||||
struct dev_pm_opp *opp;
|
||||
struct cpufreq_frequency_table *freq_table = NULL;
|
||||
int i, max_opps, ret = 0;
|
||||
unsigned long rate;
|
||||
|
||||
rcu_read_lock();
|
||||
|
||||
max_opps = dev_pm_opp_get_opp_count(dev);
|
||||
if (max_opps <= 0) {
|
||||
ret = max_opps ? max_opps : -ENODATA;
|
||||
goto out;
|
||||
}
|
||||
|
||||
freq_table = kcalloc((max_opps + 1), sizeof(*freq_table), GFP_ATOMIC);
|
||||
if (!freq_table) {
|
||||
ret = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (i = 0, rate = 0; i < max_opps; i++, rate++) {
|
||||
/* find next rate */
|
||||
opp = dev_pm_opp_find_freq_ceil(dev, &rate);
|
||||
if (IS_ERR(opp)) {
|
||||
ret = PTR_ERR(opp);
|
||||
goto out;
|
||||
}
|
||||
freq_table[i].driver_data = i;
|
||||
freq_table[i].frequency = rate / 1000;
|
||||
|
||||
/* Is Boost/turbo opp ? */
|
||||
if (dev_pm_opp_is_turbo(opp))
|
||||
freq_table[i].flags = CPUFREQ_BOOST_FREQ;
|
||||
}
|
||||
|
||||
freq_table[i].driver_data = i;
|
||||
freq_table[i].frequency = CPUFREQ_TABLE_END;
|
||||
|
||||
*table = &freq_table[0];
|
||||
|
||||
out:
|
||||
rcu_read_unlock();
|
||||
if (ret)
|
||||
kfree(freq_table);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dev_pm_opp_init_cpufreq_table);
|
||||
|
||||
/**
|
||||
* dev_pm_opp_free_cpufreq_table() - free the cpufreq table
|
||||
* @dev: device for which we do this operation
|
||||
* @table: table to free
|
||||
*
|
||||
* Free up the table allocated by dev_pm_opp_init_cpufreq_table
|
||||
*/
|
||||
void dev_pm_opp_free_cpufreq_table(struct device *dev,
|
||||
struct cpufreq_frequency_table **table)
|
||||
{
|
||||
if (!table)
|
||||
return;
|
||||
|
||||
kfree(*table);
|
||||
*table = NULL;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dev_pm_opp_free_cpufreq_table);
|
||||
#endif /* CONFIG_CPU_FREQ */
|
||||
|
||||
/* Required only for V1 bindings, as v2 can manage it from DT itself */
|
||||
int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask)
|
||||
{
|
||||
struct device_list_opp *list_dev;
|
||||
struct device_opp *dev_opp;
|
||||
struct device *dev;
|
||||
int cpu, ret = 0;
|
||||
|
||||
mutex_lock(&dev_opp_list_lock);
|
||||
|
||||
dev_opp = _find_device_opp(cpu_dev);
|
||||
if (IS_ERR(dev_opp)) {
|
||||
ret = -EINVAL;
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
for_each_cpu(cpu, cpumask) {
|
||||
if (cpu == cpu_dev->id)
|
||||
continue;
|
||||
|
||||
dev = get_cpu_device(cpu);
|
||||
if (!dev) {
|
||||
dev_err(cpu_dev, "%s: failed to get cpu%d device\n",
|
||||
__func__, cpu);
|
||||
continue;
|
||||
}
|
||||
|
||||
list_dev = _add_list_dev(dev, dev_opp);
|
||||
if (!list_dev) {
|
||||
dev_err(dev, "%s: failed to add list-dev for cpu%d device\n",
|
||||
__func__, cpu);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
unlock:
|
||||
mutex_unlock(&dev_opp_list_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dev_pm_opp_set_sharing_cpus);
|
||||
|
||||
#ifdef CONFIG_OF
|
||||
void dev_pm_opp_of_cpumask_remove_table(cpumask_var_t cpumask)
|
||||
{
|
||||
struct device *cpu_dev;
|
||||
int cpu;
|
||||
|
||||
WARN_ON(cpumask_empty(cpumask));
|
||||
|
||||
for_each_cpu(cpu, cpumask) {
|
||||
cpu_dev = get_cpu_device(cpu);
|
||||
if (!cpu_dev) {
|
||||
pr_err("%s: failed to get cpu%d device\n", __func__,
|
||||
cpu);
|
||||
continue;
|
||||
}
|
||||
|
||||
dev_pm_opp_of_remove_table(cpu_dev);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_remove_table);
|
||||
|
||||
int dev_pm_opp_of_cpumask_add_table(cpumask_var_t cpumask)
|
||||
{
|
||||
struct device *cpu_dev;
|
||||
int cpu, ret = 0;
|
||||
|
||||
WARN_ON(cpumask_empty(cpumask));
|
||||
|
||||
for_each_cpu(cpu, cpumask) {
|
||||
cpu_dev = get_cpu_device(cpu);
|
||||
if (!cpu_dev) {
|
||||
pr_err("%s: failed to get cpu%d device\n", __func__,
|
||||
cpu);
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = dev_pm_opp_of_add_table(cpu_dev);
|
||||
if (ret) {
|
||||
pr_err("%s: couldn't find opp table for cpu:%d, %d\n",
|
||||
__func__, cpu, ret);
|
||||
|
||||
/* Free all other OPPs */
|
||||
dev_pm_opp_of_cpumask_remove_table(cpumask);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_add_table);
|
||||
|
||||
/*
|
||||
* Works only for OPP v2 bindings.
|
||||
*
|
||||
* cpumask should be already set to mask of cpu_dev->id.
|
||||
* Returns -ENOENT if operating-points-v2 bindings aren't supported.
|
||||
*/
|
||||
int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask)
|
||||
{
|
||||
struct device_node *np, *tmp_np;
|
||||
struct device *tcpu_dev;
|
||||
int cpu, ret = 0;
|
||||
|
||||
/* Get OPP descriptor node */
|
||||
np = _of_get_opp_desc_node(cpu_dev);
|
||||
if (!np) {
|
||||
dev_dbg(cpu_dev, "%s: Couldn't find cpu_dev node.\n", __func__);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* OPPs are shared ? */
|
||||
if (!of_property_read_bool(np, "opp-shared"))
|
||||
goto put_cpu_node;
|
||||
|
||||
for_each_possible_cpu(cpu) {
|
||||
if (cpu == cpu_dev->id)
|
||||
continue;
|
||||
|
||||
tcpu_dev = get_cpu_device(cpu);
|
||||
if (!tcpu_dev) {
|
||||
dev_err(cpu_dev, "%s: failed to get cpu%d device\n",
|
||||
__func__, cpu);
|
||||
ret = -ENODEV;
|
||||
goto put_cpu_node;
|
||||
}
|
||||
|
||||
/* Get OPP descriptor node */
|
||||
tmp_np = _of_get_opp_desc_node(tcpu_dev);
|
||||
if (!tmp_np) {
|
||||
dev_err(tcpu_dev, "%s: Couldn't find tcpu_dev node.\n",
|
||||
__func__);
|
||||
ret = -ENOENT;
|
||||
goto put_cpu_node;
|
||||
}
|
||||
|
||||
/* CPUs are sharing opp node */
|
||||
if (np == tmp_np)
|
||||
cpumask_set_cpu(cpu, cpumask);
|
||||
|
||||
of_node_put(tmp_np);
|
||||
}
|
||||
|
||||
put_cpu_node:
|
||||
of_node_put(np);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_sharing_cpus);
|
||||
#endif
|
146
drivers/base/power/opp/opp.h
Normal file
146
drivers/base/power/opp/opp.h
Normal file
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Generic OPP Interface
|
||||
*
|
||||
* Copyright (C) 2009-2010 Texas Instruments Incorporated.
|
||||
* Nishanth Menon
|
||||
* Romit Dasgupta
|
||||
* Kevin Hilman
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#ifndef __DRIVER_OPP_H__
|
||||
#define __DRIVER_OPP_H__
|
||||
|
||||
#include <linux/device.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/pm_opp.h>
|
||||
#include <linux/rculist.h>
|
||||
#include <linux/rcupdate.h>
|
||||
|
||||
/* Lock to allow exclusive modification to the device and opp lists */
|
||||
extern struct mutex dev_opp_list_lock;
|
||||
|
||||
/*
|
||||
* Internal data structure organization with the OPP layer library is as
|
||||
* follows:
|
||||
* dev_opp_list (root)
|
||||
* |- device 1 (represents voltage domain 1)
|
||||
* | |- opp 1 (availability, freq, voltage)
|
||||
* | |- opp 2 ..
|
||||
* ... ...
|
||||
* | `- opp n ..
|
||||
* |- device 2 (represents the next voltage domain)
|
||||
* ...
|
||||
* `- device m (represents mth voltage domain)
|
||||
* device 1, 2.. are represented by dev_opp structure while each opp
|
||||
* is represented by the opp structure.
|
||||
*/
|
||||
|
||||
/**
|
||||
* struct dev_pm_opp - Generic OPP description structure
|
||||
* @node: opp list node. The nodes are maintained throughout the lifetime
|
||||
* of boot. It is expected only an optimal set of OPPs are
|
||||
* added to the library by the SoC framework.
|
||||
* RCU usage: opp list is traversed with RCU locks. node
|
||||
* modification is possible realtime, hence the modifications
|
||||
* are protected by the dev_opp_list_lock for integrity.
|
||||
* IMPORTANT: the opp nodes should be maintained in increasing
|
||||
* order.
|
||||
* @dynamic: not-created from static DT entries.
|
||||
* @available: true/false - marks if this OPP as available or not
|
||||
* @turbo: true if turbo (boost) OPP
|
||||
* @rate: Frequency in hertz
|
||||
* @u_volt: Target voltage in microvolts corresponding to this OPP
|
||||
* @u_volt_min: Minimum voltage in microvolts corresponding to this OPP
|
||||
* @u_volt_max: Maximum voltage in microvolts corresponding to this OPP
|
||||
* @u_amp: Maximum current drawn by the device in microamperes
|
||||
* @clock_latency_ns: Latency (in nanoseconds) of switching to this OPP's
|
||||
* frequency from any other OPP's frequency.
|
||||
* @dev_opp: points back to the device_opp struct this opp belongs to
|
||||
* @rcu_head: RCU callback head used for deferred freeing
|
||||
* @np: OPP's device node.
|
||||
*
|
||||
* This structure stores the OPP information for a given device.
|
||||
*/
|
||||
struct dev_pm_opp {
|
||||
struct list_head node;
|
||||
|
||||
bool available;
|
||||
bool dynamic;
|
||||
bool turbo;
|
||||
unsigned long rate;
|
||||
|
||||
unsigned long u_volt;
|
||||
unsigned long u_volt_min;
|
||||
unsigned long u_volt_max;
|
||||
unsigned long u_amp;
|
||||
unsigned long clock_latency_ns;
|
||||
|
||||
struct device_opp *dev_opp;
|
||||
struct rcu_head rcu_head;
|
||||
|
||||
struct device_node *np;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct device_list_opp - devices managed by 'struct device_opp'
|
||||
* @node: list node
|
||||
* @dev: device to which the struct object belongs
|
||||
* @rcu_head: RCU callback head used for deferred freeing
|
||||
*
|
||||
* This is an internal data structure maintaining the list of devices that are
|
||||
* managed by 'struct device_opp'.
|
||||
*/
|
||||
struct device_list_opp {
|
||||
struct list_head node;
|
||||
const struct device *dev;
|
||||
struct rcu_head rcu_head;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct device_opp - Device opp structure
|
||||
* @node: list node - contains the devices with OPPs that
|
||||
* have been registered. Nodes once added are not modified in this
|
||||
* list.
|
||||
* RCU usage: nodes are not modified in the list of device_opp,
|
||||
* however addition is possible and is secured by dev_opp_list_lock
|
||||
* @srcu_head: notifier head to notify the OPP availability changes.
|
||||
* @rcu_head: RCU callback head used for deferred freeing
|
||||
* @dev_list: list of devices that share these OPPs
|
||||
* @opp_list: list of opps
|
||||
* @np: struct device_node pointer for opp's DT node.
|
||||
* @shared_opp: OPP is shared between multiple devices.
|
||||
*
|
||||
* This is an internal data structure maintaining the link to opps attached to
|
||||
* a device. This structure is not meant to be shared to users as it is
|
||||
* meant for book keeping and private to OPP library.
|
||||
*
|
||||
* Because the opp structures can be used from both rcu and srcu readers, we
|
||||
* need to wait for the grace period of both of them before freeing any
|
||||
* resources. And so we have used kfree_rcu() from within call_srcu() handlers.
|
||||
*/
|
||||
struct device_opp {
|
||||
struct list_head node;
|
||||
|
||||
struct srcu_notifier_head srcu_head;
|
||||
struct rcu_head rcu_head;
|
||||
struct list_head dev_list;
|
||||
struct list_head opp_list;
|
||||
|
||||
struct device_node *np;
|
||||
unsigned long clock_latency_ns_max;
|
||||
bool shared_opp;
|
||||
struct dev_pm_opp *suspend_opp;
|
||||
};
|
||||
|
||||
/* Routines internal to opp core */
|
||||
struct device_opp *_find_device_opp(struct device *dev);
|
||||
struct device_list_opp *_add_list_dev(const struct device *dev,
|
||||
struct device_opp *dev_opp);
|
||||
struct device_node *_of_get_opp_desc_node(struct device *dev);
|
||||
|
||||
#endif /* __DRIVER_OPP_H__ */
|
@@ -68,6 +68,9 @@ int dev_pm_set_wake_irq(struct device *dev, int irq)
|
||||
struct wake_irq *wirq;
|
||||
int err;
|
||||
|
||||
if (irq < 0)
|
||||
return -EINVAL;
|
||||
|
||||
wirq = kzalloc(sizeof(*wirq), GFP_KERNEL);
|
||||
if (!wirq)
|
||||
return -ENOMEM;
|
||||
@@ -167,6 +170,9 @@ int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq)
|
||||
struct wake_irq *wirq;
|
||||
int err;
|
||||
|
||||
if (irq < 0)
|
||||
return -EINVAL;
|
||||
|
||||
wirq = kzalloc(sizeof(*wirq), GFP_KERNEL);
|
||||
if (!wirq)
|
||||
return -ENOMEM;
|
||||
|
@@ -25,6 +25,9 @@
|
||||
*/
|
||||
bool events_check_enabled __read_mostly;
|
||||
|
||||
/* First wakeup IRQ seen by the kernel in the last cycle. */
|
||||
unsigned int pm_wakeup_irq __read_mostly;
|
||||
|
||||
/* If set and the system is suspending, terminate the suspend. */
|
||||
static bool pm_abort_suspend __read_mostly;
|
||||
|
||||
@@ -91,7 +94,7 @@ struct wakeup_source *wakeup_source_create(const char *name)
|
||||
if (!ws)
|
||||
return NULL;
|
||||
|
||||
wakeup_source_prepare(ws, name ? kstrdup(name, GFP_KERNEL) : NULL);
|
||||
wakeup_source_prepare(ws, name ? kstrdup_const(name, GFP_KERNEL) : NULL);
|
||||
return ws;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(wakeup_source_create);
|
||||
@@ -154,7 +157,7 @@ void wakeup_source_destroy(struct wakeup_source *ws)
|
||||
|
||||
wakeup_source_drop(ws);
|
||||
wakeup_source_record(ws);
|
||||
kfree(ws->name);
|
||||
kfree_const(ws->name);
|
||||
kfree(ws);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(wakeup_source_destroy);
|
||||
@@ -868,6 +871,15 @@ EXPORT_SYMBOL_GPL(pm_system_wakeup);
|
||||
void pm_wakeup_clear(void)
|
||||
{
|
||||
pm_abort_suspend = false;
|
||||
pm_wakeup_irq = 0;
|
||||
}
|
||||
|
||||
void pm_system_irq_wakeup(unsigned int irq_number)
|
||||
{
|
||||
if (pm_wakeup_irq == 0) {
|
||||
pm_wakeup_irq = irq_number;
|
||||
pm_system_wakeup();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user