Commit e07095c9 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki
Browse files

Merge branches 'pm-devfreq' and 'pm-domains'

* pm-devfreq:
  PM / devfreq: add tracing for scheduling work
  trace: events: add devfreq trace event file
  PM / devfreq: rk3399_dmc: Pass ODT and auto power down parameters to TF-A.
  PM / devfreq: rockchip-dfi: Move GRF definitions to a common place.
  PM / devfreq: exynos-bus: Suspend all devices on system shutdown
  PM / devfreq: Fix static checker warning in try_then_request_governor
  PM / devfreq: Restart previous governor if new governor fails to start
  PM / devfreq: tegra: remove unneeded variable
  PM / devfreq: rockchip-dfi: remove unneeded semicolon
  PM / devfreq: rk3399_dmc: remove unneeded semicolon
  PM / devfreq: consistent indentation
  PM / devfreq: fix missing check of return value in devfreq_add_device()
  PM / devfreq: fix mem leak in devfreq_add_device()
  PM / devfreq: Use of_node_name_eq for node name comparisons

* pm-domains:
  PM / Domains: Allow to attach a CPU via genpd_dev_pm_attach_by_id|name()
  PM / Domains: Search for the CPU device outside the genpd lock
  PM / Domains: Drop unused in-parameter to some genpd functions
  PM / Domains: Use the base device for driver_deferred_probe_check_state()
  PM / Domains: Enable genpd_dev_pm_attach_by_id|name() for single PM domain
  PM / Domains: Allow OF lookup for multi PM domain case from ->attach_dev()
  PM / Domains: Don't kfree() the virtual device in the error path
  PM / Domains: remove unnecessary unlikely()
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -4553,6 +4553,7 @@ S: Maintained
F:	drivers/devfreq/
F:	include/linux/devfreq.h
F:	Documentation/devicetree/bindings/devfreq/
F:	include/trace/events/devfreq.h

DEVICE FREQUENCY EVENT (DEVFREQ-EVENT)
M:	Chanwoo Choi <cw00.choi@samsung.com>
+42 −45
Original line number Diff line number Diff line
@@ -393,11 +393,9 @@ int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state)
	if (unlikely(!genpd->set_performance_state))
		return -EINVAL;

	if (unlikely(!dev->power.subsys_data ||
		     !dev->power.subsys_data->domain_data)) {
		WARN_ON(1);
	if (WARN_ON(!dev->power.subsys_data ||
		     !dev->power.subsys_data->domain_data))
		return -EINVAL;
	}

	genpd_lock(genpd);

@@ -1398,8 +1396,7 @@ EXPORT_SYMBOL_GPL(pm_genpd_syscore_poweron);

#endif /* CONFIG_PM_SLEEP */

static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev,
					struct gpd_timing_data *td)
static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev)
{
	struct generic_pm_domain_data *gpd_data;
	int ret;
@@ -1414,9 +1411,6 @@ static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev,
		goto err_put;
	}

	if (td)
		gpd_data->td = *td;

	gpd_data->base.dev = dev;
	gpd_data->td.constraint_changed = true;
	gpd_data->td.effective_constraint_ns = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS;
@@ -1456,7 +1450,7 @@ static void genpd_free_dev_data(struct device *dev,
	dev_pm_put_subsys_data(dev);
}

