Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Google, Inc. |
Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 3 | * Copyright (c) 2007-2012, The Linux Foundation. All rights reserved. |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 4 | * |
| 5 | * This software is licensed under the terms of the GNU General Public |
| 6 | * License version 2, as published by the Free Software Foundation, and |
| 7 | * may be copied, distributed, and modified under those terms. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/ctype.h> |
| 19 | #include <linux/debugfs.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 20 | #include <linux/seq_file.h> |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 21 | #include <linux/clk.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 22 | #include <linux/list.h> |
| 23 | #include <linux/clkdev.h> |
Matt Wagantall | 33d01f5 | 2012-02-23 23:27:44 -0800 | [diff] [blame] | 24 | #include <mach/clk-provider.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 25 | |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 26 | #include "clock.h" |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 27 | |
| 28 | static int clock_debug_rate_set(void *data, u64 val) |
| 29 | { |
| 30 | struct clk *clock = data; |
| 31 | int ret; |
| 32 | |
| 33 | /* Only increases to max rate will succeed, but that's actually good |
| 34 | * for debugging purposes so we don't check for error. */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 35 | if (clock->flags & CLKFLAG_MAX) |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 36 | clk_set_max_rate(clock, val); |
Matt Wagantall | 8e6126f | 2011-11-08 13:34:19 -0800 | [diff] [blame] | 37 | ret = clk_set_rate(clock, val); |
| 38 | if (ret) |
Stephen Boyd | 753ab93 | 2012-08-02 13:14:38 -0700 | [diff] [blame] | 39 | pr_err("clk_set_rate(%s, %lu) failed (%d)\n", clock->dbg_name, |
| 40 | (unsigned long)val, ret); |
Matt Wagantall | 8e6126f | 2011-11-08 13:34:19 -0800 | [diff] [blame] | 41 | |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 42 | return ret; |
| 43 | } |
| 44 | |
| 45 | static int clock_debug_rate_get(void *data, u64 *val) |
| 46 | { |
| 47 | struct clk *clock = data; |
| 48 | *val = clk_get_rate(clock); |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | DEFINE_SIMPLE_ATTRIBUTE(clock_rate_fops, clock_debug_rate_get, |
| 53 | clock_debug_rate_set, "%llu\n"); |
| 54 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 55 | static struct clk *measure; |
| 56 | |
| 57 | static int clock_debug_measure_get(void *data, u64 *val) |
| 58 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 59 | struct clk *clock = data; |
Stephen Boyd | a52d7e3 | 2011-11-10 11:59:00 -0800 | [diff] [blame] | 60 | int ret, is_hw_gated; |
| 61 | |
| 62 | /* Check to see if the clock is in hardware gating mode */ |
Stephen Boyd | 0f7e564 | 2012-08-02 12:59:33 -0700 | [diff] [blame] | 63 | if (clock->ops->in_hwcg_mode) |
Stephen Boyd | a52d7e3 | 2011-11-10 11:59:00 -0800 | [diff] [blame] | 64 | is_hw_gated = clock->ops->in_hwcg_mode(clock); |
| 65 | else |
| 66 | is_hw_gated = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 67 | |
| 68 | ret = clk_set_parent(measure, clock); |
Stephen Boyd | a52d7e3 | 2011-11-10 11:59:00 -0800 | [diff] [blame] | 69 | if (!ret) { |
| 70 | /* |
| 71 | * Disable hw gating to get accurate rate measurements. Only do |
| 72 | * this if the clock is explictly enabled by software. This |
| 73 | * allows us to detect errors where clocks are on even though |
| 74 | * software is not requesting them to be on due to broken |
| 75 | * hardware gating signals. |
| 76 | */ |
| 77 | if (is_hw_gated && clock->count) |
| 78 | clock->ops->disable_hwcg(clock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 79 | *val = clk_get_rate(measure); |
Stephen Boyd | a52d7e3 | 2011-11-10 11:59:00 -0800 | [diff] [blame] | 80 | /* Reenable hwgating if it was disabled */ |
| 81 | if (is_hw_gated && clock->count) |
| 82 | clock->ops->enable_hwcg(clock); |
| 83 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 84 | |
| 85 | return ret; |
| 86 | } |
| 87 | |
| 88 | DEFINE_SIMPLE_ATTRIBUTE(clock_measure_fops, clock_debug_measure_get, |
| 89 | NULL, "%lld\n"); |
| 90 | |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 91 | static int clock_debug_enable_set(void *data, u64 val) |
| 92 | { |
| 93 | struct clk *clock = data; |
| 94 | int rc = 0; |
| 95 | |
| 96 | if (val) |
Stephen Boyd | 3bbf346 | 2012-01-12 00:19:23 -0800 | [diff] [blame] | 97 | rc = clk_prepare_enable(clock); |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 98 | else |
Stephen Boyd | 3bbf346 | 2012-01-12 00:19:23 -0800 | [diff] [blame] | 99 | clk_disable_unprepare(clock); |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 100 | |
| 101 | return rc; |
| 102 | } |
| 103 | |
| 104 | static int clock_debug_enable_get(void *data, u64 *val) |
| 105 | { |
| 106 | struct clk *clock = data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 107 | int enabled; |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 108 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 109 | if (clock->ops->is_enabled) |
| 110 | enabled = clock->ops->is_enabled(clock); |
| 111 | else |
| 112 | enabled = !!(clock->count); |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 113 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 114 | *val = enabled; |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | DEFINE_SIMPLE_ATTRIBUTE(clock_enable_fops, clock_debug_enable_get, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 119 | clock_debug_enable_set, "%lld\n"); |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 120 | |
| 121 | static int clock_debug_local_get(void *data, u64 *val) |
| 122 | { |
| 123 | struct clk *clock = data; |
| 124 | |
Matt Wagantall | acb8d02 | 2012-02-14 15:28:23 -0800 | [diff] [blame] | 125 | if (!clock->ops->is_local) |
| 126 | *val = true; |
| 127 | else |
| 128 | *val = clock->ops->is_local(clock); |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | DEFINE_SIMPLE_ATTRIBUTE(clock_local_fops, clock_debug_local_get, |
| 134 | NULL, "%llu\n"); |
| 135 | |
Stephen Boyd | a52d7e3 | 2011-11-10 11:59:00 -0800 | [diff] [blame] | 136 | static int clock_debug_hwcg_get(void *data, u64 *val) |
| 137 | { |
| 138 | struct clk *clock = data; |
Stephen Boyd | 0f7e564 | 2012-08-02 12:59:33 -0700 | [diff] [blame] | 139 | if (clock->ops->in_hwcg_mode) |
| 140 | *val = !!clock->ops->in_hwcg_mode(clock); |
| 141 | else |
| 142 | *val = 0; |
Stephen Boyd | a52d7e3 | 2011-11-10 11:59:00 -0800 | [diff] [blame] | 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | DEFINE_SIMPLE_ATTRIBUTE(clock_hwcg_fops, clock_debug_hwcg_get, |
| 147 | NULL, "%llu\n"); |
| 148 | |
Matt Wagantall | 665f0cf | 2012-02-27 15:54:43 -0800 | [diff] [blame] | 149 | static int fmax_rates_show(struct seq_file *m, void *unused) |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 150 | { |
Matt Wagantall | 665f0cf | 2012-02-27 15:54:43 -0800 | [diff] [blame] | 151 | struct clk *clock = m->private; |
| 152 | int level = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 153 | |
Matt Wagantall | 665f0cf | 2012-02-27 15:54:43 -0800 | [diff] [blame] | 154 | int vdd_level = find_vdd_level(clock, clock->rate); |
| 155 | if (vdd_level < 0) { |
| 156 | seq_printf(m, "could not find_vdd_level for %s, %ld\n", |
| 157 | clock->dbg_name, clock->rate); |
| 158 | return 0; |
| 159 | } |
Saravana Kannan | 55e959d | 2012-10-15 22:16:04 -0700 | [diff] [blame] | 160 | for (level = 0; level < clock->num_fmax; level++) { |
Matt Wagantall | 665f0cf | 2012-02-27 15:54:43 -0800 | [diff] [blame] | 161 | if (vdd_level == level) |
| 162 | seq_printf(m, "[%lu] ", clock->fmax[level]); |
| 163 | else |
| 164 | seq_printf(m, "%lu ", clock->fmax[level]); |
| 165 | } |
| 166 | seq_printf(m, "\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 167 | |
Stephen Boyd | 31c01e8 | 2012-04-13 15:22:00 -0700 | [diff] [blame] | 168 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Matt Wagantall | 665f0cf | 2012-02-27 15:54:43 -0800 | [diff] [blame] | 171 | static int fmax_rates_open(struct inode *inode, struct file *file) |
Stephen Boyd | cd50fae | 2011-11-03 11:05:42 -0700 | [diff] [blame] | 172 | { |
Matt Wagantall | 665f0cf | 2012-02-27 15:54:43 -0800 | [diff] [blame] | 173 | return single_open(file, fmax_rates_show, inode->i_private); |
Stephen Boyd | cd50fae | 2011-11-03 11:05:42 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Matt Wagantall | 665f0cf | 2012-02-27 15:54:43 -0800 | [diff] [blame] | 176 | static const struct file_operations fmax_rates_fops = { |
| 177 | .open = fmax_rates_open, |
| 178 | .read = seq_read, |
| 179 | .llseek = seq_lseek, |
| 180 | .release = seq_release, |
| 181 | }; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 182 | |
| 183 | static int list_rates_show(struct seq_file *m, void *unused) |
| 184 | { |
| 185 | struct clk *clock = m->private; |
Matt Wagantall | e18bbc8 | 2011-10-06 10:07:28 -0700 | [diff] [blame] | 186 | int rate, level, fmax = 0, i = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 187 | |
Matt Wagantall | e18bbc8 | 2011-10-06 10:07:28 -0700 | [diff] [blame] | 188 | /* Find max frequency supported within voltage constraints. */ |
| 189 | if (!clock->vdd_class) { |
Matt Wagantall | e426f904 | 2011-11-01 16:21:34 -0700 | [diff] [blame] | 190 | fmax = INT_MAX; |
Matt Wagantall | e18bbc8 | 2011-10-06 10:07:28 -0700 | [diff] [blame] | 191 | } else { |
Saravana Kannan | 55e959d | 2012-10-15 22:16:04 -0700 | [diff] [blame] | 192 | for (level = 0; level < clock->num_fmax; level++) |
Matt Wagantall | e18bbc8 | 2011-10-06 10:07:28 -0700 | [diff] [blame] | 193 | if (clock->fmax[level]) |
| 194 | fmax = clock->fmax[level]; |
| 195 | } |
| 196 | |
| 197 | /* |
| 198 | * List supported frequencies <= fmax. Higher frequencies may appear in |
| 199 | * the frequency table, but are not valid and should not be listed. |
| 200 | */ |
| 201 | while ((rate = clock->ops->list_rate(clock, i++)) >= 0) { |
| 202 | if (rate <= fmax) |
| 203 | seq_printf(m, "%u\n", rate); |
| 204 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 205 | |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 206 | return 0; |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 207 | } |
| 208 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 209 | static int list_rates_open(struct inode *inode, struct file *file) |
| 210 | { |
| 211 | return single_open(file, list_rates_show, inode->i_private); |
| 212 | } |
| 213 | |
| 214 | static const struct file_operations list_rates_fops = { |
| 215 | .open = list_rates_open, |
| 216 | .read = seq_read, |
| 217 | .llseek = seq_lseek, |
| 218 | .release = seq_release, |
| 219 | }; |
| 220 | |
Saravana Kannan | 531051f | 2012-09-27 16:19:07 -0700 | [diff] [blame] | 221 | static int clock_parent_show(struct seq_file *m, void *unused) |
| 222 | { |
| 223 | struct clk *clock = m->private; |
| 224 | struct clk *parent = clk_get_parent(clock); |
| 225 | |
| 226 | seq_printf(m, "%s\n", (parent ? parent->dbg_name : "None")); |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | static int clock_parent_open(struct inode *inode, struct file *file) |
| 232 | { |
| 233 | return single_open(file, clock_parent_show, inode->i_private); |
| 234 | } |
| 235 | |
| 236 | static const struct file_operations clock_parent_fops = { |
| 237 | .open = clock_parent_open, |
| 238 | .read = seq_read, |
| 239 | .llseek = seq_lseek, |
| 240 | .release = seq_release, |
| 241 | }; |
| 242 | |
Matt Wagantall | 665f0cf | 2012-02-27 15:54:43 -0800 | [diff] [blame] | 243 | static struct dentry *debugfs_base; |
| 244 | static u32 debug_suspend; |
Patrick Daly | 0a78a0e | 2012-07-23 13:18:59 -0700 | [diff] [blame] | 245 | |
Matt Wagantall | 665f0cf | 2012-02-27 15:54:43 -0800 | [diff] [blame] | 246 | struct clk_table { |
| 247 | struct list_head node; |
| 248 | struct clk_lookup *clocks; |
| 249 | size_t num_clocks; |
Patrick Daly | 0a78a0e | 2012-07-23 13:18:59 -0700 | [diff] [blame] | 250 | }; |
| 251 | |
Matt Wagantall | 665f0cf | 2012-02-27 15:54:43 -0800 | [diff] [blame] | 252 | static int clock_debug_add(struct clk *clock) |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 253 | { |
| 254 | char temp[50], *ptr; |
Stephen Boyd | 6e6d9b5 | 2011-01-26 16:20:55 -0800 | [diff] [blame] | 255 | struct dentry *clk_dir; |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 256 | |
Stephen Boyd | 6e6d9b5 | 2011-01-26 16:20:55 -0800 | [diff] [blame] | 257 | if (!debugfs_base) |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 258 | return -ENOMEM; |
| 259 | |
Saravana Kannan | 7f62698 | 2011-09-26 19:02:02 -0700 | [diff] [blame] | 260 | strlcpy(temp, clock->dbg_name, ARRAY_SIZE(temp)); |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 261 | for (ptr = temp; *ptr; ptr++) |
| 262 | *ptr = tolower(*ptr); |
| 263 | |
Stephen Boyd | 6e6d9b5 | 2011-01-26 16:20:55 -0800 | [diff] [blame] | 264 | clk_dir = debugfs_create_dir(temp, debugfs_base); |
| 265 | if (!clk_dir) |
| 266 | return -ENOMEM; |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 267 | |
Stephen Boyd | 6e6d9b5 | 2011-01-26 16:20:55 -0800 | [diff] [blame] | 268 | if (!debugfs_create_file("rate", S_IRUGO | S_IWUSR, clk_dir, |
| 269 | clock, &clock_rate_fops)) |
| 270 | goto error; |
| 271 | |
| 272 | if (!debugfs_create_file("enable", S_IRUGO | S_IWUSR, clk_dir, |
| 273 | clock, &clock_enable_fops)) |
| 274 | goto error; |
| 275 | |
| 276 | if (!debugfs_create_file("is_local", S_IRUGO, clk_dir, clock, |
| 277 | &clock_local_fops)) |
| 278 | goto error; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 279 | |
Stephen Boyd | a52d7e3 | 2011-11-10 11:59:00 -0800 | [diff] [blame] | 280 | if (!debugfs_create_file("has_hw_gating", S_IRUGO, clk_dir, clock, |
| 281 | &clock_hwcg_fops)) |
| 282 | goto error; |
| 283 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 284 | if (measure && |
| 285 | !clk_set_parent(measure, clock) && |
| 286 | !debugfs_create_file("measure", S_IRUGO, clk_dir, clock, |
| 287 | &clock_measure_fops)) |
| 288 | goto error; |
| 289 | |
| 290 | if (clock->ops->list_rate) |
| 291 | if (!debugfs_create_file("list_rates", |
| 292 | S_IRUGO, clk_dir, clock, &list_rates_fops)) |
| 293 | goto error; |
| 294 | |
Patrick Daly | 0a78a0e | 2012-07-23 13:18:59 -0700 | [diff] [blame] | 295 | if (clock->vdd_class && !debugfs_create_file("fmax_rates", |
| 296 | S_IRUGO, clk_dir, clock, &fmax_rates_fops)) |
| 297 | goto error; |
| 298 | |
Saravana Kannan | 531051f | 2012-09-27 16:19:07 -0700 | [diff] [blame] | 299 | if (!debugfs_create_file("parent", S_IRUGO, clk_dir, clock, |
| 300 | &clock_parent_fops)) |
| 301 | goto error; |
| 302 | |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 303 | return 0; |
Stephen Boyd | 6e6d9b5 | 2011-01-26 16:20:55 -0800 | [diff] [blame] | 304 | error: |
| 305 | debugfs_remove_recursive(clk_dir); |
| 306 | return -ENOMEM; |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 307 | } |
Matt Wagantall | 665f0cf | 2012-02-27 15:54:43 -0800 | [diff] [blame] | 308 | static LIST_HEAD(clk_list); |
| 309 | static DEFINE_SPINLOCK(clk_list_lock); |
| 310 | |
| 311 | /** |
| 312 | * clock_debug_register() - Add additional clocks to clock debugfs hierarchy |
| 313 | * @table: Table of clocks to create debugfs nodes for |
| 314 | * @size: Size of @table |
| 315 | * |
| 316 | * Use this function to register additional clocks in debugfs. The clock debugfs |
| 317 | * hierarchy must have already been initialized with clock_debug_init() prior to |
| 318 | * calling this function. Unlike clock_debug_init(), this may be called multiple |
| 319 | * times with different clock lists and can be used after the kernel has |
| 320 | * finished booting. |
| 321 | */ |
| 322 | int clock_debug_register(struct clk_lookup *table, size_t size) |
| 323 | { |
| 324 | struct clk_table *clk_table; |
| 325 | unsigned long flags; |
| 326 | int i; |
| 327 | |
| 328 | clk_table = kmalloc(sizeof(*clk_table), GFP_KERNEL); |
| 329 | if (!clk_table) |
| 330 | return -ENOMEM; |
| 331 | |
| 332 | clk_table->clocks = table; |
| 333 | clk_table->num_clocks = size; |
| 334 | |
| 335 | spin_lock_irqsave(&clk_list_lock, flags); |
| 336 | list_add_tail(&clk_table->node, &clk_list); |
| 337 | spin_unlock_irqrestore(&clk_list_lock, flags); |
| 338 | |
| 339 | for (i = 0; i < size; i++) |
| 340 | clock_debug_add(table[i].clk); |
| 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * clock_debug_init() - Initialize clock debugfs |
| 347 | */ |
| 348 | int __init clock_debug_init(void) |
| 349 | { |
| 350 | debugfs_base = debugfs_create_dir("clk", NULL); |
| 351 | if (!debugfs_base) |
| 352 | return -ENOMEM; |
| 353 | if (!debugfs_create_u32("debug_suspend", S_IRUGO | S_IWUSR, |
| 354 | debugfs_base, &debug_suspend)) { |
| 355 | debugfs_remove_recursive(debugfs_base); |
| 356 | return -ENOMEM; |
| 357 | } |
| 358 | |
| 359 | measure = clk_get_sys("debug", "measure"); |
| 360 | if (IS_ERR(measure)) |
| 361 | measure = NULL; |
| 362 | |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | static int clock_debug_print_clock(struct clk *c) |
| 367 | { |
| 368 | char *start = ""; |
| 369 | |
| 370 | if (!c || !c->prepare_count) |
| 371 | return 0; |
| 372 | |
| 373 | pr_info("\t"); |
| 374 | do { |
| 375 | if (c->vdd_class) |
| 376 | pr_cont("%s%s:%u:%u [%ld, %lu]", start, c->dbg_name, |
| 377 | c->prepare_count, c->count, c->rate, |
| 378 | c->vdd_class->cur_level); |
| 379 | else |
| 380 | pr_cont("%s%s:%u:%u [%ld]", start, c->dbg_name, |
| 381 | c->prepare_count, c->count, c->rate); |
| 382 | start = " -> "; |
| 383 | } while ((c = clk_get_parent(c))); |
| 384 | |
| 385 | pr_cont("\n"); |
| 386 | |
| 387 | return 1; |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * clock_debug_print_enabled() - Print names of enabled clocks for suspend debug |
| 392 | * |
| 393 | * Print the names of enabled clocks and their parents if debug_suspend is set |
| 394 | */ |
| 395 | void clock_debug_print_enabled(void) |
| 396 | { |
| 397 | struct clk_table *table; |
| 398 | unsigned long flags; |
| 399 | int i, cnt = 0; |
| 400 | |
| 401 | if (likely(!debug_suspend)) |
| 402 | return; |
| 403 | |
| 404 | pr_info("Enabled clocks:\n"); |
| 405 | spin_lock_irqsave(&clk_list_lock, flags); |
| 406 | list_for_each_entry(table, &clk_list, node) { |
| 407 | for (i = 0; i < table->num_clocks; i++) |
| 408 | cnt += clock_debug_print_clock(table->clocks[i].clk); |
| 409 | } |
| 410 | spin_unlock_irqrestore(&clk_list_lock, flags); |
| 411 | |
| 412 | if (cnt) |
| 413 | pr_info("Enabled clock count: %d\n", cnt); |
| 414 | else |
| 415 | pr_info("No clocks enabled.\n"); |
| 416 | |
| 417 | } |