Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f9688466 authored by Alex Shi's avatar Alex Shi
Browse files

Merge remote-tracking branch 'origin/v4.4/topic/OPPv2' into linux-linaro-lsk-v4.4

parents a7a69d59 454f12fd
Loading
Loading
Loading
Loading
+93 −39
Original line number Diff line number Diff line
@@ -45,21 +45,10 @@ Devices supporting OPPs must set their "operating-points-v2" property with
phandle to a OPP table in their DT node. The OPP core will use this phandle to
find the operating points for the device.

Devices may want to choose OPP tables at runtime and so can provide a list of
phandles here. But only *one* of them should be chosen at runtime. This must be
accompanied by a corresponding "operating-points-names" property, to uniquely
identify the OPP tables.

If required, this can be extended for SoC vendor specfic bindings. Such bindings
should be documented as Documentation/devicetree/bindings/power/<vendor>-opp.txt
and should have a compatible description like: "operating-points-v2-<vendor>".

Optional properties:
- operating-points-names: Names of OPP tables (required if multiple OPP
  tables are present), to uniquely identify them. The same list must be present
  for all the CPUs which are sharing clock/voltage rails and hence the OPP
  tables.

* OPP Table Node

This describes the OPPs belonging to a device. This node can have following
@@ -100,6 +89,14 @@ Optional properties:
  Entries for multiple regulators must be present in the same order as
  regulators are specified in device's DT node.

- opp-microvolt-<name>: Named opp-microvolt property. This is exactly similar to
  the above opp-microvolt property, but allows multiple voltage ranges to be
  provided for the same OPP. At runtime, the platform can pick a <name> and
  matching opp-microvolt-<name> property will be enabled for all OPPs. If the
  platform doesn't pick a specific <name> or the <name> doesn't match with any
  opp-microvolt-<name> properties, then opp-microvolt property shall be used, if
  present.

- opp-microamp: The maximum current drawn by the device in microamperes
  considering system specific parameters (such as transients, process, aging,
  maximum operating temperature range etc.) as necessary. This may be used to
@@ -112,6 +109,9 @@ Optional properties:
  for few regulators, then this should be marked as zero for them. If it isn't
  required for any regulator, then this property need not be present.

- opp-microamp-<name>: Named opp-microamp property. Similar to
  opp-microvolt-<name> property, but for microamp instead.

- clock-latency-ns: Specifies the maximum possible transition latency (in
  nanoseconds) for switching to this OPP from any other OPP.

@@ -123,6 +123,26 @@ Optional properties:
- opp-suspend: Marks the OPP to be used during device suspend. Only one OPP in
  the table should have this.

- opp-supported-hw: This enables us to select only a subset of OPPs from the
  larger OPP table, based on what version of the hardware we are running on. We
  still can't have multiple nodes with the same opp-hz value in OPP table.

  It's an user defined array containing a hierarchy of hardware version numbers,
  supported by the OPP. For example: a platform with hierarchy of three levels
  of versions (A, B and C), this field should be like <X Y Z>, where X
  corresponds to Version hierarchy A, Y corresponds to version hierarchy B and Z
  corresponds to version hierarchy C.

  Each level of hierarchy is represented by a 32 bit value, and so there can be
  only 32 different supported version per hierarchy. i.e. 1 bit per version. A
  value of 0xFFFFFFFF will enable the OPP for all versions for that hierarchy
  level. And a value of 0x00000000 will disable the OPP completely, and so we
  never want that to happen.

  If 32 values aren't sufficient for a version hierarchy, than that version
  hierarchy can be contained in multiple 32 bit values. i.e. <X Y Z1 Z2> in the
  above example, Z1 & Z2 refer to the version hierarchy Z.

- status: Marks the node enabled/disabled.

