diff options
-rw-r--r-- | drivers/base/power/opp/Makefile | 1 | ||||
-rw-r--r-- | drivers/base/power/opp/core.c | 21 | ||||
-rw-r--r-- | drivers/base/power/opp/debugfs.c | 219 | ||||
-rw-r--r-- | drivers/base/power/opp/opp.h | 42 |
4 files changed, 281 insertions, 2 deletions
diff --git a/drivers/base/power/opp/Makefile b/drivers/base/power/opp/Makefile index 33c1e18c41a4..19837ef04d8e 100644 --- a/drivers/base/power/opp/Makefile +++ b/drivers/base/power/opp/Makefile | |||
@@ -1,2 +1,3 @@ | |||
1 | ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG | 1 | ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG |
2 | obj-y += core.o cpu.o | 2 | obj-y += core.o cpu.o |
3 | obj-$(CONFIG_DEBUG_FS) += debugfs.o | ||
diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index b8e76f75073b..6aa172be6e8e 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c | |||
@@ -463,6 +463,7 @@ static void _kfree_list_dev_rcu(struct rcu_head *head) | |||
463 | static void _remove_list_dev(struct device_list_opp *list_dev, | 463 | static void _remove_list_dev(struct device_list_opp *list_dev, |
464 | struct device_opp *dev_opp) | 464 | struct device_opp *dev_opp) |
465 | { | 465 | { |
466 | opp_debug_unregister(list_dev, dev_opp); | ||
466 | list_del(&list_dev->node); | 467 | list_del(&list_dev->node); |
467 | call_srcu(&dev_opp->srcu_head.srcu, &list_dev->rcu_head, | 468 | call_srcu(&dev_opp->srcu_head.srcu, &list_dev->rcu_head, |
468 | _kfree_list_dev_rcu); | 469 | _kfree_list_dev_rcu); |
@@ -472,6 +473,7 @@ struct device_list_opp *_add_list_dev(const struct device *dev, | |||
472 | struct device_opp *dev_opp) | 473 | struct device_opp *dev_opp) |
473 | { | 474 | { |
474 | struct device_list_opp *list_dev; | 475 | struct device_list_opp *list_dev; |
476 | int ret; | ||
475 | 477 | ||
476 | list_dev = kzalloc(sizeof(*list_dev), GFP_KERNEL); | 478 | list_dev = kzalloc(sizeof(*list_dev), GFP_KERNEL); |
477 | if (!list_dev) | 479 | if (!list_dev) |
@@ -481,6 +483,12 @@ struct device_list_opp *_add_list_dev(const struct device *dev, | |||
481 | list_dev->dev = dev; | 483 | list_dev->dev = dev; |
482 | list_add_rcu(&list_dev->node, &dev_opp->dev_list); | 484 | list_add_rcu(&list_dev->node, &dev_opp->dev_list); |
483 | 485 | ||
486 | /* Create debugfs entries for the dev_opp */ | ||
487 | ret = opp_debug_register(list_dev, dev_opp); | ||
488 | if (ret) | ||
489 | dev_err(dev, "%s: Failed to register opp debugfs (%d)\n", | ||
490 | __func__, ret); | ||
491 | |||
484 | return list_dev; | 492 | return list_dev; |
485 | } | 493 | } |
486 | 494 | ||
@@ -596,6 +604,7 @@ static void _opp_remove(struct device_opp *dev_opp, | |||
596 | */ | 604 | */ |
597 | if (notify) | 605 | if (notify) |
598 | srcu_notifier_call_chain(&dev_opp->srcu_head, OPP_EVENT_REMOVE, opp); | 606 | srcu_notifier_call_chain(&dev_opp->srcu_head, OPP_EVENT_REMOVE, opp); |
607 | opp_debug_remove_one(opp); | ||
599 | list_del_rcu(&opp->node); | 608 | list_del_rcu(&opp->node); |
600 | call_srcu(&dev_opp->srcu_head.srcu, &opp->rcu_head, _kfree_opp_rcu); | 609 | call_srcu(&dev_opp->srcu_head.srcu, &opp->rcu_head, _kfree_opp_rcu); |
601 | 610 | ||
@@ -673,6 +682,7 @@ static int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, | |||
673 | { | 682 | { |
674 | struct dev_pm_opp *opp; | 683 | struct dev_pm_opp *opp; |
675 | struct list_head *head = &dev_opp->opp_list; | 684 | struct list_head *head = &dev_opp->opp_list; |
685 | int ret; | ||
676 | 686 | ||
677 | /* | 687 | /* |
678 | * Insert new OPP in order of increasing frequency and discard if | 688 | * Insert new OPP in order of increasing frequency and discard if |
@@ -703,6 +713,11 @@ static int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, | |||
703 | new_opp->dev_opp = dev_opp; | 713 | new_opp->dev_opp = dev_opp; |
704 | list_add_rcu(&new_opp->node, head); | 714 | list_add_rcu(&new_opp->node, head); |
705 | 715 | ||
716 | ret = opp_debug_create_one(new_opp, dev_opp); | ||
717 | if (ret) | ||
718 | dev_err(dev, "%s: Failed to register opp to debugfs (%d)\n", | ||
719 | __func__, ret); | ||
720 | |||
706 | return 0; | 721 | return 0; |
707 | } | 722 | } |
708 | 723 | ||
@@ -889,12 +904,14 @@ static int _opp_add_static_v2(struct device *dev, struct device_node *np) | |||
889 | 904 | ||
890 | /* OPP to select on device suspend */ | 905 | /* OPP to select on device suspend */ |
891 | if (of_property_read_bool(np, "opp-suspend")) { | 906 | if (of_property_read_bool(np, "opp-suspend")) { |
892 | if (dev_opp->suspend_opp) | 907 | if (dev_opp->suspend_opp) { |
893 | dev_warn(dev, "%s: Multiple suspend OPPs found (%lu %lu)\n", | 908 | dev_warn(dev, "%s: Multiple suspend OPPs found (%lu %lu)\n", |
894 | __func__, dev_opp->suspend_opp->rate, | 909 | __func__, dev_opp->suspend_opp->rate, |
895 | new_opp->rate); | 910 | new_opp->rate); |
896 | else | 911 | } else { |
912 | new_opp->suspend = true; | ||
897 | dev_opp->suspend_opp = new_opp; | 913 | dev_opp->suspend_opp = new_opp; |
914 | } | ||
898 | } | 915 | } |
899 | 916 | ||
900 | if (new_opp->clock_latency_ns > dev_opp->clock_latency_ns_max) | 917 | if (new_opp->clock_latency_ns > dev_opp->clock_latency_ns_max) |
diff --git a/drivers/base/power/opp/debugfs.c b/drivers/base/power/opp/debugfs.c new file mode 100644 index 000000000000..ddfe4773e922 --- /dev/null +++ b/drivers/base/power/opp/debugfs.c | |||
@@ -0,0 +1,219 @@ | |||
1 | /* | ||
2 | * Generic OPP debugfs interface | ||
3 | * | ||
4 | * Copyright (C) 2015-2016 Viresh Kumar <viresh.kumar@linaro.org> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | |||
11 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
12 | |||
13 | #include <linux/debugfs.h> | ||
14 | #include <linux/device.h> | ||
15 | #include <linux/err.h> | ||
16 | #include <linux/init.h> | ||
17 | #include <linux/limits.h> | ||
18 | |||
19 | #include "opp.h" | ||
20 | |||
21 | static struct dentry *rootdir; | ||
22 | |||
23 | static void opp_set_dev_name(const struct device *dev, char *name) | ||
24 | { | ||
25 | if (dev->parent) | ||
26 | snprintf(name, NAME_MAX, "%s-%s", dev_name(dev->parent), | ||
27 | dev_name(dev)); | ||
28 | else | ||
29 | snprintf(name, NAME_MAX, "%s", dev_name(dev)); | ||
30 | } | ||
31 | |||
32 | void opp_debug_remove_one(struct dev_pm_opp *opp) | ||
33 | { | ||
34 | debugfs_remove_recursive(opp->dentry); | ||
35 | } | ||
36 | |||
37 | int opp_debug_create_one(struct dev_pm_opp *opp, struct device_opp *dev_opp) | ||
38 | { | ||
39 | struct dentry *pdentry = dev_opp->dentry; | ||
40 | struct dentry *d; | ||
41 | char name[25]; /* 20 chars for 64 bit value + 5 (opp:\0) */ | ||
42 | |||
43 | /* Rate is unique to each OPP, use it to give opp-name */ | ||
44 | snprintf(name, sizeof(name), "opp:%lu", opp->rate); | ||
45 | |||
46 | /* Create per-opp directory */ | ||
47 | d = debugfs_create_dir(name, pdentry); | ||
48 | if (!d) | ||
49 | return -ENOMEM; | ||
50 | |||
51 | if (!debugfs_create_bool("available", S_IRUGO, d, &opp->available)) | ||
52 | return -ENOMEM; | ||
53 | |||
54 | if (!debugfs_create_bool("dynamic", S_IRUGO, d, &opp->dynamic)) | ||
55 | return -ENOMEM; | ||
56 | |||
57 | if (!debugfs_create_bool("turbo", S_IRUGO, d, &opp->turbo)) | ||
58 | return -ENOMEM; | ||
59 | |||
60 | if (!debugfs_create_bool("suspend", S_IRUGO, d, &opp->suspend)) | ||
61 | return -ENOMEM; | ||
62 | |||
63 | if (!debugfs_create_ulong("rate_hz", S_IRUGO, d, &opp->rate)) | ||
64 | return -ENOMEM; | ||
65 | |||
66 | if (!debugfs_create_ulong("u_volt_target", S_IRUGO, d, &opp->u_volt)) | ||
67 | return -ENOMEM; | ||
68 | |||
69 | if (!debugfs_create_ulong("u_volt_min", S_IRUGO, d, &opp->u_volt_min)) | ||
70 | return -ENOMEM; | ||
71 | |||
72 | if (!debugfs_create_ulong("u_volt_max", S_IRUGO, d, &opp->u_volt_max)) | ||
73 | return -ENOMEM; | ||
74 | |||
75 | if (!debugfs_create_ulong("u_amp", S_IRUGO, d, &opp->u_amp)) | ||
76 | return -ENOMEM; | ||
77 | |||
78 | if (!debugfs_create_ulong("clock_latency_ns", S_IRUGO, d, | ||
79 | &opp->clock_latency_ns)) | ||
80 | return -ENOMEM; | ||
81 | |||
82 | opp->dentry = d; | ||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | static int device_opp_debug_create_dir(struct device_list_opp *list_dev, | ||
87 | struct device_opp *dev_opp) | ||
88 | { | ||
89 | const struct device *dev = list_dev->dev; | ||
90 | struct dentry *d; | ||
91 | |||
92 | opp_set_dev_name(dev, dev_opp->dentry_name); | ||
93 | |||
94 | /* Create device specific directory */ | ||
95 | d = debugfs_create_dir(dev_opp->dentry_name, rootdir); | ||
96 | if (!d) { | ||
97 | dev_err(dev, "%s: Failed to create debugfs dir\n", __func__); | ||
98 | return -ENOMEM; | ||
99 | } | ||
100 | |||
101 | list_dev->dentry = d; | ||
102 | dev_opp->dentry = d; | ||
103 | |||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | static int device_opp_debug_create_link(struct device_list_opp *list_dev, | ||
108 | struct device_opp *dev_opp) | ||
109 | { | ||
110 | const struct device *dev = list_dev->dev; | ||
111 | char name[NAME_MAX]; | ||
112 | struct dentry *d; | ||
113 | |||
114 | opp_set_dev_name(list_dev->dev, name); | ||
115 | |||
116 | /* Create device specific directory link */ | ||
117 | d = debugfs_create_symlink(name, rootdir, dev_opp->dentry_name); | ||
118 | if (!d) { | ||
119 | dev_err(dev, "%s: Failed to create link\n", __func__); | ||
120 | return -ENOMEM; | ||
121 | } | ||
122 | |||
123 | list_dev->dentry = d; | ||
124 | |||
125 | return 0; | ||
126 | } | ||
127 | |||
128 | /** | ||
129 | * opp_debug_register - add a device opp node to the debugfs 'opp' directory | ||
130 | * @list_dev: list-dev pointer for device | ||
131 | * @dev_opp: the device-opp being added | ||
132 | * | ||
133 | * Dynamically adds device specific directory in debugfs 'opp' directory. If the | ||
134 | * device-opp is shared with other devices, then links will be created for all | ||
135 | * devices except the first. | ||
136 | * | ||
137 | * Return: 0 on success, otherwise negative error. | ||
138 | */ | ||
139 | int opp_debug_register(struct device_list_opp *list_dev, | ||
140 | struct device_opp *dev_opp) | ||
141 | { | ||
142 | if (!rootdir) { | ||
143 | pr_debug("%s: Uninitialized rootdir\n", __func__); | ||
144 | return -EINVAL; | ||
145 | } | ||
146 | |||
147 | if (dev_opp->dentry) | ||
148 | return device_opp_debug_create_link(list_dev, dev_opp); | ||
149 | |||
150 | return device_opp_debug_create_dir(list_dev, dev_opp); | ||
151 | } | ||
152 | |||
153 | static void opp_migrate_dentry(struct device_list_opp *list_dev, | ||
154 | struct device_opp *dev_opp) | ||
155 | { | ||
156 | struct device_list_opp *new_dev; | ||
157 | const struct device *dev; | ||
158 | struct dentry *dentry; | ||
159 | |||
160 | /* Look for next list-dev */ | ||
161 | list_for_each_entry(new_dev, &dev_opp->dev_list, node) | ||
162 | if (new_dev != list_dev) | ||
163 | break; | ||
164 | |||
165 | /* new_dev is guaranteed to be valid here */ | ||
166 | dev = new_dev->dev; | ||
167 | debugfs_remove_recursive(new_dev->dentry); | ||
168 | |||
169 | opp_set_dev_name(dev, dev_opp->dentry_name); | ||
170 | |||
171 | dentry = debugfs_rename(rootdir, list_dev->dentry, rootdir, | ||
172 | dev_opp->dentry_name); | ||
173 | if (!dentry) { | ||
174 | dev_err(dev, "%s: Failed to rename link from: %s to %s\n", | ||
175 | __func__, dev_name(list_dev->dev), dev_name(dev)); | ||
176 | return; | ||
177 | } | ||
178 | |||
179 | new_dev->dentry = dentry; | ||
180 | dev_opp->dentry = dentry; | ||
181 | } | ||
182 | |||
183 | /** | ||
184 | * opp_debug_unregister - remove a device opp node from debugfs opp directory | ||
185 | * @list_dev: list-dev pointer for device | ||
186 | * @dev_opp: the device-opp being removed | ||
187 | * | ||
188 | * Dynamically removes device specific directory from debugfs 'opp' directory. | ||
189 | */ | ||
190 | void opp_debug_unregister(struct device_list_opp *list_dev, | ||
191 | struct device_opp *dev_opp) | ||
192 | { | ||
193 | if (list_dev->dentry == dev_opp->dentry) { | ||
194 | /* Move the real dentry object under another device */ | ||
195 | if (!list_is_singular(&dev_opp->dev_list)) { | ||
196 | opp_migrate_dentry(list_dev, dev_opp); | ||
197 | goto out; | ||
198 | } | ||
199 | dev_opp->dentry = NULL; | ||
200 | } | ||
201 | |||
202 | debugfs_remove_recursive(list_dev->dentry); | ||
203 | |||
204 | out: | ||
205 | list_dev->dentry = NULL; | ||
206 | } | ||
207 | |||
208 | static int __init opp_debug_init(void) | ||
209 | { | ||
210 | /* Create /sys/kernel/debug/opp directory */ | ||
211 | rootdir = debugfs_create_dir("opp", NULL); | ||
212 | if (!rootdir) { | ||
213 | pr_err("%s: Failed to create root directory\n", __func__); | ||
214 | return -ENOMEM; | ||
215 | } | ||
216 | |||
217 | return 0; | ||
218 | } | ||
219 | core_initcall(opp_debug_init); | ||
diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h index 7366b2aa8997..a6bd8d2c2b47 100644 --- a/drivers/base/power/opp/opp.h +++ b/drivers/base/power/opp/opp.h | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/device.h> | 17 | #include <linux/device.h> |
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/list.h> | 19 | #include <linux/list.h> |
20 | #include <linux/limits.h> | ||
20 | #include <linux/pm_opp.h> | 21 | #include <linux/pm_opp.h> |
21 | #include <linux/rculist.h> | 22 | #include <linux/rculist.h> |
22 | #include <linux/rcupdate.h> | 23 | #include <linux/rcupdate.h> |
@@ -53,6 +54,7 @@ extern struct mutex dev_opp_list_lock; | |||
53 | * @dynamic: not-created from static DT entries. | 54 | * @dynamic: not-created from static DT entries. |
54 | * @available: true/false - marks if this OPP as available or not | 55 | * @available: true/false - marks if this OPP as available or not |
55 | * @turbo: true if turbo (boost) OPP | 56 | * @turbo: true if turbo (boost) OPP |
57 | * @suspend: true if suspend OPP | ||
56 | * @rate: Frequency in hertz | 58 | * @rate: Frequency in hertz |
57 | * @u_volt: Target voltage in microvolts corresponding to this OPP | 59 | * @u_volt: Target voltage in microvolts corresponding to this OPP |
58 | * @u_volt_min: Minimum voltage in microvolts corresponding to this OPP | 60 | * @u_volt_min: Minimum voltage in microvolts corresponding to this OPP |
@@ -63,6 +65,7 @@ extern struct mutex dev_opp_list_lock; | |||
63 | * @dev_opp: points back to the device_opp struct this opp belongs to | 65 | * @dev_opp: points back to the device_opp struct this opp belongs to |
64 | * @rcu_head: RCU callback head used for deferred freeing | 66 | * @rcu_head: RCU callback head used for deferred freeing |
65 | * @np: OPP's device node. | 67 | * @np: OPP's device node. |
68 | * @dentry: debugfs dentry pointer (per opp) | ||
66 | * | 69 | * |
67 | * This structure stores the OPP information for a given device. | 70 | * This structure stores the OPP information for a given device. |
68 | */ | 71 | */ |
@@ -72,6 +75,7 @@ struct dev_pm_opp { | |||
72 | bool available; | 75 | bool available; |
73 | bool dynamic; | 76 | bool dynamic; |
74 | bool turbo; | 77 | bool turbo; |
78 | bool suspend; | ||
75 | unsigned long rate; | 79 | unsigned long rate; |
76 | 80 | ||
77 | unsigned long u_volt; | 81 | unsigned long u_volt; |
@@ -84,6 +88,10 @@ struct dev_pm_opp { | |||
84 | struct rcu_head rcu_head; | 88 | struct rcu_head rcu_head; |
85 | 89 | ||
86 | struct device_node *np; | 90 | struct device_node *np; |
91 | |||
92 | #ifdef CONFIG_DEBUG_FS | ||
93 | struct dentry *dentry; | ||
94 | #endif | ||
87 | }; | 95 | }; |
88 | 96 | ||
89 | /** | 97 | /** |
@@ -91,6 +99,7 @@ struct dev_pm_opp { | |||
91 | * @node: list node | 99 | * @node: list node |
92 | * @dev: device to which the struct object belongs | 100 | * @dev: device to which the struct object belongs |
93 | * @rcu_head: RCU callback head used for deferred freeing | 101 | * @rcu_head: RCU callback head used for deferred freeing |
102 | * @dentry: debugfs dentry pointer (per device) | ||
94 | * | 103 | * |
95 | * This is an internal data structure maintaining the list of devices that are | 104 | * This is an internal data structure maintaining the list of devices that are |
96 | * managed by 'struct device_opp'. | 105 | * managed by 'struct device_opp'. |
@@ -99,6 +108,10 @@ struct device_list_opp { | |||
99 | struct list_head node; | 108 | struct list_head node; |
100 | const struct device *dev; | 109 | const struct device *dev; |
101 | struct rcu_head rcu_head; | 110 | struct rcu_head rcu_head; |
111 | |||
112 | #ifdef CONFIG_DEBUG_FS | ||
113 | struct dentry *dentry; | ||
114 | #endif | ||
102 | }; | 115 | }; |
103 | 116 | ||
104 | /** | 117 | /** |
@@ -114,6 +127,8 @@ struct device_list_opp { | |||
114 | * @opp_list: list of opps | 127 | * @opp_list: list of opps |
115 | * @np: struct device_node pointer for opp's DT node. | 128 | * @np: struct device_node pointer for opp's DT node. |
116 | * @shared_opp: OPP is shared between multiple devices. | 129 | * @shared_opp: OPP is shared between multiple devices. |
130 | * @dentry: debugfs dentry pointer of the real device directory (not links). | ||
131 | * @dentry_name: Name of the real dentry. | ||
117 | * | 132 | * |
118 | * This is an internal data structure maintaining the link to opps attached to | 133 | * This is an internal data structure maintaining the link to opps attached to |
119 | * a device. This structure is not meant to be shared to users as it is | 134 | * a device. This structure is not meant to be shared to users as it is |
@@ -135,6 +150,11 @@ struct device_opp { | |||
135 | unsigned long clock_latency_ns_max; | 150 | unsigned long clock_latency_ns_max; |
136 | bool shared_opp; | 151 | bool shared_opp; |
137 | struct dev_pm_opp *suspend_opp; | 152 | struct dev_pm_opp *suspend_opp; |
153 | |||
154 | #ifdef CONFIG_DEBUG_FS | ||
155 | struct dentry *dentry; | ||
156 | char dentry_name[NAME_MAX]; | ||
157 | #endif | ||
138 | }; | 158 | }; |
139 | 159 | ||
140 | /* Routines internal to opp core */ | 160 | /* Routines internal to opp core */ |
@@ -143,4 +163,26 @@ struct device_list_opp *_add_list_dev(const struct device *dev, | |||
143 | struct device_opp *dev_opp); | 163 | struct device_opp *dev_opp); |
144 | struct device_node *_of_get_opp_desc_node(struct device *dev); | 164 | struct device_node *_of_get_opp_desc_node(struct device *dev); |
145 | 165 | ||
166 | #ifdef CONFIG_DEBUG_FS | ||
167 | void opp_debug_remove_one(struct dev_pm_opp *opp); | ||
168 | int opp_debug_create_one(struct dev_pm_opp *opp, struct device_opp *dev_opp); | ||
169 | int opp_debug_register(struct device_list_opp *list_dev, | ||
170 | struct device_opp *dev_opp); | ||
171 | void opp_debug_unregister(struct device_list_opp *list_dev, | ||
172 | struct device_opp *dev_opp); | ||
173 | #else | ||
174 | static inline void opp_debug_remove_one(struct dev_pm_opp *opp) {} | ||
175 | |||
176 | static inline int opp_debug_create_one(struct dev_pm_opp *opp, | ||
177 | struct device_opp *dev_opp) | ||
178 | { return 0; } | ||
179 | static inline int opp_debug_register(struct device_list_opp *list_dev, | ||
180 | struct device_opp *dev_opp) | ||
181 | { return 0; } | ||
182 | |||
183 | static inline void opp_debug_unregister(struct device_list_opp *list_dev, | ||
184 | struct device_opp *dev_opp) | ||
185 | { } | ||
186 | #endif /* DEBUG_FS */ | ||
187 | |||
146 | #endif /* __DRIVER_OPP_H__ */ | 188 | #endif /* __DRIVER_OPP_H__ */ |