static void __genpd_update_cpumask(struct generic_pm_domain *genpd,
static void genpd_update_cpumask(struct generic_pm_domain *genpd,
				 int cpu, bool set, unsigned int depth)
{
	struct gpd_link *link;
@@ -1468,7 +1462,7 @@ static void __genpd_update_cpumask(struct generic_pm_domain *genpd,
		struct generic_pm_domain *master = link->master;

		genpd_lock_nested(master, depth + 1);
		__genpd_update_cpumask(master, cpu, set, depth + 1);
		genpd_update_cpumask(master, cpu, set, depth + 1);
		genpd_unlock(master);
	}

@@ -1478,36 +1472,35 @@ static void __genpd_update_cpumask(struct generic_pm_domain *genpd,
		cpumask_clear_cpu(cpu, genpd->cpus);
}

static void genpd_update_cpumask(struct generic_pm_domain *genpd,
				 struct device *dev, bool set)
static void genpd_set_cpumask(struct generic_pm_domain *genpd, int cpu)
{
	if (cpu >= 0)
		genpd_update_cpumask(genpd, cpu, true, 0);
}

static void genpd_clear_cpumask(struct generic_pm_domain *genpd, int cpu)
{
	if (cpu >= 0)
		genpd_update_cpumask(genpd, cpu, false, 0);
}

static int genpd_get_cpu(struct generic_pm_domain *genpd, struct device *dev)
{
	int cpu;

	if (!genpd_is_cpu_domain(genpd))
		return;
		return -1;

	for_each_possible_cpu(cpu) {
		if (get_cpu_device(cpu) == dev) {
			__genpd_update_cpumask(genpd, cpu, set, 0);
			return;
		}
	}
		if (get_cpu_device(cpu) == dev)
			return cpu;
	}

static void genpd_set_cpumask(struct generic_pm_domain *genpd,
			      struct device *dev)
{
	genpd_update_cpumask(genpd, dev, true);
}

static void genpd_clear_cpumask(struct generic_pm_domain *genpd,
				struct device *dev)
{
	genpd_update_cpumask(genpd, dev, false);
	return -1;
}

static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
			    struct gpd_timing_data *td)
			    struct device *base_dev)
{
	struct generic_pm_domain_data *gpd_data;
	int ret;
@@ -1517,17 +1510,19 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
	if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev))
		return -EINVAL;

	gpd_data = genpd_alloc_dev_data(dev, td);
	gpd_data = genpd_alloc_dev_data(dev);
	if (IS_ERR(gpd_data))
		return PTR_ERR(gpd_data);

	gpd_data->cpu = genpd_get_cpu(genpd, base_dev);

	ret = genpd->attach_dev ? genpd->attach_dev(genpd, dev) : 0;
	if (ret)
		goto out;

	genpd_lock(genpd);

	genpd_set_cpumask(genpd, dev);
	genpd_set_cpumask(genpd, gpd_data->cpu);
	dev_pm_domain_set(dev, &genpd->domain);

	genpd->device_count++;
@@ -1555,7 +1550,7 @@ int pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev)
	int ret;

	mutex_lock(&gpd_list_lock);
	ret = genpd_add_device(genpd, dev, NULL);
	ret = genpd_add_device(genpd, dev, dev);
	mutex_unlock(&gpd_list_lock);

	return ret;
@@ -1585,7 +1580,7 @@ static int genpd_remove_device(struct generic_pm_domain *genpd,
	genpd->device_count--;
	genpd->max_off_time_changed = true;

	genpd_clear_cpumask(genpd, dev);
	genpd_clear_cpumask(genpd, gpd_data->cpu);
	dev_pm_domain_set(dev, NULL);

	list_del_init(&pdd->list_node);
@@ -2261,7 +2256,7 @@ int of_genpd_add_device(struct of_phandle_args *genpdspec, struct device *dev)
		goto out;
	}

	ret = genpd_add_device(genpd, dev, NULL);
	ret = genpd_add_device(genpd, dev, dev);

out:
	mutex_unlock(&gpd_list_lock);
@@ -2345,6 +2340,7 @@ EXPORT_SYMBOL_GPL(of_genpd_remove_last);

static void genpd_release_dev(struct device *dev)
{
	of_node_put(dev->of_node);
	kfree(dev);
}

@@ -2406,14 +2402,14 @@ static void genpd_dev_pm_sync(struct device *dev)
	genpd_queue_power_off_work(pd);
}

