summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2026-04-10 12:48:32 +0200
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2026-04-10 12:48:32 +0200
commitd923f70e37310fe613883a3a4c2ea2f31246253b (patch)
treecda3a57839fc77632eddf8d0b99bb2318899b9db
parent2bd33eb50754489dc75175e730eeeb7fcfac474f (diff)
parent6e6e1e3be6d864332e520afd440bf4bbb52d0c90 (diff)
downloadlinux-d923f70e37310fe613883a3a4c2ea2f31246253b.tar.gz
linux-d923f70e37310fe613883a3a4c2ea2f31246253b.zip
Merge branch 'pm-devfreq'
Merge devfreq updates for 7.1-rc1: - Remove unneeded casting for HZ_PER_KHZ in devfreq (Andy Shevchenko) - Use _visible attribute to replace create/remove_sysfs_files() in devfreq (Pengjie Zhang) - Add Tegra114 support to activity monitor device in tegra30-devfreq as a preparation to upcoming EMC controller support (Svyatoslav Ryhel) * pm-devfreq: PM / devfreq: tegra30-devfreq: add support for Tegra114 PM / devfreq: use _visible attribute to replace create/remove_sysfs_files() PM / devfreq: Remove unneeded casting for HZ_PER_KHZ
-rw-r--r--drivers/devfreq/devfreq.c108
-rw-r--r--drivers/devfreq/tegra30-devfreq.c17
2 files changed, 74 insertions, 51 deletions
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index c0a74091b904..82dd9a43dc62 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -38,6 +38,7 @@
static struct class *devfreq_class;
static struct dentry *devfreq_debugfs;
+static const struct attribute_group gov_attr_group;
/*
* devfreq core provides delayed work based load monitoring helper
@@ -146,10 +147,9 @@ void devfreq_get_freq_range(struct devfreq *devfreq,
DEV_PM_QOS_MIN_FREQUENCY);
qos_max_freq = dev_pm_qos_read_value(devfreq->dev.parent,
DEV_PM_QOS_MAX_FREQUENCY);
- *min_freq = max(*min_freq, (unsigned long)HZ_PER_KHZ * qos_min_freq);
+ *min_freq = max(*min_freq, HZ_PER_KHZ * qos_min_freq);
if (qos_max_freq != PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE)
- *max_freq = min(*max_freq,
- (unsigned long)HZ_PER_KHZ * qos_max_freq);
+ *max_freq = min(*max_freq, HZ_PER_KHZ * qos_max_freq);
/* Apply constraints from OPP interface */
*max_freq = clamp(*max_freq, devfreq->scaling_min_freq, devfreq->scaling_max_freq);
@@ -785,11 +785,6 @@ static void devfreq_dev_release(struct device *dev)
kfree(devfreq);
}
-static void create_sysfs_files(struct devfreq *devfreq,
- const struct devfreq_governor *gov);
-static void remove_sysfs_files(struct devfreq *devfreq,
- const struct devfreq_governor *gov);
-
/**
* devfreq_add_device() - Add devfreq feature to the device
* @dev: the device to add devfreq feature.
@@ -956,7 +951,10 @@ struct devfreq *devfreq_add_device(struct device *dev,
__func__);
goto err_init;
}
- create_sysfs_files(devfreq, devfreq->governor);
+
+ err = sysfs_update_group(&devfreq->dev.kobj, &gov_attr_group);
+ if (err)
+ goto err_init;
list_add(&devfreq->node, &devfreq_list);
@@ -995,12 +993,9 @@ int devfreq_remove_device(struct devfreq *devfreq)
devfreq_cooling_unregister(devfreq->cdev);
- if (devfreq->governor) {
+ if (devfreq->governor)
devfreq->governor->event_handler(devfreq,
DEVFREQ_GOV_STOP, NULL);
- remove_sysfs_files(devfreq, devfreq->governor);
- }
-
device_unregister(&devfreq->dev);
return 0;
@@ -1460,7 +1455,6 @@ static ssize_t governor_store(struct device *dev, struct device_attribute *attr,
__func__, df->governor->name, ret);
goto out;
}
- remove_sysfs_files(df, df->governor);
/*
* Start the new governor and create the specific sysfs files
@@ -1489,7 +1483,7 @@ static ssize_t governor_store(struct device *dev, struct device_attribute *attr,
* Create the sysfs files for the new governor. But if failed to start
* the new governor, restore the sysfs files of previous governor.
*/
- create_sysfs_files(df, df->governor);
+ ret = sysfs_update_group(&df->dev.kobj, &gov_attr_group);
out:
mutex_unlock(&devfreq_list_lock);
@@ -1807,14 +1801,17 @@ static struct attribute *devfreq_attrs[] = {
&dev_attr_trans_stat.attr,
NULL,
};
-ATTRIBUTE_GROUPS(devfreq);
static ssize_t polling_interval_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct devfreq *df = to_devfreq(dev);
- if (!df->profile)
+ /* Protect against race between sysfs attrs update and read/write */
+ guard(mutex)(&devfreq_list_lock);
+
+ if (!df->profile || !df->governor ||
+ !IS_SUPPORTED_ATTR(df->governor->attrs, POLLING_INTERVAL))
return -EINVAL;
return sprintf(buf, "%d\n", df->profile->polling_ms);
@@ -1828,7 +1825,10 @@ static ssize_t polling_interval_store(struct device *dev,
unsigned int value;
int ret;
- if (!df->governor)
+ guard(mutex)(&devfreq_list_lock);
+
+ if (!df->governor ||
+ !IS_SUPPORTED_ATTR(df->governor->attrs, POLLING_INTERVAL))
return -EINVAL;
ret = sscanf(buf, "%u", &value);
@@ -1847,7 +1847,10 @@ static ssize_t timer_show(struct device *dev,
{
struct devfreq *df = to_devfreq(dev);
- if (!df->profile)
+ guard(mutex)(&devfreq_list_lock);
+
+ if (!df->profile || !df->governor ||
+ !IS_SUPPORTED_ATTR(df->governor->attrs, TIMER))
return -EINVAL;
return sprintf(buf, "%s\n", timer_name[df->profile->timer]);
@@ -1861,7 +1864,10 @@ static ssize_t timer_store(struct device *dev, struct device_attribute *attr,
int timer = -1;
int ret = 0, i;
- if (!df->governor || !df->profile)
+ guard(mutex)(&devfreq_list_lock);
+
+ if (!df->governor || !df->profile ||
+ !IS_SUPPORTED_ATTR(df->governor->attrs, TIMER))
return -EINVAL;
ret = sscanf(buf, "%16s", str_timer);
@@ -1905,37 +1911,47 @@ out:
}
static DEVICE_ATTR_RW(timer);
-#define CREATE_SYSFS_FILE(df, name) \
-{ \
- int ret; \
- ret = sysfs_create_file(&df->dev.kobj, &dev_attr_##name.attr); \
- if (ret < 0) { \
- dev_warn(&df->dev, \
- "Unable to create attr(%s)\n", "##name"); \
- } \
-} \
+static struct attribute *governor_attrs[] = {
+ &dev_attr_polling_interval.attr,
+ &dev_attr_timer.attr,
+ NULL
+};
-/* Create the specific sysfs files which depend on each governor. */
-static void create_sysfs_files(struct devfreq *devfreq,
- const struct devfreq_governor *gov)
+static umode_t gov_attr_visible(struct kobject *kobj,
+ struct attribute *attr, int n)
{
- if (IS_SUPPORTED_ATTR(gov->attrs, POLLING_INTERVAL))
- CREATE_SYSFS_FILE(devfreq, polling_interval);
- if (IS_SUPPORTED_ATTR(gov->attrs, TIMER))
- CREATE_SYSFS_FILE(devfreq, timer);
-}
+ struct device *dev = kobj_to_dev(kobj);
+ struct devfreq *df = to_devfreq(dev);
-/* Remove the specific sysfs files which depend on each governor. */
-static void remove_sysfs_files(struct devfreq *devfreq,
- const struct devfreq_governor *gov)
-{
- if (IS_SUPPORTED_ATTR(gov->attrs, POLLING_INTERVAL))
- sysfs_remove_file(&devfreq->dev.kobj,
- &dev_attr_polling_interval.attr);
- if (IS_SUPPORTED_ATTR(gov->attrs, TIMER))
- sysfs_remove_file(&devfreq->dev.kobj, &dev_attr_timer.attr);
+ if (!df->governor || !df->governor->attrs)
+ return 0;
+
+ if (attr == &dev_attr_polling_interval.attr &&
+ IS_SUPPORTED_ATTR(df->governor->attrs, POLLING_INTERVAL))
+ return attr->mode;
+
+ if (attr == &dev_attr_timer.attr &&
+ IS_SUPPORTED_ATTR(df->governor->attrs, TIMER))
+ return attr->mode;
+
+ return 0;
}
+static const struct attribute_group devfreq_group = {
+ .attrs = devfreq_attrs,
+};
+
+static const struct attribute_group gov_attr_group = {
+ .attrs = governor_attrs,
+ .is_visible = gov_attr_visible,
+};
+
+static const struct attribute_group *devfreq_groups[] = {
+ &devfreq_group,
+ &gov_attr_group,
+ NULL
+};
+
/**
* devfreq_summary_show() - Show the summary of the devfreq devices
* @s: seq_file instance to show the summary of devfreq devices
diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c
index 8b57194ac698..401aac6a9f07 100644
--- a/drivers/devfreq/tegra30-devfreq.c
+++ b/drivers/devfreq/tegra30-devfreq.c
@@ -941,16 +941,22 @@ static int tegra_devfreq_probe(struct platform_device *pdev)
return 0;
}
+/*
+ * The activity counter is incremented every 256 memory transactions. However,
+ * the number of clock cycles required for each transaction varies across
+ * different SoC generations. For instance, a single transaction takes 2 EMC
+ * clocks on Tegra30, 1 EMC clock on Tegra114, and 4 EMC clocks on Tegra124.
+ */
static const struct tegra_devfreq_soc_data tegra124_soc = {
.configs = tegra124_device_configs,
-
- /*
- * Activity counter is incremented every 256 memory transactions,
- * and each transaction takes 4 EMC clocks.
- */
.count_weight = 4 * 256,
};
+static const struct tegra_devfreq_soc_data tegra114_soc = {
+ .configs = tegra124_device_configs,
+ .count_weight = 256,
+};
+
static const struct tegra_devfreq_soc_data tegra30_soc = {
.configs = tegra30_device_configs,
.count_weight = 2 * 256,
@@ -958,6 +964,7 @@ static const struct tegra_devfreq_soc_data tegra30_soc = {
static const struct of_device_id tegra_devfreq_of_match[] = {
{ .compatible = "nvidia,tegra30-actmon", .data = &tegra30_soc, },
+ { .compatible = "nvidia,tegra114-actmon", .data = &tegra114_soc, },
{ .compatible = "nvidia,tegra124-actmon", .data = &tegra124_soc, },
{ },
};