Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
# SPDX-License-Identifier: GPL-2.0-only
config PM_OPP
bool
help
SOCs have a standard set of tuples consisting of frequency and
voltage pairs that the device will support per voltage domain. This
is called Operating Performance Point or OPP. The actual definitions
of OPP varies over silicon within the same family of devices.
OPP layer organizes the data internally using device pointers
representing individual voltage domains and provides SOC
implementations a ready to use framework to manage OPPs.
For more information, read <file:Documentation/power/opp.rst>
+6
View File
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-only
ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
obj-y += core.o cpu.o
obj-$(CONFIG_OF) += of.o
obj-$(CONFIG_DEBUG_FS) += debugfs.o
obj-$(CONFIG_ARM_TI_CPUFREQ) += ti-opp-supply.o
File diff suppressed because it is too large Load Diff
+228
View File
@@ -0,0 +1,228 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Generic OPP helper interface for CPU device
*
* Copyright (C) 2009-2014 Texas Instruments Incorporated.
* Nishanth Menon
* Romit Dasgupta
* Kevin Hilman
*/
#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/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
* @opp_table: Cpufreq table returned back to caller
*
* Generate a cpufreq table for a provided device- this assumes that the
* 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
* 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.
*/
int dev_pm_opp_init_cpufreq_table(struct device *dev,
struct cpufreq_frequency_table **opp_table)
{
struct cpufreq_frequency_table *freq_table = NULL;
int i, max_opps, ret = 0;
unsigned long rate;
max_opps = dev_pm_opp_get_opp_count(dev);
if (max_opps <= 0)
return max_opps ? max_opps : -ENODATA;
freq_table = kzalloc_objs(*freq_table, (max_opps + 1));
if (!freq_table)
return -ENOMEM;
for (i = 0, rate = 0; i < max_opps; i++, rate++) {
/* find next rate */
struct dev_pm_opp *opp __free(put_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;
*opp_table = &freq_table[0];
out:
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
* @opp_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 **opp_table)
{
if (!opp_table)
return;
kfree(*opp_table);
*opp_table = NULL;
}
EXPORT_SYMBOL_GPL(dev_pm_opp_free_cpufreq_table);
#endif /* CONFIG_CPU_FREQ */
void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask,
int last_cpu)
{
struct device *cpu_dev;
int cpu;
WARN_ON(cpumask_empty(cpumask));
for_each_cpu(cpu, cpumask) {
if (cpu == last_cpu)
break;
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_remove_table(cpu_dev);
}
}
/**
* dev_pm_opp_cpumask_remove_table() - Removes OPP table for @cpumask
* @cpumask: cpumask for which OPP table needs to be removed
*
* This removes the OPP tables for CPUs present in the @cpumask.
* This should be used to remove all the OPPs entries associated with
* the cpus in @cpumask.
*/
void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
{
_dev_pm_opp_cpumask_remove_table(cpumask, -1);
}
EXPORT_SYMBOL_GPL(dev_pm_opp_cpumask_remove_table);
/**
* dev_pm_opp_set_sharing_cpus() - Mark OPP table as shared by few CPUs
* @cpu_dev: CPU device for which we do this operation
* @cpumask: cpumask of the CPUs which share the OPP table with @cpu_dev
*
* This marks OPP table of the @cpu_dev as shared by the CPUs present in
* @cpumask.
*
* Returns -ENODEV if OPP table isn't already present.
*/
int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev,
const struct cpumask *cpumask)
{
struct opp_device *opp_dev;
struct device *dev;
int cpu;
struct opp_table *opp_table __free(put_opp_table) =
_find_opp_table(cpu_dev);
if (IS_ERR(opp_table))
return PTR_ERR(opp_table);
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;
}
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;
}
/* Mark opp-table as multiple CPUs are sharing it now */
opp_table->shared_opp = OPP_TABLE_ACCESS_SHARED;
}
return 0;
}
EXPORT_SYMBOL_GPL(dev_pm_opp_set_sharing_cpus);
/**
* dev_pm_opp_get_sharing_cpus() - Get cpumask of CPUs sharing OPPs with @cpu_dev
* @cpu_dev: CPU device for which we do this operation
* @cpumask: cpumask to update with information of sharing CPUs
*
* This updates the @cpumask with CPUs that are sharing OPPs with @cpu_dev.
*
* Returns -ENODEV if OPP table isn't already present and -EINVAL if the OPP
* table's status is access-unknown.
*/
int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
{
struct opp_device *opp_dev;
struct opp_table *opp_table __free(put_opp_table) =
_find_opp_table(cpu_dev);
if (IS_ERR(opp_table))
return PTR_ERR(opp_table);
if (opp_table->shared_opp == OPP_TABLE_ACCESS_UNKNOWN)
return -EINVAL;
cpumask_clear(cpumask);
if (opp_table->shared_opp == OPP_TABLE_ACCESS_SHARED) {
guard(mutex)(&opp_table->lock);
list_for_each_entry(opp_dev, &opp_table->dev_list, node)
cpumask_set_cpu(opp_dev->dev->id, cpumask);
} else {
cpumask_set_cpu(cpu_dev->id, cpumask);
}
return 0;
}
EXPORT_SYMBOL_GPL(dev_pm_opp_get_sharing_cpus);
+281
View File
@@ -0,0 +1,281 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Generic OPP debugfs interface
*
* Copyright (C) 2015-2016 Viresh Kumar <viresh.kumar@linaro.org>
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/debugfs.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/of.h>
#include <linux/init.h>
#include <linux/limits.h>
#include <linux/slab.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);
}
static ssize_t bw_name_read(struct file *fp, char __user *userbuf,
size_t count, loff_t *ppos)
{
struct icc_path *path = fp->private_data;
const char *name = icc_get_name(path);
char buf[64];
int i = 0;
if (name)
i = scnprintf(buf, sizeof(buf), "%.62s\n", name);
return simple_read_from_buffer(userbuf, count, ppos, buf, i);
}
static const struct file_operations bw_name_fops = {
.open = simple_open,
.read = bw_name_read,
.llseek = default_llseek,
};
static void opp_debug_create_bw(struct dev_pm_opp *opp,
struct opp_table *opp_table,
struct dentry *pdentry)
{
struct dentry *d;
char name[] = "icc-path-XXXXXXXXXXX"; /* Integers can take 11 chars max */
int i;
for (i = 0; i < opp_table->path_count; i++) {
snprintf(name, sizeof(name), "icc-path-%d", i);
/* Create per-path directory */
d = debugfs_create_dir(name, pdentry);
debugfs_create_file("name", S_IRUGO, d, opp_table->paths[i],
&bw_name_fops);
debugfs_create_u32("peak_bw", S_IRUGO, d,
&opp->bandwidth[i].peak);
debugfs_create_u32("avg_bw", S_IRUGO, d,
&opp->bandwidth[i].avg);
}
}
static void opp_debug_create_clks(struct dev_pm_opp *opp,
struct opp_table *opp_table,
struct dentry *pdentry)
{
char name[] = "rate_hz_XXXXXXXXXXX"; /* Integers can take 11 chars max */
int i;
if (opp_table->clk_count == 1) {
debugfs_create_ulong("rate_hz", S_IRUGO, pdentry, &opp->rates[0]);
return;
}
for (i = 0; i < opp_table->clk_count; i++) {
snprintf(name, sizeof(name), "rate_hz_%d", i);
debugfs_create_ulong(name, S_IRUGO, pdentry, &opp->rates[i]);
}
}
static void opp_debug_create_supplies(struct dev_pm_opp *opp,
struct opp_table *opp_table,
struct dentry *pdentry)
{
struct dentry *d;
int i;
for (i = 0; i < opp_table->regulator_count; i++) {
char name[] = "supply-XXXXXXXXXXX"; /* Integers can take 11 chars max */
snprintf(name, sizeof(name), "supply-%d", i);
/* Create per-opp directory */
d = debugfs_create_dir(name, pdentry);
debugfs_create_ulong("u_volt_target", S_IRUGO, d,
&opp->supplies[i].u_volt);
debugfs_create_ulong("u_volt_min", S_IRUGO, d,
&opp->supplies[i].u_volt_min);
debugfs_create_ulong("u_volt_max", S_IRUGO, d,
&opp->supplies[i].u_volt_max);
debugfs_create_ulong("u_amp", S_IRUGO, d,
&opp->supplies[i].u_amp);
debugfs_create_ulong("u_watt", S_IRUGO, d,
&opp->supplies[i].u_watt);
}
}
void 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[36]; /* "opp:"(4) + u64(20) + "-" (1) + u32(10) + NULL(1) */
/*
* Get directory name for OPP.
*
* - Normally rate is unique to each OPP, use it to get unique opp-name,
* together with performance level if available.
* - For some devices rate isn't available or there are multiple, use
* index instead for them.
*/
if (likely(opp_table->clk_count == 1 && opp->rates[0])) {
if (opp->level == OPP_LEVEL_UNSET)
snprintf(name, sizeof(name), "opp:%lu", opp->rates[0]);
else
snprintf(name, sizeof(name), "opp:%lu-%u", opp->rates[0], opp->level);
} else {
snprintf(name, sizeof(name), "opp:%u", _get_opp_count(opp_table));
}
/* Create per-opp directory */
d = debugfs_create_dir(name, pdentry);
debugfs_create_bool("available", S_IRUGO, d, &opp->available);
debugfs_create_bool("dynamic", S_IRUGO, d, &opp->dynamic);
debugfs_create_bool("turbo", S_IRUGO, d, &opp->turbo);
debugfs_create_bool("suspend", S_IRUGO, d, &opp->suspend);
debugfs_create_u32("level", S_IRUGO, d, &opp->level);
debugfs_create_ulong("clock_latency_ns", S_IRUGO, d,
&opp->clock_latency_ns);
opp->of_name = of_node_full_name(opp->np);
debugfs_create_str("of_name", S_IRUGO, d, (char **)&opp->of_name);
opp_debug_create_clks(opp, opp_table, d);
opp_debug_create_supplies(opp, opp_table, d);
opp_debug_create_bw(opp, opp_table, d);
opp->dentry = d;
}
static void 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);
opp_dev->dentry = d;
opp_table->dentry = d;
}
static void opp_list_debug_create_link(struct opp_device *opp_dev,
struct opp_table *opp_table)
{
char name[NAME_MAX];
opp_set_dev_name(opp_dev->dev, name);
/* Create device specific directory link */
opp_dev->dentry = debugfs_create_symlink(name, rootdir,
opp_table->dentry_name);
}
/**
* 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.
*/
void opp_debug_register(struct opp_device *opp_dev, struct opp_table *opp_table)
{
if (opp_table->dentry)
opp_list_debug_create_link(opp_dev, opp_table);
else
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 = NULL, *iter;
const struct device *dev;
int err;
/* Look for next opp-dev */
list_for_each_entry(iter, &opp_table->dev_list, node)
if (iter != opp_dev) {
new_dev = iter;
break;
}
BUG_ON(!new_dev);
/* 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);
err = debugfs_change_name(opp_dev->dentry, "%s", opp_table->dentry_name);
if (err) {
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 = opp_table->dentry = opp_dev->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);
return 0;
}
core_initcall(opp_debug_init);
File diff suppressed because it is too large Load Diff
+302
View File
@@ -0,0 +1,302 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Generic OPP Interface
*
* Copyright (C) 2009-2010 Texas Instruments Incorporated.
* Nishanth Menon
* Romit Dasgupta
* Kevin Hilman
*/
#ifndef __DRIVER_OPP_H__
#define __DRIVER_OPP_H__
#include <linux/device.h>
#include <linux/interconnect.h>
#include <linux/kernel.h>
#include <linux/kref.h>
#include <linux/list.h>
#include <linux/limits.h>
#include <linux/pm_opp.h>
#include <linux/notifier.h>
struct clk;
struct regulator;
/* Lock to allow exclusive modification to the device and opp lists */
extern struct mutex opp_table_lock;
extern struct list_head opp_tables;
/* OPP Config flags */
#define OPP_CONFIG_CLK BIT(0)
#define OPP_CONFIG_REGULATOR BIT(1)
#define OPP_CONFIG_REGULATOR_HELPER BIT(2)
#define OPP_CONFIG_PROP_NAME BIT(3)
#define OPP_CONFIG_SUPPORTED_HW BIT(4)
#define OPP_CONFIG_REQUIRED_DEV BIT(5)
/**
* struct opp_config_data - data for set config operations
* @opp_table: OPP table
* @flags: OPP config flags
* @required_dev_index: The position in the array of required_devs
*
* This structure stores the OPP config information for each OPP table
* configuration by the callers.
*/
struct opp_config_data {
struct opp_table *opp_table;
unsigned int flags;
unsigned int required_dev_index;
};
/**
* struct dev_pm_opp_icc_bw - Interconnect bandwidth values
* @avg: Average bandwidth corresponding to this OPP (in icc units)
* @peak: Peak bandwidth corresponding to this OPP (in icc units)
*
* This structure stores the bandwidth values for a single interconnect path.
*/
struct dev_pm_opp_icc_bw {
u32 avg;
u32 peak;
};
/*
* Internal data structure organization with the OPP layer library is as
* follows:
* opp_tables (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 opp_table structure while each opp
* is represented by the opp structure.
*/
/**
* struct dev_pm_opp - Generic OPP description structure
* @node: opp table 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.
* IMPORTANT: the opp nodes should be maintained in increasing
* order.
* @kref: for reference count of the OPP.
* @available: true/false - marks if this OPP as available or not
* @dynamic: not-created from static DT entries.
* @turbo: true if turbo (boost) OPP
* @suspend: true if suspend OPP
* @removed: flag indicating that OPP's reference is dropped by OPP core.
* @rates: Frequencies in hertz
* @level: Performance level
* @supplies: Power supplies voltage/current values
* @bandwidth: Interconnect bandwidth values
* @clock_latency_ns: Latency (in nanoseconds) of switching to this OPP's
* frequency from any other OPP's frequency.
* @required_opps: List of OPPs that are required by this OPP.
* @opp_table: points back to the opp_table struct this opp belongs to
* @np: OPP's device node.
* @dentry: debugfs dentry pointer (per opp)
*
* This structure stores the OPP information for a given device.
*/
struct dev_pm_opp {
struct list_head node;
struct kref kref;
bool available;
bool dynamic;
bool turbo;
bool suspend;
bool removed;
unsigned long *rates;
unsigned int level;
struct dev_pm_opp_supply *supplies;
struct dev_pm_opp_icc_bw *bandwidth;
unsigned long clock_latency_ns;
struct dev_pm_opp **required_opps;
struct opp_table *opp_table;
struct device_node *np;
#ifdef CONFIG_DEBUG_FS
struct dentry *dentry;
const char *of_name;
#endif
};
/**
* struct opp_device - devices managed by 'struct opp_table'
* @node: list node
* @dev: device to which the struct object belongs
* @dentry: debugfs dentry pointer (per device)
*
* This is an internal data structure maintaining the devices that are managed
* by 'struct opp_table'.
*/
struct opp_device {
struct list_head node;
const struct device *dev;
#ifdef CONFIG_DEBUG_FS
struct dentry *dentry;
#endif
};
enum opp_table_access {
OPP_TABLE_ACCESS_UNKNOWN = 0,
OPP_TABLE_ACCESS_EXCLUSIVE = 1,
OPP_TABLE_ACCESS_SHARED = 2,
};
/**
* struct opp_table - Device opp structure
* @node: table node - contains the devices with OPPs that
* have been registered. Nodes once added are not modified in this
* table.
* @head: notifier head to notify the OPP availability changes.
* @dev_list: list of devices that share these OPPs
* @opp_list: table of opps
* @kref: for reference count of the table.
* @lock: mutex protecting the opp_list and dev_list.
* @np: struct device_node pointer for opp's DT node.
* @clock_latency_ns_max: Max clock latency in nanoseconds.
* @parsed_static_opps: Count of devices for which OPPs are initialized from DT.
* @shared_opp: OPP is shared between multiple devices.
* @current_rate_single_clk: Currently configured frequency for single clk.
* @current_opp: Currently configured OPP for the table.
* @suspend_opp: Pointer to OPP to be used during device suspend.
* @required_opp_tables: List of device OPP tables that are required by OPPs in
* this table.
* @required_devs: List of devices for required OPP tables.
* @required_opp_count: Number of required devices.
* @supported_hw: Array of version number to support.
* @supported_hw_count: Number of elements in supported_hw array.
* @prop_name: A name to postfix to many DT properties, while parsing them.
* @config_clks: Platform specific config_clks() callback.
* @clks: Device's clock handles, for multiple clocks.
* @clk: Device's clock handle, for single clock.
* @clk_count: Number of clocks.
* @config_regulators: Platform specific config_regulators() callback.
* @regulators: Supply regulators
* @regulator_count: Number of power supply regulators. Its value can be -1
* (uninitialized), 0 (no opp-microvolt property) or > 0 (has opp-microvolt
* property).
* @paths: Interconnect path handles
* @path_count: Number of interconnect paths
* @enabled: Set to true if the device's resources are enabled/configured.
* @is_genpd: Marks if the OPP table belongs to a genpd.
* @dentry: debugfs dentry pointer of the real device directory (not links).
* @dentry_name: Name of the real dentry.
*
* @voltage_tolerance_v1: In percentage, for v1 bindings only.
*
* 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.
*/
struct opp_table {
struct list_head node, lazy;
struct blocking_notifier_head head;
struct list_head dev_list;
struct list_head opp_list;
struct kref kref;
struct mutex lock;
struct device_node *np;
unsigned long clock_latency_ns_max;
/* For backward compatibility with v1 bindings */
unsigned int voltage_tolerance_v1;
unsigned int parsed_static_opps;
enum opp_table_access shared_opp;
unsigned long current_rate_single_clk;
struct dev_pm_opp *current_opp;
struct dev_pm_opp *suspend_opp;
struct opp_table **required_opp_tables;
struct device **required_devs;
unsigned int required_opp_count;
unsigned int *supported_hw;
unsigned int supported_hw_count;
const char *prop_name;
config_clks_t config_clks;
struct clk **clks;
struct clk *clk;
int clk_count;
config_regulators_t config_regulators;
struct regulator **regulators;
int regulator_count;
struct icc_path **paths;
unsigned int path_count;
bool enabled;
bool is_genpd;
#ifdef CONFIG_DEBUG_FS
struct dentry *dentry;
char dentry_name[NAME_MAX];
#endif
};
/* Routines internal to opp core */
bool _opp_remove_all_static(struct opp_table *opp_table);
int _get_opp_count(struct opp_table *opp_table);
struct opp_table *_find_opp_table(struct device *dev);
struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table *opp_table);
struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table);
void _opp_free(struct dev_pm_opp *opp);
int _opp_compare_key(struct opp_table *opp_table, struct dev_pm_opp *opp1, struct dev_pm_opp *opp2);
int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table);
int _opp_add_v1(struct opp_table *opp_table, struct device *dev, struct dev_pm_opp_data *data, bool dynamic);
void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, int last_cpu);
struct opp_table *_add_opp_table_indexed(struct device *dev, int index, bool getclk);
void _required_opps_available(struct dev_pm_opp *opp, int count);
static inline bool lazy_linking_pending(struct opp_table *opp_table)
{
return unlikely(!list_empty(&opp_table->lazy));
}
#ifdef CONFIG_OF
void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index);
void _of_clear_opp_table(struct opp_table *opp_table);
struct opp_table *_managed_opp(struct device *dev, int index);
void _of_clear_opp(struct opp_table *opp_table, struct dev_pm_opp *opp);
#else
static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index) {}
static inline void _of_clear_opp_table(struct opp_table *opp_table) {}
static inline struct opp_table *_managed_opp(struct device *dev, int index) { return NULL; }
static inline void _of_clear_opp(struct opp_table *opp_table, struct dev_pm_opp *opp) {}
#endif
#ifdef CONFIG_DEBUG_FS
void opp_debug_remove_one(struct dev_pm_opp *opp);
void opp_debug_create_one(struct dev_pm_opp *opp, struct opp_table *opp_table);
void opp_debug_register(struct opp_device *opp_dev, struct opp_table *opp_table);
void opp_debug_unregister(struct opp_device *opp_dev, struct opp_table *opp_table);
#else
static inline void opp_debug_remove_one(struct dev_pm_opp *opp) {}
static inline void opp_debug_create_one(struct dev_pm_opp *opp,
struct opp_table *opp_table) { }
static inline void opp_debug_register(struct opp_device *opp_dev,
struct opp_table *opp_table) { }
static inline void opp_debug_unregister(struct opp_device *opp_dev,
struct opp_table *opp_table)
{ }
#endif /* DEBUG_FS */
#endif /* __DRIVER_OPP_H__ */
+414
View File
@@ -0,0 +1,414 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2016-2017 Texas Instruments Incorporated - https://www.ti.com/
* Nishanth Menon <nm@ti.com>
* Dave Gerlach <d-gerlach@ti.com>
*
* TI OPP supply driver that provides override into the regulator control
* for generic opp core to handle devices with ABB regulator and/or
* SmartReflex Class0.
*/
#include <linux/clk.h>
#include <linux/cpufreq.h>
#include <linux/device.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/notifier.h>
#include <linux/of_device.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pm_opp.h>
#include <linux/property.h>
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
/**
* struct ti_opp_supply_optimum_voltage_table - optimized voltage table
* @reference_uv: reference voltage (usually Nominal voltage)
* @optimized_uv: Optimized voltage from efuse
*/
struct ti_opp_supply_optimum_voltage_table {
unsigned int reference_uv;
unsigned int optimized_uv;
};
/**
* struct ti_opp_supply_data - OMAP specific opp supply data
* @vdd_table: Optimized voltage mapping table
* @num_vdd_table: number of entries in vdd_table
* @vdd_absolute_max_voltage_uv: absolute maximum voltage in UV for the supply
* @old_supplies: Placeholder for supplies information for old OPP.
* @new_supplies: Placeholder for supplies information for new OPP.
*/
struct ti_opp_supply_data {
struct ti_opp_supply_optimum_voltage_table *vdd_table;
u32 num_vdd_table;
u32 vdd_absolute_max_voltage_uv;
struct dev_pm_opp_supply old_supplies[2];
struct dev_pm_opp_supply new_supplies[2];
};
static struct ti_opp_supply_data opp_data;
/**
* struct ti_opp_supply_of_data - device tree match data
* @flags: specific type of opp supply
* @efuse_voltage_mask: mask required for efuse register representing voltage
* @efuse_voltage_uv: Are the efuse entries in micro-volts? if not, assume
* milli-volts.
*/
struct ti_opp_supply_of_data {
#define OPPDM_EFUSE_CLASS0_OPTIMIZED_VOLTAGE BIT(1)
#define OPPDM_HAS_NO_ABB BIT(2)
const u8 flags;
const u32 efuse_voltage_mask;
const bool efuse_voltage_uv;
};
/**
* _store_optimized_voltages() - store optimized voltages
* @dev: ti opp supply device for which we need to store info
* @data: data specific to the device
*
* Picks up efuse based optimized voltages for VDD unique per device and
* stores it in internal data structure for use during transition requests.
*
* Return: If successful, 0, else appropriate error value.
*/
static int _store_optimized_voltages(struct device *dev,
struct ti_opp_supply_data *data)
{
void __iomem *base;
struct property *prop;
struct resource *res;
const __be32 *val;
int proplen, i;
int ret = 0;
struct ti_opp_supply_optimum_voltage_table *table;
const struct ti_opp_supply_of_data *of_data = dev_get_drvdata(dev);
/* pick up Efuse based voltages */
res = platform_get_resource(to_platform_device(dev), IORESOURCE_MEM, 0);
if (!res) {
dev_err(dev, "Unable to get IO resource\n");
ret = -ENODEV;
goto out_map;
}
base = ioremap(res->start, resource_size(res));
if (!base) {
dev_err(dev, "Unable to map Efuse registers\n");
ret = -ENOMEM;
goto out_map;
}
/* Fetch efuse-settings. */
prop = of_find_property(dev->of_node, "ti,efuse-settings", NULL);
if (!prop) {
dev_err(dev, "No 'ti,efuse-settings' property found\n");
ret = -EINVAL;
goto out;
}
proplen = prop->length / sizeof(int);
data->num_vdd_table = proplen / 2;
/* Verify for corrupted OPP entries in dt */
if (data->num_vdd_table * 2 * sizeof(int) != prop->length) {
dev_err(dev, "Invalid 'ti,efuse-settings'\n");
ret = -EINVAL;
goto out;
}
ret = of_property_read_u32(dev->of_node, "ti,absolute-max-voltage-uv",
&data->vdd_absolute_max_voltage_uv);
if (ret) {
dev_err(dev, "ti,absolute-max-voltage-uv is missing\n");
ret = -EINVAL;
goto out;
}
table = kzalloc_objs(*data->vdd_table, data->num_vdd_table);
if (!table) {
ret = -ENOMEM;
goto out;
}
data->vdd_table = table;
val = prop->value;
for (i = 0; i < data->num_vdd_table; i++, table++) {
u32 efuse_offset;
u32 tmp;
table->reference_uv = be32_to_cpup(val++);
efuse_offset = be32_to_cpup(val++);
tmp = readl(base + efuse_offset);
tmp &= of_data->efuse_voltage_mask;
tmp >>= __ffs(of_data->efuse_voltage_mask);
table->optimized_uv = of_data->efuse_voltage_uv ? tmp :
tmp * 1000;
dev_dbg(dev, "[%d] efuse=0x%08x volt_table=%d vset=%d\n",
i, efuse_offset, table->reference_uv,
table->optimized_uv);
/*
* Some older samples might not have optimized efuse
* Use reference voltage for those - just add debug message
* for them.
*/
if (!table->optimized_uv) {
dev_dbg(dev, "[%d] efuse=0x%08x volt_table=%d:vset0\n",
i, efuse_offset, table->reference_uv);
table->optimized_uv = table->reference_uv;
}
}
out:
iounmap(base);
out_map:
return ret;
}
/**
* _free_optimized_voltages() - free resources for optvoltages
* @dev: device for which we need to free info
* @data: data specific to the device
*/
static void _free_optimized_voltages(struct device *dev,
struct ti_opp_supply_data *data)
{
kfree(data->vdd_table);
data->vdd_table = NULL;
data->num_vdd_table = 0;
}
/**
* _get_optimal_vdd_voltage() - Finds optimal voltage for the supply
* @dev: device for which we need to find info
* @data: data specific to the device
* @reference_uv: reference voltage (OPP voltage) for which we need value
*
* Return: if a match is found, return optimized voltage, else return
* reference_uv, also return reference_uv if no optimization is needed.
*/
static int _get_optimal_vdd_voltage(struct device *dev,
struct ti_opp_supply_data *data,
int reference_uv)
{
int i;
struct ti_opp_supply_optimum_voltage_table *table;
if (!data->num_vdd_table)
return reference_uv;
table = data->vdd_table;
if (!table)
return -EINVAL;
/* Find a exact match - this list is usually very small */
for (i = 0; i < data->num_vdd_table; i++, table++)
if (table->reference_uv == reference_uv)
return table->optimized_uv;
/* IF things are screwed up, we'd make a mess on console.. ratelimit */
dev_err_ratelimited(dev, "%s: Failed optimized voltage match for %d\n",
__func__, reference_uv);
return reference_uv;
}
static int _opp_set_voltage(struct device *dev,
struct dev_pm_opp_supply *supply,
int new_target_uv, struct regulator *reg,
char *reg_name)
{
int ret;
unsigned long vdd_uv, uv_max;
if (new_target_uv)
vdd_uv = new_target_uv;
else
vdd_uv = supply->u_volt;
/*
* If we do have an absolute max voltage specified, then we should
* use that voltage instead to allow for cases where the voltage rails
* are ganged (example if we set the max for an opp as 1.12v, and
* the absolute max is 1.5v, for another rail to get 1.25v, it cannot
* be achieved if the regulator is constrainted to max of 1.12v, even
* if it can function at 1.25v
*/
if (opp_data.vdd_absolute_max_voltage_uv)
uv_max = opp_data.vdd_absolute_max_voltage_uv;
else
uv_max = supply->u_volt_max;
if (vdd_uv > uv_max ||
vdd_uv < supply->u_volt_min ||
supply->u_volt_min > uv_max) {
dev_warn(dev,
"Invalid range voltages [Min:%lu target:%lu Max:%lu]\n",
supply->u_volt_min, vdd_uv, uv_max);
return -EINVAL;
}
dev_dbg(dev, "%s scaling to %luuV[min %luuV max %luuV]\n", reg_name,
vdd_uv, supply->u_volt_min,
uv_max);
ret = regulator_set_voltage_triplet(reg,
supply->u_volt_min,
vdd_uv,
uv_max);
if (ret) {
dev_err(dev, "%s failed for %luuV[min %luuV max %luuV]\n",
reg_name, vdd_uv, supply->u_volt_min,
uv_max);
return ret;
}
return 0;
}
/* Do the opp supply transition */
static int ti_opp_config_regulators(struct device *dev,
struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp,
struct regulator **regulators, unsigned int count)
{
struct dev_pm_opp_supply *old_supply_vdd = &opp_data.old_supplies[0];
struct dev_pm_opp_supply *old_supply_vbb = &opp_data.old_supplies[1];
struct dev_pm_opp_supply *new_supply_vdd = &opp_data.new_supplies[0];
struct dev_pm_opp_supply *new_supply_vbb = &opp_data.new_supplies[1];
struct regulator *vdd_reg = regulators[0];
struct regulator *vbb_reg = regulators[1];
unsigned long old_freq, freq;
int vdd_uv;
int ret;
/* We must have two regulators here */
WARN_ON(count != 2);
/* Fetch supplies and freq information from OPP core */
ret = dev_pm_opp_get_supplies(new_opp, opp_data.new_supplies);
WARN_ON(ret);
old_freq = dev_pm_opp_get_freq(old_opp);
freq = dev_pm_opp_get_freq(new_opp);
WARN_ON(!old_freq || !freq);
vdd_uv = _get_optimal_vdd_voltage(dev, &opp_data,
new_supply_vdd->u_volt);
if (new_supply_vdd->u_volt_min < vdd_uv)
new_supply_vdd->u_volt_min = vdd_uv;
/* Scaling up? Scale voltage before frequency */
if (freq > old_freq) {
ret = _opp_set_voltage(dev, new_supply_vdd, vdd_uv, vdd_reg,
"vdd");
if (ret)
goto restore_voltage;
ret = _opp_set_voltage(dev, new_supply_vbb, 0, vbb_reg, "vbb");
if (ret)
goto restore_voltage;
} else {
ret = _opp_set_voltage(dev, new_supply_vbb, 0, vbb_reg, "vbb");
if (ret)
goto restore_voltage;
ret = _opp_set_voltage(dev, new_supply_vdd, vdd_uv, vdd_reg,
"vdd");
if (ret)
goto restore_voltage;
}
return 0;
restore_voltage:
/* Fetch old supplies information only if required */
ret = dev_pm_opp_get_supplies(old_opp, opp_data.old_supplies);
WARN_ON(ret);
/* This shouldn't harm even if the voltages weren't updated earlier */
if (old_supply_vdd->u_volt) {
ret = _opp_set_voltage(dev, old_supply_vbb, 0, vbb_reg, "vbb");
if (ret)
return ret;
ret = _opp_set_voltage(dev, old_supply_vdd, 0, vdd_reg,
"vdd");
if (ret)
return ret;
}
return ret;
}
static const struct ti_opp_supply_of_data omap_generic_of_data = {
};
static const struct ti_opp_supply_of_data omap_omap5_of_data = {
.flags = OPPDM_EFUSE_CLASS0_OPTIMIZED_VOLTAGE,
.efuse_voltage_mask = 0xFFF,
.efuse_voltage_uv = false,
};
static const struct ti_opp_supply_of_data omap_omap5core_of_data = {
.flags = OPPDM_EFUSE_CLASS0_OPTIMIZED_VOLTAGE | OPPDM_HAS_NO_ABB,
.efuse_voltage_mask = 0xFFF,
.efuse_voltage_uv = false,
};
static const struct of_device_id ti_opp_supply_of_match[] = {
{.compatible = "ti,omap-opp-supply", .data = &omap_generic_of_data},
{.compatible = "ti,omap5-opp-supply", .data = &omap_omap5_of_data},
{.compatible = "ti,omap5-core-opp-supply",
.data = &omap_omap5core_of_data},
{},
};
MODULE_DEVICE_TABLE(of, ti_opp_supply_of_match);
static int ti_opp_supply_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device *cpu_dev = get_cpu_device(0);
const struct ti_opp_supply_of_data *of_data;
int ret = 0;
of_data = device_get_match_data(dev);
if (!of_data) {
/* Again, unlikely.. but mistakes do happen */
dev_err(dev, "%s: Bad data in match\n", __func__);
return -EINVAL;
}
dev_set_drvdata(dev, (void *)of_data);
/* If we need optimized voltage */
if (of_data->flags & OPPDM_EFUSE_CLASS0_OPTIMIZED_VOLTAGE) {
ret = _store_optimized_voltages(dev, &opp_data);
if (ret)
return ret;
}
ret = dev_pm_opp_set_config_regulators(cpu_dev, ti_opp_config_regulators);
if (ret < 0) {
_free_optimized_voltages(dev, &opp_data);
return ret;
}
return 0;
}
static struct platform_driver ti_opp_supply_driver = {
.probe = ti_opp_supply_probe,
.driver = {
.name = "ti_opp_supply",
.of_match_table = ti_opp_supply_of_match,
},
};
module_platform_driver(ti_opp_supply_driver);
MODULE_DESCRIPTION("Texas Instruments OMAP OPP Supply driver");
MODULE_AUTHOR("Texas Instruments Inc.");
MODULE_LICENSE("GPL v2");