Example 1: Single cluster Dual-core ARM cortex A9, switch DVFS states together.
@@ -157,20 +177,20 @@ Example 1: Single cluster Dual-core ARM cortex A9, switch DVFS states together.
		compatible = "operating-points-v2";
		opp-shared;

		opp00 {
		opp@1000000000 {
			opp-hz = /bits/ 64 <1000000000>;
			opp-microvolt = <970000 975000 985000>;
			opp-microamp = <70000>;
			clock-latency-ns = <300000>;
			opp-suspend;
		};
		opp01 {
		opp@1100000000 {
			opp-hz = /bits/ 64 <1100000000>;
			opp-microvolt = <980000 1000000 1010000>;
			opp-microamp = <80000>;
			clock-latency-ns = <310000>;
		};
		opp02 {
		opp@1200000000 {
			opp-hz = /bits/ 64 <1200000000>;
			opp-microvolt = <1025000>;
			clock-latency-ns = <290000>;
@@ -236,20 +256,20 @@ independently.
		 * independently.
		 */

		opp00 {
		opp@1000000000 {
			opp-hz = /bits/ 64 <1000000000>;
			opp-microvolt = <970000 975000 985000>;
			opp-microamp = <70000>;
			clock-latency-ns = <300000>;
			opp-suspend;
		};
		opp01 {
		opp@1100000000 {
			opp-hz = /bits/ 64 <1100000000>;
			opp-microvolt = <980000 1000000 1010000>;
			opp-microamp = <80000>;
			clock-latency-ns = <310000>;
		};
		opp02 {
		opp@1200000000 {
			opp-hz = /bits/ 64 <1200000000>;
			opp-microvolt = <1025000>;
			opp-microamp = <90000;
@@ -312,20 +332,20 @@ DVFS state together.
		compatible = "operating-points-v2";
		opp-shared;

		opp00 {
		opp@1000000000 {
			opp-hz = /bits/ 64 <1000000000>;
			opp-microvolt = <970000 975000 985000>;
			opp-microamp = <70000>;
			clock-latency-ns = <300000>;
			opp-suspend;
		};
		opp01 {
		opp@1100000000 {
			opp-hz = /bits/ 64 <1100000000>;
			opp-microvolt = <980000 1000000 1010000>;
			opp-microamp = <80000>;
			clock-latency-ns = <310000>;
		};
		opp02 {
		opp@1200000000 {
			opp-hz = /bits/ 64 <1200000000>;
			opp-microvolt = <1025000>;
			opp-microamp = <90000>;
@@ -338,20 +358,20 @@ DVFS state together.
		compatible = "operating-points-v2";
		opp-shared;

		opp10 {
		opp@1300000000 {
			opp-hz = /bits/ 64 <1300000000>;
			opp-microvolt = <1045000 1050000 1055000>;
			opp-microamp = <95000>;
			clock-latency-ns = <400000>;
			opp-suspend;
		};
		opp11 {
		opp@1400000000 {
			opp-hz = /bits/ 64 <1400000000>;
			opp-microvolt = <1075000>;
			opp-microamp = <100000>;
			clock-latency-ns = <400000>;
		};
		opp12 {
		opp@1500000000 {
			opp-hz = /bits/ 64 <1500000000>;
			opp-microvolt = <1010000 1100000 1110000>;
			opp-microamp = <95000>;
@@ -378,7 +398,7 @@ Example 4: Handling multiple regulators
		compatible = "operating-points-v2";
		opp-shared;

		opp00 {
		opp@1000000000 {
			opp-hz = /bits/ 64 <1000000000>;
			opp-microvolt = <970000>, /* Supply 0 */
					<960000>, /* Supply 1 */
@@ -391,7 +411,7 @@ Example 4: Handling multiple regulators

		/* OR */

		opp00 {
		opp@1000000000 {
			opp-hz = /bits/ 64 <1000000000>;
			opp-microvolt = <970000 975000 985000>, /* Supply 0 */
					<960000 965000 975000>, /* Supply 1 */
@@ -404,7 +424,7 @@ Example 4: Handling multiple regulators

		/* OR */

		opp00 {
		opp@1000000000 {
			opp-hz = /bits/ 64 <1000000000>;
			opp-microvolt = <970000 975000 985000>, /* Supply 0 */
					<960000 965000 975000>, /* Supply 1 */
@@ -417,7 +437,8 @@ Example 4: Handling multiple regulators
	};
};

Example 5: Multiple OPP tables
Example 5: opp-supported-hw
(example: three level hierarchy of versions: cuts, substrate and process)

/ {
	cpus {
@@ -426,40 +447,73 @@ Example 5: Multiple OPP tables
			...

			cpu-supply = <&cpu_supply>
			operating-points-v2 = <&cpu0_opp_table_slow>, <&cpu0_opp_table_fast>;
			operating-points-names = "slow", "fast";
			operating-points-v2 = <&cpu0_opp_table_slow>;
		};
	};

	cpu0_opp_table_slow: opp_table_slow {
	opp_table {
		compatible = "operating-points-v2";
		status = "okay";
		opp-shared;

		opp00 {
		opp@600000000 {
			/*
			 * Supports all substrate and process versions for 0xF
			 * cuts, i.e. only first four cuts.
			 */
			opp-supported-hw = <0xF 0xFFFFFFFF 0xFFFFFFFF>
			opp-hz = /bits/ 64 <600000000>;
			opp-microvolt = <900000 915000 925000>;
			...
		};

		opp01 {
		opp@800000000 {
			/*
			 * Supports:
			 * - cuts: only one, 6th cut (represented by 6th bit).
			 * - substrate: supports 16 different substrate versions
			 * - process: supports 9 different process versions
			 */
			opp-supported-hw = <0x20 0xff0000ff 0x0000f4f0>
			opp-hz = /bits/ 64 <800000000>;
			opp-microvolt = <900000 915000 925000>;
			...
		};
	};
};

	cpu0_opp_table_fast: opp_table_fast {
Example 6: opp-microvolt-<name>, opp-microamp-<name>:
(example: device with two possible microvolt ranges: slow and fast)

/ {
	cpus {
		cpu@0 {
			compatible = "arm,cortex-a7";
			...

			operating-points-v2 = <&cpu0_opp_table>;
		};
	};

	cpu0_opp_table: opp_table0 {
		compatible = "operating-points-v2";
		status = "okay";
		opp-shared;

		opp10 {
		opp@1000000000 {
			opp-hz = /bits/ 64 <1000000000>;
			...
			opp-microvolt-slow = <900000 915000 925000>;
			opp-microvolt-fast = <970000 975000 985000>;
			opp-microamp-slow =  <70000>;
			opp-microamp-fast =  <71000>;
		};

		opp11 {
			opp-hz = /bits/ 64 <1100000000>;
			...
		opp@1200000000 {
			opp-hz = /bits/ 64 <1200000000>;
			opp-microvolt-slow = <900000 915000 925000>, /* Supply vcc0 */
					      <910000 925000 935000>; /* Supply vcc1 */
			opp-microvolt-fast = <970000 975000 985000>, /* Supply vcc0 */
					     <960000 965000 975000>; /* Supply vcc1 */
			opp-microamp =  <70000>; /* Will be used for both slow/fast */
		};
	};
};
+1 −0
Original line number Diff line number Diff line
ccflags-$(CONFIG_DEBUG_DRIVER)	:= -DDEBUG
obj-y				+= core.o cpu.o
obj-$(CONFIG_DEBUG_FS)		+= debugfs.o
+988 −251

File changed.

Preview size limit exceeded, changes collapsed.

+13 −12
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@
 * @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.
 * opp table 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
@@ -44,7 +44,7 @@
 * 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.
 * Locking: The internal opp_table 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.
@@ -122,15 +122,15 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_free_cpufreq_table);
/* 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 opp_device *opp_dev;
	struct opp_table *opp_table;
	struct device *dev;
	int cpu, ret = 0;

	mutex_lock(&dev_opp_list_lock);
	mutex_lock(&opp_table_lock);

	dev_opp = _find_device_opp(cpu_dev);
	if (IS_ERR(dev_opp)) {
	opp_table = _find_opp_table(cpu_dev);
	if (IS_ERR(opp_table)) {
		ret = -EINVAL;
		goto unlock;
	}
@@ -146,15 +146,15 @@ int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask)
			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",
		opp_dev = _add_opp_dev(dev, opp_table);
		if (!opp_dev) {
			dev_err(dev, "%s: failed to add opp-dev for cpu%d device\n",
				__func__, cpu);
			continue;
		}
	}
unlock:
	mutex_unlock(&dev_opp_list_lock);
	mutex_unlock(&opp_table_lock);

	return ret;
}
@@ -214,7 +214,6 @@ 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)
@@ -230,6 +229,8 @@ int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask
		return -ENOENT;
	}

	cpumask_set_cpu(cpu_dev->id, cpumask);

	/* OPPs are shared ? */
	if (!of_property_read_bool(np, "opp-shared"))
		goto put_cpu_node;
+218 −0
Original line number Diff line number Diff line
/*
 * Generic OPP debugfs interface
 *
 * Copyright (C) 2015-2016 Viresh Kumar <viresh.kumar@linaro.org>
 *
 * 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/debugfs.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/limits.h>

#include "opp.h"

static struct dentry *rootdir;

static void opp_set_dev_name(const struct device *dev, char *name)
{
	if (dev->parent)
		snprintf(name, NAME_MAX, "%s-%s", dev_name(dev->parent),
			 dev_name(dev));
	else
		snprintf(name, NAME_MAX, "%s", dev_name(dev));
}

void opp_debug_remove_one(struct dev_pm_opp *opp)
{
	debugfs_remove_recursive(opp->dentry);
}

int opp_debug_create_one(struct dev_pm_opp *opp, struct opp_table *opp_table)
{
	struct dentry *pdentry = opp_table->dentry;
	struct dentry *d;
	char name[25];	/* 20 chars for 64 bit value + 5 (opp:\0) */

	/* Rate is unique to each OPP, use it to give opp-name */
	snprintf(name, sizeof(name), "opp:%lu", opp->rate);

	/* Create per-opp directory */
	d = debugfs_create_dir(name, pdentry);
	if (!d)
		return -ENOMEM;

	if (!debugfs_create_bool("available", S_IRUGO, d, &opp->available))
		return -ENOMEM;

	if (!debugfs_create_bool("dynamic", S_IRUGO, d, &opp->dynamic))
		return -ENOMEM;

	if (!debugfs_create_bool("turbo", S_IRUGO, d, &opp->turbo))
		return -ENOMEM;

	if (!debugfs_create_bool("suspend", S_IRUGO, d, &opp->suspend))
		return -ENOMEM;

	if (!debugfs_create_ulong("rate_hz", S_IRUGO, d, &opp->rate))
		return -ENOMEM;

	if (!debugfs_create_ulong("u_volt_target", S_IRUGO, d, &opp->u_volt))
		return -ENOMEM;

	if (!debugfs_create_ulong("u_volt_min", S_IRUGO, d, &opp->u_volt_min))
		return -ENOMEM;

	if (!debugfs_create_ulong("u_volt_max", S_IRUGO, d, &opp->u_volt_max))
		return -ENOMEM;

	if (!debugfs_create_ulong("u_amp", S_IRUGO, d, &opp->u_amp))
		return -ENOMEM;

	if (!debugfs_create_ulong("clock_latency_ns", S_IRUGO, d,
				  &opp->clock_latency_ns))
		return -ENOMEM;

	opp->dentry = d;
	return 0;
}

static int opp_list_debug_create_dir(struct opp_device *opp_dev,
				     struct opp_table *opp_table)
{
	const struct device *dev = opp_dev->dev;
	struct dentry *d;

	opp_set_dev_name(dev, opp_table->dentry_name);

	/* Create device specific directory */
	d = debugfs_create_dir(opp_table->dentry_name, rootdir);
	if (!d) {
		dev_err(dev, "%s: Failed to create debugfs dir\n", __func__);
		return -ENOMEM;
	}

	opp_dev->dentry = d;
	opp_table->dentry = d;

	return 0;
}

static int opp_list_debug_create_link(struct opp_device *opp_dev,
				      struct opp_table *opp_table)
{
	const struct device *dev = opp_dev->dev;
	char name[NAME_MAX];
	struct dentry *d;

	opp_set_dev_name(opp_dev->dev, name);

	/* Create device specific directory link */
	d = debugfs_create_symlink(name, rootdir, opp_table->dentry_name);
	if (!d) {
		dev_err(dev, "%s: Failed to create link\n", __func__);
		return -ENOMEM;
	}

	opp_dev->dentry = d;

	return 0;
}

/**
 * opp_debug_register - add a device opp node to the debugfs 'opp' directory
 * @opp_dev: opp-dev pointer for device
 * @opp_table: the device-opp being added
 *
 * Dynamically adds device specific directory in debugfs 'opp' directory. If the
 * device-opp is shared with other devices, then links will be created for all
 * devices except the first.
 *
 * Return: 0 on success, otherwise negative error.
 */
int opp_debug_register(struct opp_device *opp_dev, struct opp_table *opp_table)
{
	if (!rootdir) {
		pr_debug("%s: Uninitialized rootdir\n", __func__);
		return -EINVAL;
	}

	if (opp_table->dentry)
		return opp_list_debug_create_link(opp_dev, opp_table);

	return opp_list_debug_create_dir(opp_dev, opp_table);
}

static void opp_migrate_dentry(struct opp_device *opp_dev,
			       struct opp_table *opp_table)
{
	struct opp_device *new_dev;
	const struct device *dev;
	struct dentry *dentry;

	/* Look for next opp-dev */
	list_for_each_entry(new_dev, &opp_table->dev_list, node)
		if (new_dev != opp_dev)
			break;

	/* new_dev is guaranteed to be valid here */
	dev = new_dev->dev;
	debugfs_remove_recursive(new_dev->dentry);

	opp_set_dev_name(dev, opp_table->dentry_name);

	dentry = debugfs_rename(rootdir, opp_dev->dentry, rootdir,
				opp_table->dentry_name);
	if (!dentry) {
		dev_err(dev, "%s: Failed to rename link from: %s to %s\n",
			__func__, dev_name(opp_dev->dev), dev_name(dev));
		return;
	}

	new_dev->dentry = dentry;
	opp_table->dentry = dentry;
}

/**
 * opp_debug_unregister - remove a device opp node from debugfs opp directory
 * @opp_dev: opp-dev pointer for device
 * @opp_table: the device-opp being removed
 *
 * Dynamically removes device specific directory from debugfs 'opp' directory.
 */
void opp_debug_unregister(struct opp_device *opp_dev,
			  struct opp_table *opp_table)
{
	if (opp_dev->dentry == opp_table->dentry) {
		/* Move the real dentry object under another device */
		if (!list_is_singular(&opp_table->dev_list)) {
			opp_migrate_dentry(opp_dev, opp_table);
			goto out;
		}
		opp_table->dentry = NULL;
	}

	debugfs_remove_recursive(opp_dev->dentry);

out:
	opp_dev->dentry = NULL;
}

static int __init opp_debug_init(void)
{
	/* Create /sys/kernel/debug/opp directory */
	rootdir = debugfs_create_dir("opp", NULL);
	if (!rootdir) {
		pr_err("%s: Failed to create root directory\n", __func__);
		return -ENOMEM;
	}

	return 0;
}
core_initcall(opp_debug_init);
Loading