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