static int __genpd_dev_pm_attach(struct device *dev, struct device_node *np,
static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,
				 unsigned int index, bool power_on)
{
	struct of_phandle_args pd_args;
	struct generic_pm_domain *pd;
	int ret;

	ret = of_parse_phandle_with_args(np, "power-domains",
	ret = of_parse_phandle_with_args(dev->of_node, "power-domains",
				"#power-domain-cells", index, &pd_args);
	if (ret < 0)
		return ret;
@@ -2425,12 +2421,12 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device_node *np,
		mutex_unlock(&gpd_list_lock);
		dev_dbg(dev, "%s() failed to find PM domain: %ld\n",
			__func__, PTR_ERR(pd));
		return driver_deferred_probe_check_state(dev);
		return driver_deferred_probe_check_state(base_dev);
	}

	dev_dbg(dev, "adding to PM domain %s\n", pd->name);

	ret = genpd_add_device(pd, dev, NULL);
	ret = genpd_add_device(pd, dev, base_dev);
	mutex_unlock(&gpd_list_lock);

	if (ret < 0) {
@@ -2481,7 +2477,7 @@ int genpd_dev_pm_attach(struct device *dev)
				       "#power-domain-cells") != 1)
		return 0;

	return __genpd_dev_pm_attach(dev, dev->of_node, 0, true);
	return __genpd_dev_pm_attach(dev, dev, 0, true);
}
EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);

@@ -2511,10 +2507,10 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev,
	if (!dev->of_node)
		return NULL;

	/* Deal only with devices using multiple PM domains. */
	/* Verify that the index is within a valid range. */
	num_domains = of_count_phandle_with_args(dev->of_node, "power-domains",
						 "#power-domain-cells");
	if (num_domains < 2 || index >= num_domains)
	if (index >= num_domains)
		return NULL;

	/* Allocate and register device on the genpd bus. */
@@ -2525,15 +2521,16 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev,
	dev_set_name(virt_dev, "genpd:%u:%s", index, dev_name(dev));
	virt_dev->bus = &genpd_bus_type;
	virt_dev->release = genpd_release_dev;
	virt_dev->of_node = of_node_get(dev->of_node);

	ret = device_register(virt_dev);
	if (ret) {
		kfree(virt_dev);
		put_device(virt_dev);
		return ERR_PTR(ret);
	}

	/* Try to attach the device to the PM domain at the specified index. */
	ret = __genpd_dev_pm_attach(virt_dev, dev->of_node, index, false);
	ret = __genpd_dev_pm_attach(virt_dev, dev, index, false);
	if (ret < 1) {
		device_unregister(virt_dev);
		return ret ? ERR_PTR(ret) : NULL;
+1 −1
Original line number Diff line number Diff line
@@ -240,7 +240,7 @@ struct devfreq_event_dev *devfreq_event_get_edev_by_phandle(struct device *dev,
	}

	list_for_each_entry(edev, &devfreq_event_list, node) {
		if (!strcmp(edev->desc->name, node->name))
		if (of_node_name_eq(node, edev->desc->name))
			goto out;
	}
	edev = NULL;
+59 −31
Original line number Diff line number Diff line
@@ -29,6 +29,9 @@
#include <linux/of.h>
#include "governor.h"

#define CREATE_TRACE_POINTS
#include <trace/events/devfreq.h>

static struct class *devfreq_class;

/*
@@ -228,7 +231,7 @@ static struct devfreq_governor *find_devfreq_governor(const char *name)
 * if is not found. This can happen when both drivers (the governor driver
 * and the driver that call devfreq_add_device) are built as modules.
 * devfreq_list_lock should be held by the caller. Returns the matched
 * governor's pointer.
 * governor's pointer or an error pointer.
 */
static struct devfreq_governor *try_then_request_governor(const char *name)
{
@@ -254,7 +257,7 @@ static struct devfreq_governor *try_then_request_governor(const char *name)
		/* Restore previous state before return */
		mutex_lock(&devfreq_list_lock);
		if (err)
			return NULL;
			return ERR_PTR(err);

		governor = find_devfreq_governor(name);
	}
@@ -394,6 +397,8 @@ static void devfreq_monitor(struct work_struct *work)
	queue_delayed_work(devfreq_wq, &devfreq->work,
				msecs_to_jiffies(devfreq->profile->polling_ms));
	mutex_unlock(&devfreq->lock);

	trace_devfreq_monitor(devfreq);
}

