^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Generic OPP debugfs interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2015-2016 Viresh Kumar <viresh.kumar@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/limits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "opp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static struct dentry *rootdir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static void opp_set_dev_name(const struct device *dev, char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) if (dev->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) snprintf(name, NAME_MAX, "%s-%s", dev_name(dev->parent),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) dev_name(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) snprintf(name, NAME_MAX, "%s", dev_name(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) void opp_debug_remove_one(struct dev_pm_opp *opp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) debugfs_remove_recursive(opp->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static ssize_t bw_name_read(struct file *fp, char __user *userbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct icc_path *path = fp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) char buf[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) i = scnprintf(buf, sizeof(buf), "%.62s\n", icc_get_name(path));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return simple_read_from_buffer(userbuf, count, ppos, buf, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static const struct file_operations bw_name_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .open = simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .read = bw_name_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .llseek = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static void opp_debug_create_bw(struct dev_pm_opp *opp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct opp_table *opp_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct dentry *pdentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct dentry *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) char name[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) for (i = 0; i < opp_table->path_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) snprintf(name, sizeof(name), "icc-path-%.1d", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* Create per-path directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) d = debugfs_create_dir(name, pdentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) debugfs_create_file("name", S_IRUGO, d, opp_table->paths[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) &bw_name_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) debugfs_create_u32("peak_bw", S_IRUGO, d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) &opp->bandwidth[i].peak);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) debugfs_create_u32("avg_bw", S_IRUGO, d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) &opp->bandwidth[i].avg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static void opp_debug_create_supplies(struct dev_pm_opp *opp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct opp_table *opp_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct dentry *pdentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct dentry *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) for (i = 0; i < opp_table->regulator_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) char name[15];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) snprintf(name, sizeof(name), "supply-%d", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /* Create per-opp directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) d = debugfs_create_dir(name, pdentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) debugfs_create_ulong("u_volt_target", S_IRUGO, d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) &opp->supplies[i].u_volt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) debugfs_create_ulong("u_volt_min", S_IRUGO, d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) &opp->supplies[i].u_volt_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) debugfs_create_ulong("u_volt_max", S_IRUGO, d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) &opp->supplies[i].u_volt_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) debugfs_create_ulong("u_amp", S_IRUGO, d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) &opp->supplies[i].u_amp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) void opp_debug_create_one(struct dev_pm_opp *opp, struct opp_table *opp_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct dentry *pdentry = opp_table->dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct dentry *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unsigned long id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) char name[25]; /* 20 chars for 64 bit value + 5 (opp:\0) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * Get directory name for OPP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * - Normally rate is unique to each OPP, use it to get unique opp-name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * - For some devices rate isn't available, use index instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (likely(opp->rate))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) id = opp->rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) id = _get_opp_count(opp_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) snprintf(name, sizeof(name), "opp:%lu", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /* Create per-opp directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) d = debugfs_create_dir(name, pdentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) debugfs_create_bool("available", S_IRUGO, d, &opp->available);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) debugfs_create_bool("dynamic", S_IRUGO, d, &opp->dynamic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) debugfs_create_bool("turbo", S_IRUGO, d, &opp->turbo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) debugfs_create_bool("suspend", S_IRUGO, d, &opp->suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) debugfs_create_u32("performance_state", S_IRUGO, d, &opp->pstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) debugfs_create_ulong("rate_hz", S_IRUGO, d, &opp->rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) debugfs_create_ulong("clock_latency_ns", S_IRUGO, d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) &opp->clock_latency_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) opp_debug_create_supplies(opp, opp_table, d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) opp_debug_create_bw(opp, opp_table, d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) opp->dentry = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static void opp_list_debug_create_dir(struct opp_device *opp_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct opp_table *opp_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) const struct device *dev = opp_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct dentry *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) opp_set_dev_name(dev, opp_table->dentry_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /* Create device specific directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) d = debugfs_create_dir(opp_table->dentry_name, rootdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) opp_dev->dentry = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) opp_table->dentry = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static void opp_list_debug_create_link(struct opp_device *opp_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct opp_table *opp_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) char name[NAME_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) opp_set_dev_name(opp_dev->dev, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /* Create device specific directory link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) opp_dev->dentry = debugfs_create_symlink(name, rootdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) opp_table->dentry_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * opp_debug_register - add a device opp node to the debugfs 'opp' directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * @opp_dev: opp-dev pointer for device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * @opp_table: the device-opp being added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * Dynamically adds device specific directory in debugfs 'opp' directory. If the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * device-opp is shared with other devices, then links will be created for all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * devices except the first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) void opp_debug_register(struct opp_device *opp_dev, struct opp_table *opp_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (opp_table->dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) opp_list_debug_create_link(opp_dev, opp_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) opp_list_debug_create_dir(opp_dev, opp_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static void opp_migrate_dentry(struct opp_device *opp_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct opp_table *opp_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct opp_device *new_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) const struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /* Look for next opp-dev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) list_for_each_entry(new_dev, &opp_table->dev_list, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (new_dev != opp_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* new_dev is guaranteed to be valid here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) dev = new_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) debugfs_remove_recursive(new_dev->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) opp_set_dev_name(dev, opp_table->dentry_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) dentry = debugfs_rename(rootdir, opp_dev->dentry, rootdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) opp_table->dentry_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (!dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) dev_err(dev, "%s: Failed to rename link from: %s to %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) __func__, dev_name(opp_dev->dev), dev_name(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) new_dev->dentry = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) opp_table->dentry = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * opp_debug_unregister - remove a device opp node from debugfs opp directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * @opp_dev: opp-dev pointer for device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * @opp_table: the device-opp being removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * Dynamically removes device specific directory from debugfs 'opp' directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) void opp_debug_unregister(struct opp_device *opp_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct opp_table *opp_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (opp_dev->dentry == opp_table->dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* Move the real dentry object under another device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (!list_is_singular(&opp_table->dev_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) opp_migrate_dentry(opp_dev, opp_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) opp_table->dentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) debugfs_remove_recursive(opp_dev->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) opp_dev->dentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static int opp_summary_show(struct seq_file *s, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct list_head *lists = (struct list_head *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct opp_table *opp_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct dev_pm_opp *opp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) mutex_lock(&opp_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) seq_puts(s, " device rate(Hz) target(uV) min(uV) max(uV)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) seq_puts(s, "-------------------------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) list_for_each_entry(opp_table, lists, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) seq_printf(s, " %s\n", opp_table->dentry_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) mutex_lock(&opp_table->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) list_for_each_entry(opp, &opp_table->opp_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (!opp->available)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) seq_printf(s, "%31lu %12lu %11lu %11lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) opp->rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) opp->supplies[0].u_volt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) opp->supplies[0].u_volt_min,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) opp->supplies[0].u_volt_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (opp_table->regulator_count > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) seq_printf(s, "%44lu %11lu %11lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) opp->supplies[1].u_volt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) opp->supplies[1].u_volt_min,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) opp->supplies[1].u_volt_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) mutex_unlock(&opp_table->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) mutex_unlock(&opp_table_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static int opp_summary_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return single_open(file, opp_summary_show, inode->i_private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static const struct file_operations opp_summary_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) .open = opp_summary_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) .read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) .llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) .release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static int __init opp_debug_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /* Create /sys/kernel/debug/opp directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) rootdir = debugfs_create_dir("opp", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) debugfs_create_file("opp_summary", 0444, rootdir, &opp_tables,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) &opp_summary_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) core_initcall(opp_debug_init);