Daniel Lezcano | 7c15fad | 2016-02-18 15:57:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Power debug tool (powerdebug) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 3 | * |
Daniel Lezcano | 7c15fad | 2016-02-18 15:57:43 +0000 | [diff] [blame] | 4 | * Copyright (C) 2016, Linaro Limited. |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 5 | * |
Daniel Lezcano | 7c15fad | 2016-02-18 15:57:43 +0000 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version 2 |
| 9 | * of the License, or (at your option) any later version. |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 10 | * |
Daniel Lezcano | 7c15fad | 2016-02-18 15:57:43 +0000 | [diff] [blame] | 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 15 | * |
Daniel Lezcano | 7c15fad | 2016-02-18 15:57:43 +0000 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 19 | * |
Daniel Lezcano | 7c15fad | 2016-02-18 15:57:43 +0000 | [diff] [blame] | 20 | */ |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 21 | |
Daniel Lezcano | 141c048 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 22 | #ifndef _GNU_SOURCE |
| 23 | #define _GNU_SOURCE |
Daniel Lezcano | 9dc3fb3 | 2011-03-26 22:06:08 +0100 | [diff] [blame] | 24 | #include <stdio.h> |
Daniel Lezcano | 141c048 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 25 | #undef _GNU_SOURCE |
| 26 | #endif |
Daniel Lezcano | 1562748 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 27 | #include <string.h> |
| 28 | #include <stdbool.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <unistd.h> |
| 31 | #include <sys/param.h> |
Daniel Lezcano | 9dc3fb3 | 2011-03-26 22:06:08 +0100 | [diff] [blame] | 32 | #include <mntent.h> |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 33 | #include <sys/stat.h> |
Daniel Lezcano | 9dc3fb3 | 2011-03-26 22:06:08 +0100 | [diff] [blame] | 34 | |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 35 | #include "powerdebug.h" |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 36 | #include "display.h" |
Daniel Lezcano | c193b60 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 37 | #include "tree.h" |
Daniel Lezcano | 88b38e3 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 38 | #include "utils.h" |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 39 | |
Shaojie Sun | 73e5d97 | 2013-08-21 17:04:34 +0800 | [diff] [blame] | 40 | #ifndef uint |
| 41 | #define uint unsigned int |
| 42 | #endif |
| 43 | |
| 44 | |
Daniel Lezcano | c45662b | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 45 | struct clock_info { |
Daniel Lezcano | c45662b | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 46 | int flags; |
Shaojie Sun | 73e5d97 | 2013-08-21 17:04:34 +0800 | [diff] [blame] | 47 | uint rate; |
Daniel Lezcano | c45662b | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 48 | int usecount; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 49 | bool expanded; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 50 | char *prefix; |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 51 | int preparecount; |
| 52 | int enablecount; |
| 53 | int notifiercount; |
Daniel Lezcano | c45662b | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 54 | } *clocks_info; |
| 55 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 56 | enum clock_fw_type{ |
| 57 | CCF, /* common clock framework */ |
| 58 | OCF, /* old clock framework */ |
| 59 | MAX, |
| 60 | }; |
| 61 | |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 62 | static struct tree *clock_tree = NULL; |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 63 | static int clock_fw; |
Daniel Lezcano | c193b60 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 64 | |
Daniel Lezcano | 9dc3fb3 | 2011-03-26 22:06:08 +0100 | [diff] [blame] | 65 | static int locate_debugfs(char *clk_path) |
| 66 | { |
Nishanth Menon | a14971b | 2011-09-20 11:31:17 +0200 | [diff] [blame] | 67 | strcpy(clk_path, "/sys/kernel/debug"); |
| 68 | return 0; |
Daniel Lezcano | 9dc3fb3 | 2011-03-26 22:06:08 +0100 | [diff] [blame] | 69 | } |
| 70 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 71 | static struct clock_info *clock_alloc(void) |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 72 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 73 | struct clock_info *ci; |
Daniel Lezcano | 9dc3fb3 | 2011-03-26 22:06:08 +0100 | [diff] [blame] | 74 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 75 | ci = malloc(sizeof(*ci)); |
| 76 | if (ci) |
| 77 | memset(ci, 0, sizeof(*ci)); |
Daniel Lezcano | c5a65bf | 2011-03-26 22:06:11 +0100 | [diff] [blame] | 78 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 79 | return ci; |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 80 | } |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 81 | |
Shaojie Sun | 2489bc7 | 2013-08-21 17:27:33 +0800 | [diff] [blame] | 82 | static inline bool is_hex_clock(uint rate) |
| 83 | { |
| 84 | return rate%10; |
| 85 | } |
| 86 | |
Shaojie Sun | 73e5d97 | 2013-08-21 17:04:34 +0800 | [diff] [blame] | 87 | static inline const char *clock_rate(uint *rate) |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 88 | { |
Shaojie Sun | 2489bc7 | 2013-08-21 17:27:33 +0800 | [diff] [blame] | 89 | uint r, mod; |
| 90 | bool is_hex = is_hex_clock(*rate); |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 91 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 92 | /* GHZ */ |
Shaojie Sun | 2489bc7 | 2013-08-21 17:27:33 +0800 | [diff] [blame] | 93 | if (is_hex) { |
| 94 | r = *rate >> 30; |
| 95 | mod = *rate&((1<<30)-1); |
| 96 | } else { |
| 97 | r = *rate / 1000000000; |
| 98 | mod = *rate % 1000000000; |
| 99 | } |
| 100 | if (r && !mod) { |
| 101 | *rate = r; |
| 102 | return "GHZ"; |
| 103 | } |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 104 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 105 | /* MHZ */ |
Shaojie Sun | 2489bc7 | 2013-08-21 17:27:33 +0800 | [diff] [blame] | 106 | if (is_hex) { |
| 107 | r = *rate >> 20; |
| 108 | mod = *rate&((1<<20)-1); |
| 109 | } else { |
| 110 | r = *rate / 1000000; |
| 111 | mod = *rate % 1000000; |
| 112 | } |
| 113 | if (r && !mod) { |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 114 | *rate = r; |
| 115 | return "MHZ"; |
| 116 | } |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 117 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 118 | /* KHZ */ |
Shaojie Sun | 2489bc7 | 2013-08-21 17:27:33 +0800 | [diff] [blame] | 119 | if (is_hex) { |
| 120 | r = *rate >> 10; |
| 121 | mod = *rate&((1<<10)-1); |
| 122 | } else { |
| 123 | r = *rate / 1000; |
| 124 | mod = *rate % 1000; |
| 125 | } |
| 126 | if (r && !mod) { |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 127 | *rate = r; |
| 128 | return "KHZ"; |
| 129 | } |
| 130 | |
| 131 | return ""; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 132 | } |
| 133 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 134 | static int dump_clock_cb(struct tree *t, void *data) |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 135 | { |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 136 | struct clock_info *clk = t->private; |
| 137 | struct clock_info *pclk; |
| 138 | const char *unit; |
| 139 | int ret = 0; |
Shaojie Sun | 73e5d97 | 2013-08-21 17:04:34 +0800 | [diff] [blame] | 140 | uint rate = clk->rate; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 141 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 142 | if (!t->parent) { |
| 143 | printf("/\n"); |
| 144 | clk->prefix = ""; |
| 145 | return 0; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 146 | } |
| 147 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 148 | pclk = t->parent->private; |
| 149 | |
| 150 | if (!clk->prefix) |
| 151 | ret = asprintf(&clk->prefix, "%s%s%s", pclk->prefix, |
| 152 | t->depth > 1 ? " ": "", t->next ? "|" : " "); |
| 153 | if (ret < 0) |
| 154 | return -1; |
| 155 | |
| 156 | unit = clock_rate(&rate); |
| 157 | |
Shaojie Sun | 73e5d97 | 2013-08-21 17:04:34 +0800 | [diff] [blame] | 158 | printf("%s%s-- %s (flags:0x%x, usecount:%d, rate: %u %s)\n", |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 159 | clk->prefix, !t->next ? "`" : "", t->name, clk->flags, |
| 160 | clk->usecount, rate, unit); |
| 161 | |
| 162 | return 0; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 165 | int dump_clock_info(void) |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 166 | { |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 167 | return tree_for_each(clock_tree, dump_clock_cb, NULL); |
| 168 | } |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 169 | |
Daniel Lezcano | 3e38e0f | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 170 | static int dump_all_parents(char *clkarg) |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 171 | { |
| 172 | struct tree *tree; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 173 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 174 | tree = tree_find(clock_tree, clkarg); |
| 175 | if (!tree) { |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 176 | printf("Clock NOT found!\n"); |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 177 | return -1; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 178 | } |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 179 | |
| 180 | return tree_for_each_parent(tree, dump_clock_cb, NULL); |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 181 | } |
| 182 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 183 | static inline int read_clock_cb(struct tree *t, void *data) |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 184 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 185 | struct clock_info *clk = t->private; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 186 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 187 | if(clock_fw == CCF) { |
| 188 | file_read_value(t->path, "clk_flags", "%x", &clk->flags); |
Shaojie Sun | 73e5d97 | 2013-08-21 17:04:34 +0800 | [diff] [blame] | 189 | file_read_value(t->path, "clk_rate", "%u", &clk->rate); |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 190 | file_read_value(t->path, "clk_prepare_count", "%d", &clk->preparecount); |
| 191 | file_read_value(t->path, "clk_enable_count", "%d", &clk->enablecount); |
| 192 | file_read_value(t->path, "clk_notifier_count", "%d", &clk->notifiercount); |
| 193 | } |
| 194 | else { |
| 195 | file_read_value(t->path, "flags", "%x", &clk->flags); |
Shaojie Sun | 73e5d97 | 2013-08-21 17:04:34 +0800 | [diff] [blame] | 196 | file_read_value(t->path, "rate", "%u", &clk->rate); |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 197 | file_read_value(t->path, "usecount", "%d", &clk->usecount); |
| 198 | } |
Amit Arora | 3bc8c92 | 2010-11-16 11:27:38 +0530 | [diff] [blame] | 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 203 | static int read_clock_info(struct tree *tree) |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 204 | { |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 205 | return tree_for_each(tree, read_clock_cb, NULL); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 206 | } |
| 207 | |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 208 | static int fill_clock_cb(struct tree *t, void *data) |
| 209 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 210 | struct clock_info *clk; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 211 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 212 | clk = clock_alloc(); |
| 213 | if (!clk) |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 214 | return -1; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 215 | t->private = clk; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 216 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 217 | /* we skip the root node but we set it expanded for its children */ |
| 218 | if (!t->parent) { |
| 219 | clk->expanded = true; |
| 220 | return 0; |
| 221 | } |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 222 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 223 | return read_clock_cb(t, data); |
| 224 | } |
| 225 | |
| 226 | static int fill_clock_tree(void) |
| 227 | { |
| 228 | return tree_for_each(clock_tree, fill_clock_cb, NULL); |
| 229 | } |
| 230 | |
| 231 | static int is_collapsed(struct tree *t, void *data) |
| 232 | { |
| 233 | struct clock_info *clk = t->private; |
| 234 | |
| 235 | if (!clk->expanded) |
| 236 | return 1; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 241 | static char *clock_line(struct tree *t) |
Amit Arora | eb6cba9 | 2010-10-25 16:03:21 +0530 | [diff] [blame] | 242 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 243 | struct clock_info *clk; |
Shaojie Sun | 73e5d97 | 2013-08-21 17:04:34 +0800 | [diff] [blame] | 244 | uint rate; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 245 | const char *clkunit; |
| 246 | char *clkrate, *clkname, *clkline = NULL; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 247 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 248 | clk = t->private; |
| 249 | rate = clk->rate; |
| 250 | clkunit = clock_rate(&rate); |
| 251 | |
| 252 | if (asprintf(&clkname, "%*s%s", (t->depth - 1) * 2, "", t->name) < 0) |
| 253 | return NULL; |
| 254 | |
| 255 | if (asprintf(&clkrate, "%d%s", rate, clkunit) < 0) |
| 256 | goto free_clkname; |
| 257 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 258 | if(clock_fw == CCF) { |
| 259 | if (asprintf(&clkline, "%-35s 0x%-8x %-12s %-10d %-11d %-15d %-14d %-10d", |
| 260 | clkname, clk->flags, clkrate, clk->usecount, t->nrchild, |
| 261 | clk->preparecount, clk->enablecount, clk->notifiercount) < 0) |
| 262 | goto free_clkrate; |
| 263 | } |
| 264 | else { |
| 265 | if (asprintf(&clkline, "%-55s 0x%-16x %-12s %-9d %-8d", |
| 266 | clkname, clk->flags, clkrate, clk->usecount, t->nrchild) < 0) |
| 267 | goto free_clkrate; |
| 268 | } |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 269 | |
| 270 | free_clkrate: |
| 271 | free(clkrate); |
| 272 | free_clkname: |
| 273 | free(clkname); |
| 274 | |
| 275 | return clkline; |
| 276 | } |
| 277 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 278 | static int _clock_print_info_cb(struct tree *t, void *data) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 279 | { |
| 280 | struct clock_info *clock = t->private; |
| 281 | int *line = data; |
| 282 | char *buffer; |
| 283 | |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 284 | /* we skip the root node of the tree */ |
| 285 | if (!t->parent) |
| 286 | return 0; |
| 287 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 288 | buffer = clock_line(t); |
| 289 | if (!buffer) |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 290 | return -1; |
| 291 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 292 | display_print_line(CLOCK, *line, buffer, clock->usecount, t); |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 293 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 294 | (*line)++; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 295 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 296 | free(buffer); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 297 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 298 | return 0; |
| 299 | } |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 300 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 301 | static int clock_print_info_cb(struct tree *t, void *data) |
| 302 | { |
Daniel Lezcano | d577aaa | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 303 | /* we skip the root node of the tree */ |
| 304 | if (!t->parent) |
| 305 | return 0; |
| 306 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 307 | /* show the clock when *all* its parent is expanded */ |
| 308 | if (tree_for_each_parent(t->parent, is_collapsed, NULL)) |
| 309 | return 0; |
| 310 | |
| 311 | return _clock_print_info_cb(t, data); |
| 312 | } |
| 313 | |
Daniel Lezcano | fa45333 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 314 | static int clock_print_header(void) |
| 315 | { |
| 316 | char *buf; |
| 317 | int ret; |
| 318 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 319 | if(clock_fw == CCF) { |
| 320 | if (asprintf(&buf, "%-35s %-10s %-12s %-10s %-11s %-15s %-14s %-14s", |
| 321 | "Name", "Flags", "Rate", "Usecount", "Children", "Prepare_Count", |
| 322 | "Enable_Count", "Notifier_Count") < 0) |
| 323 | return -1; |
| 324 | } |
| 325 | else { |
| 326 | if (asprintf(&buf, "%-55s %-16s %-12s %-9s %-8s", |
Daniel Lezcano | fa45333 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 327 | "Name", "Flags", "Rate", "Usecount", "Children") < 0) |
| 328 | return -1; |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 329 | } |
Daniel Lezcano | fa45333 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 330 | |
Daniel Lezcano | 372ffba | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 331 | ret = display_column_name(buf); |
Daniel Lezcano | fa45333 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 332 | |
| 333 | free(buf); |
| 334 | |
| 335 | return ret; |
| 336 | } |
| 337 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 338 | static int clock_print_info(struct tree *tree) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 339 | { |
| 340 | int ret, line = 0; |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 341 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 342 | display_reset_cursor(CLOCK); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 343 | |
Daniel Lezcano | fa45333 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 344 | clock_print_header(); |
| 345 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 346 | ret = tree_for_each(tree, clock_print_info_cb, &line); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 347 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 348 | display_refresh_pad(CLOCK); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 349 | |
| 350 | return ret; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 351 | } |
| 352 | |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 353 | static int clock_select(void) |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 354 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 355 | struct tree *t = display_get_row_data(CLOCK); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 356 | struct clock_info *clk = t->private; |
| 357 | |
| 358 | clk->expanded = !clk->expanded; |
| 359 | |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | /* |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 364 | * Read the clock information and fill the tree with the information |
| 365 | * found in the files. Then print the result to the text based interface |
| 366 | * Return 0 on success, < 0 otherwise |
| 367 | */ |
Daniel Lezcano | d577aaa | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 368 | static int clock_display(bool refresh) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 369 | { |
Daniel Lezcano | d577aaa | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 370 | if (refresh && read_clock_info(clock_tree)) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 371 | return -1; |
| 372 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 373 | return clock_print_info(clock_tree); |
| 374 | } |
| 375 | |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 376 | static int clock_find(const char *name) |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 377 | { |
| 378 | struct tree **ptree = NULL; |
| 379 | int i, nr, line = 0, ret = 0; |
| 380 | |
| 381 | nr = tree_finds(clock_tree, name, &ptree); |
| 382 | |
| 383 | display_reset_cursor(CLOCK); |
| 384 | |
| 385 | for (i = 0; i < nr; i++) { |
| 386 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 387 | ret = _clock_print_info_cb(ptree[i], &line); |
| 388 | if (ret) |
| 389 | break; |
Daniel Lezcano | d577aaa | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 390 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | display_refresh_pad(CLOCK); |
| 394 | |
| 395 | free(ptree); |
| 396 | |
| 397 | return ret; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 398 | } |
| 399 | |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 400 | static int clock_selectf(void) |
| 401 | { |
| 402 | struct tree *t = display_get_row_data(CLOCK); |
| 403 | int line = 0; |
| 404 | |
| 405 | display_reset_cursor(CLOCK); |
| 406 | |
| 407 | if (tree_for_each_parent(t, _clock_print_info_cb, &line)) |
| 408 | return -1; |
| 409 | |
| 410 | return display_refresh_pad(CLOCK); |
| 411 | } |
| 412 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 413 | /* |
| 414 | * Read the clock information and fill the tree with the information |
| 415 | * found in the files. Then dump to stdout a formatted result. |
| 416 | * @clk : a name for a specific clock we want to show |
| 417 | * Return 0 on success, < 0 otherwise |
| 418 | */ |
Daniel Lezcano | 597892a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 419 | int clock_dump(char *clk) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 420 | { |
| 421 | int ret; |
| 422 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 423 | if (read_clock_info(clock_tree)) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 424 | return -1; |
Amit Arora | eb6cba9 | 2010-10-25 16:03:21 +0530 | [diff] [blame] | 425 | |
Daniel Lezcano | c789194 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 426 | if (clk) { |
| 427 | printf("\nParents for \"%s\" Clock :\n\n", clk); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 428 | ret = dump_all_parents(clk); |
Daniel Lezcano | c789194 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 429 | printf("\n\n"); |
| 430 | } else { |
| 431 | printf("\nClock Tree :\n"); |
| 432 | printf("**********\n"); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 433 | ret = dump_clock_info(); |
Daniel Lezcano | c789194 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 434 | printf("\n\n"); |
| 435 | } |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 436 | |
| 437 | return ret; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 438 | } |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 439 | |
| 440 | static struct display_ops clock_ops = { |
| 441 | .display = clock_display, |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 442 | .select = clock_select, |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 443 | .find = clock_find, |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 444 | .selectf = clock_selectf, |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 445 | }; |
| 446 | |
| 447 | /* |
| 448 | * Initialize the clock framework |
| 449 | */ |
Daniel Lezcano | b4eec7e | 2016-02-18 16:44:55 +0000 | [diff] [blame^] | 450 | int clock_init(struct powerdebug_options *options) |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 451 | { |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 452 | char clk_dir_path[MAX+1][PATH_MAX]; |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 453 | |
Daniel Lezcano | b4eec7e | 2016-02-18 16:44:55 +0000 | [diff] [blame^] | 454 | if (!(options->flags & CLOCK_OPTION)) |
| 455 | return 0; |
| 456 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 457 | if (locate_debugfs(clk_dir_path[CCF]) || locate_debugfs(clk_dir_path[OCF])) |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 458 | return -1; |
| 459 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 460 | sprintf(clk_dir_path[CCF], "%s/clk", clk_dir_path[CCF]); |
| 461 | sprintf(clk_dir_path[OCF], "%s/clock", clk_dir_path[OCF]); |
| 462 | if (!access(clk_dir_path[CCF], F_OK)) { |
| 463 | clock_fw = CCF; |
| 464 | strcpy(clk_dir_path[MAX],clk_dir_path[CCF]); |
| 465 | } |
| 466 | else if(!access(clk_dir_path[OCF], F_OK)) { |
| 467 | clock_fw = OCF; |
| 468 | strcpy(clk_dir_path[MAX],clk_dir_path[OCF]); |
| 469 | } |
| 470 | else |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 471 | return -1; |
| 472 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 473 | clock_tree = tree_load(clk_dir_path[MAX], NULL, false); |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 474 | if (!clock_tree) |
| 475 | return -1; |
| 476 | |
Daniel Lezcano | caafece | 2011-06-27 22:59:17 +0200 | [diff] [blame] | 477 | if (fill_clock_tree()) |
| 478 | return -1; |
| 479 | |
| 480 | return display_register(CLOCK, &clock_ops); |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 481 | } |