/**
@@ -651,7 +656,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
		mutex_unlock(&devfreq->lock);
		err = set_freq_table(devfreq);
		if (err < 0)
			goto err_out;
			goto err_dev;
		mutex_lock(&devfreq->lock);
	}

@@ -683,16 +688,27 @@ struct devfreq *devfreq_add_device(struct device *dev,
		goto err_out;
	}

	devfreq->trans_table =
		devm_kzalloc(&devfreq->dev,
	devfreq->trans_table = devm_kzalloc(&devfreq->dev,
			array3_size(sizeof(unsigned int),
				    devfreq->profile->max_state,
				    devfreq->profile->max_state),
			GFP_KERNEL);
	if (!devfreq->trans_table) {
		mutex_unlock(&devfreq->lock);
		err = -ENOMEM;
		goto err_devfreq;
	}

	devfreq->time_in_state = devm_kcalloc(&devfreq->dev,
			devfreq->profile->max_state,
			sizeof(unsigned long),
			GFP_KERNEL);
	if (!devfreq->time_in_state) {
		mutex_unlock(&devfreq->lock);
		err = -ENOMEM;
		goto err_devfreq;
	}

	devfreq->last_stat_updated = jiffies;

	srcu_init_notifier_head(&devfreq->transition_notifier_list);
@@ -726,7 +742,7 @@ struct devfreq *devfreq_add_device(struct device *dev,

err_init:
	mutex_unlock(&devfreq_list_lock);

err_devfreq:
	devfreq_remove_device(devfreq);
	devfreq = NULL;
err_dev:
@@ -1113,7 +1129,7 @@ static ssize_t governor_store(struct device *dev, struct device_attribute *attr,
	struct devfreq *df = to_devfreq(dev);
	int ret;
	char str_governor[DEVFREQ_NAME_LEN + 1];
	struct devfreq_governor *governor;
	const struct devfreq_governor *governor, *prev_governor;

	ret = sscanf(buf, "%" __stringify(DEVFREQ_NAME_LEN) "s", str_governor);
	if (ret != 1)
@@ -1142,12 +1158,24 @@ static ssize_t governor_store(struct device *dev, struct device_attribute *attr,
			goto out;
		}
	}
	prev_governor = df->governor;
	df->governor = governor;
	strncpy(df->governor_name, governor->name, DEVFREQ_NAME_LEN);
	ret = df->governor->event_handler(df, DEVFREQ_GOV_START, NULL);
	if (ret)
	if (ret) {
		dev_warn(dev, "%s: Governor %s not started(%d)\n",
			 __func__, df->governor->name, ret);
		df->governor = prev_governor;
		strncpy(df->governor_name, prev_governor->name,
			DEVFREQ_NAME_LEN);
		ret = df->governor->event_handler(df, DEVFREQ_GOV_START, NULL);
		if (ret) {
			dev_err(dev,
				"%s: reverting to Governor %s failed (%d)\n",
				__func__, df->governor_name, ret);
			df->governor = NULL;
		}
	}
out:
	mutex_unlock(&devfreq_list_lock);

@@ -1518,8 +1546,8 @@ static void devm_devfreq_opp_release(struct device *dev, void *res)
}

/**
 * devm_ devfreq_register_opp_notifier()
 *		- Resource-managed devfreq_register_opp_notifier()
 * devm_devfreq_register_opp_notifier() - Resource-managed
 *					  devfreq_register_opp_notifier()
 * @dev:	The devfreq user device. (parent of devfreq)
 * @devfreq:	The devfreq object.
 */
@@ -1547,8 +1575,8 @@ int devm_devfreq_register_opp_notifier(struct device *dev,
EXPORT_SYMBOL(devm_devfreq_register_opp_notifier);

/**
 * devm_devfreq_unregister_opp_notifier()
 *		- Resource-managed devfreq_unregister_opp_notifier()
 * devm_devfreq_unregister_opp_notifier() - Resource-managed
 *					    devfreq_unregister_opp_notifier()
 * @dev:	The devfreq user device. (parent of devfreq)
 * @devfreq:	The devfreq object.
 */
+1 −1
Original line number Diff line number Diff line
@@ -529,7 +529,7 @@ static int of_get_devfreq_events(struct device_node *np,
			if (!ppmu_events[i].name)
				continue;

			if (!of_node_cmp(node->name, ppmu_events[i].name))
			if (of_node_name_eq(node, ppmu_events[i].name))
				break;
		}

Loading