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 | 2489bc7 | 2013-08-21 17:27:33 +0800 | [diff] [blame] | 81 | static inline bool is_hex_clock(uint rate) |
| 82 | { |
| 83 | return rate%10; |
| 84 | } |
| 85 | |
Shaojie Sun | 73e5d97 | 2013-08-21 17:04:34 +0800 | [diff] [blame] | 86 | static inline const char *clock_rate(uint *rate) |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 87 | { |
Shaojie Sun | 2489bc7 | 2013-08-21 17:27:33 +0800 | [diff] [blame] | 88 | uint r, mod; |
| 89 | bool is_hex = is_hex_clock(*rate); |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 90 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 91 | /* GHZ */ |
Shaojie Sun | 2489bc7 | 2013-08-21 17:27:33 +0800 | [diff] [blame] | 92 | if (is_hex) { |
| 93 | r = *rate >> 30; |
| 94 | mod = *rate&((1<<30)-1); |
| 95 | } else { |
| 96 | r = *rate / 1000000000; |
| 97 | mod = *rate % 1000000000; |
| 98 | } |
| 99 | if (r && !mod) { |
| 100 | *rate = r; |
| 101 | return "GHZ"; |
| 102 | } |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 103 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 104 | /* MHZ */ |
Shaojie Sun | 2489bc7 | 2013-08-21 17:27:33 +0800 | [diff] [blame] | 105 | if (is_hex) { |
| 106 | r = *rate >> 20; |
| 107 | mod = *rate&((1<<20)-1); |
| 108 | } else { |
| 109 | r = *rate / 1000000; |
| 110 | mod = *rate % 1000000; |
| 111 | } |
| 112 | if (r && !mod) { |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 113 | *rate = r; |
| 114 | return "MHZ"; |
| 115 | } |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 116 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 117 | /* KHZ */ |
Shaojie Sun | 2489bc7 | 2013-08-21 17:27:33 +0800 | [diff] [blame] | 118 | if (is_hex) { |
| 119 | r = *rate >> 10; |
| 120 | mod = *rate&((1<<10)-1); |
| 121 | } else { |
| 122 | r = *rate / 1000; |
| 123 | mod = *rate % 1000; |
| 124 | } |
| 125 | if (r && !mod) { |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 126 | *rate = r; |
| 127 | return "KHZ"; |
| 128 | } |
| 129 | |
| 130 | return ""; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 131 | } |
| 132 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 133 | static int dump_clock_cb(struct tree *t, void *data) |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 134 | { |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 135 | struct clock_info *clk = t->private; |
| 136 | struct clock_info *pclk; |
| 137 | const char *unit; |
| 138 | int ret = 0; |
Shaojie Sun | 73e5d97 | 2013-08-21 17:04:34 +0800 | [diff] [blame] | 139 | uint rate = clk->rate; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 140 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 141 | if (!t->parent) { |
| 142 | printf("/\n"); |
| 143 | clk->prefix = ""; |
| 144 | return 0; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 145 | } |
| 146 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 147 | pclk = t->parent->private; |
| 148 | |
| 149 | if (!clk->prefix) |
| 150 | ret = asprintf(&clk->prefix, "%s%s%s", pclk->prefix, |
| 151 | t->depth > 1 ? " ": "", t->next ? "|" : " "); |
| 152 | if (ret < 0) |
| 153 | return -1; |
| 154 | |
| 155 | unit = clock_rate(&rate); |
| 156 | |
Shaojie Sun | 73e5d97 | 2013-08-21 17:04:34 +0800 | [diff] [blame] | 157 | 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] | 158 | clk->prefix, !t->next ? "`" : "", t->name, clk->flags, |
| 159 | clk->usecount, rate, unit); |
| 160 | |
| 161 | return 0; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 162 | } |
| 163 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 164 | int dump_clock_info(void) |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 165 | { |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 166 | return tree_for_each(clock_tree, dump_clock_cb, NULL); |
| 167 | } |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 168 | |
Daniel Lezcano | 3e38e0f | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 169 | static int dump_all_parents(char *clkarg) |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 170 | { |
| 171 | struct tree *tree; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 172 | |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 173 | tree = tree_find(clock_tree, clkarg); |
| 174 | if (!tree) { |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 175 | printf("Clock NOT found!\n"); |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 176 | return -1; |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 177 | } |
Daniel Lezcano | afe6225 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 178 | |
| 179 | return tree_for_each_parent(tree, dump_clock_cb, NULL); |
Daniel Lezcano | c671833 | 2011-03-23 14:37:39 +0100 | [diff] [blame] | 180 | } |
| 181 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 182 | static inline int read_clock_cb(struct tree *t, void *data) |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 183 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 184 | struct clock_info *clk = t->private; |
Daniel Lezcano | ef32319 | 2011-03-26 22:06:20 +0100 | [diff] [blame] | 185 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 186 | if(clock_fw == CCF) { |
| 187 | file_read_value(t->path, "clk_flags", "%x", &clk->flags); |
Shaojie Sun | 73e5d97 | 2013-08-21 17:04:34 +0800 | [diff] [blame] | 188 | file_read_value(t->path, "clk_rate", "%u", &clk->rate); |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 189 | file_read_value(t->path, "clk_prepare_count", "%d", &clk->preparecount); |
| 190 | file_read_value(t->path, "clk_enable_count", "%d", &clk->enablecount); |
| 191 | file_read_value(t->path, "clk_notifier_count", "%d", &clk->notifiercount); |
| 192 | } |
| 193 | else { |
| 194 | file_read_value(t->path, "flags", "%x", &clk->flags); |
Shaojie Sun | 73e5d97 | 2013-08-21 17:04:34 +0800 | [diff] [blame] | 195 | file_read_value(t->path, "rate", "%u", &clk->rate); |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 196 | file_read_value(t->path, "usecount", "%d", &clk->usecount); |
| 197 | } |
Amit Arora | 3bc8c92 | 2010-11-16 11:27:38 +0530 | [diff] [blame] | 198 | |
| 199 | return 0; |
| 200 | } |
| 201 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 202 | static int read_clock_info(struct tree *tree) |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 203 | { |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 204 | return tree_for_each(tree, read_clock_cb, NULL); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 205 | } |
| 206 | |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 207 | static int fill_clock_cb(struct tree *t, void *data) |
| 208 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 209 | struct clock_info *clk; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 210 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 211 | clk = clock_alloc(); |
| 212 | if (!clk) |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 213 | return -1; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 214 | t->private = clk; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 215 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 216 | /* we skip the root node but we set it expanded for its children */ |
| 217 | if (!t->parent) { |
| 218 | clk->expanded = true; |
| 219 | return 0; |
| 220 | } |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 221 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 222 | return read_clock_cb(t, data); |
| 223 | } |
| 224 | |
| 225 | static int fill_clock_tree(void) |
| 226 | { |
| 227 | return tree_for_each(clock_tree, fill_clock_cb, NULL); |
| 228 | } |
| 229 | |
| 230 | static int is_collapsed(struct tree *t, void *data) |
| 231 | { |
| 232 | struct clock_info *clk = t->private; |
| 233 | |
| 234 | if (!clk->expanded) |
| 235 | return 1; |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 240 | static char *clock_line(struct tree *t) |
Amit Arora | eb6cba9 | 2010-10-25 16:03:21 +0530 | [diff] [blame] | 241 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 242 | struct clock_info *clk; |
Shaojie Sun | 73e5d97 | 2013-08-21 17:04:34 +0800 | [diff] [blame] | 243 | uint rate; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 244 | const char *clkunit; |
| 245 | char *clkrate, *clkname, *clkline = NULL; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 246 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 247 | clk = t->private; |
| 248 | rate = clk->rate; |
| 249 | clkunit = clock_rate(&rate); |
| 250 | |
| 251 | if (asprintf(&clkname, "%*s%s", (t->depth - 1) * 2, "", t->name) < 0) |
| 252 | return NULL; |
| 253 | |
| 254 | if (asprintf(&clkrate, "%d%s", rate, clkunit) < 0) |
| 255 | goto free_clkname; |
| 256 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 257 | if(clock_fw == CCF) { |
| 258 | if (asprintf(&clkline, "%-35s 0x%-8x %-12s %-10d %-11d %-15d %-14d %-10d", |
| 259 | clkname, clk->flags, clkrate, clk->usecount, t->nrchild, |
| 260 | clk->preparecount, clk->enablecount, clk->notifiercount) < 0) |
| 261 | goto free_clkrate; |
| 262 | } |
| 263 | else { |
| 264 | if (asprintf(&clkline, "%-55s 0x%-16x %-12s %-9d %-8d", |
| 265 | clkname, clk->flags, clkrate, clk->usecount, t->nrchild) < 0) |
| 266 | goto free_clkrate; |
| 267 | } |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 268 | |
| 269 | free_clkrate: |
| 270 | free(clkrate); |
| 271 | free_clkname: |
| 272 | free(clkname); |
| 273 | |
| 274 | return clkline; |
| 275 | } |
| 276 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 277 | static int _clock_print_info_cb(struct tree *t, void *data) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 278 | { |
| 279 | struct clock_info *clock = t->private; |
| 280 | int *line = data; |
| 281 | char *buffer; |
| 282 | |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 283 | /* we skip the root node of the tree */ |
| 284 | if (!t->parent) |
| 285 | return 0; |
| 286 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 287 | buffer = clock_line(t); |
| 288 | if (!buffer) |
Daniel Lezcano | 9d5431c | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 289 | return -1; |
| 290 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 291 | display_print_line(CLOCK, *line, buffer, clock->usecount, t); |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 292 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 293 | (*line)++; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 294 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 295 | free(buffer); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 296 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 297 | return 0; |
| 298 | } |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 299 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 300 | static int clock_print_info_cb(struct tree *t, void *data) |
| 301 | { |
Daniel Lezcano | d577aaa | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 302 | /* we skip the root node of the tree */ |
| 303 | if (!t->parent) |
| 304 | return 0; |
| 305 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 306 | /* show the clock when *all* its parent is expanded */ |
| 307 | if (tree_for_each_parent(t->parent, is_collapsed, NULL)) |
| 308 | return 0; |
| 309 | |
| 310 | return _clock_print_info_cb(t, data); |
| 311 | } |
| 312 | |
Daniel Lezcano | fa45333 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 313 | static int clock_print_header(void) |
| 314 | { |
| 315 | char *buf; |
| 316 | int ret; |
| 317 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 318 | if(clock_fw == CCF) { |
| 319 | if (asprintf(&buf, "%-35s %-10s %-12s %-10s %-11s %-15s %-14s %-14s", |
| 320 | "Name", "Flags", "Rate", "Usecount", "Children", "Prepare_Count", |
| 321 | "Enable_Count", "Notifier_Count") < 0) |
| 322 | return -1; |
| 323 | } |
| 324 | else { |
| 325 | if (asprintf(&buf, "%-55s %-16s %-12s %-9s %-8s", |
Daniel Lezcano | fa45333 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 326 | "Name", "Flags", "Rate", "Usecount", "Children") < 0) |
| 327 | return -1; |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 328 | } |
Daniel Lezcano | fa45333 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 329 | |
Daniel Lezcano | 372ffba | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 330 | ret = display_column_name(buf); |
Daniel Lezcano | fa45333 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 331 | |
| 332 | free(buf); |
| 333 | |
| 334 | return ret; |
| 335 | } |
| 336 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 337 | static int clock_print_info(struct tree *tree) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 338 | { |
| 339 | int ret, line = 0; |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 340 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 341 | display_reset_cursor(CLOCK); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 342 | |
Daniel Lezcano | fa45333 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 343 | clock_print_header(); |
| 344 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 345 | ret = tree_for_each(tree, clock_print_info_cb, &line); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 346 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 347 | display_refresh_pad(CLOCK); |
Daniel Lezcano | b2565a8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 348 | |
| 349 | return ret; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 350 | } |
| 351 | |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 352 | static int clock_select(void) |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 353 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 354 | struct tree *t = display_get_row_data(CLOCK); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 355 | struct clock_info *clk = t->private; |
| 356 | |
| 357 | clk->expanded = !clk->expanded; |
| 358 | |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | /* |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 363 | * Read the clock information and fill the tree with the information |
| 364 | * found in the files. Then print the result to the text based interface |
| 365 | * Return 0 on success, < 0 otherwise |
| 366 | */ |
Daniel Lezcano | d577aaa | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 367 | static int clock_display(bool refresh) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 368 | { |
Daniel Lezcano | d577aaa | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 369 | if (refresh && read_clock_info(clock_tree)) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 370 | return -1; |
| 371 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 372 | return clock_print_info(clock_tree); |
| 373 | } |
| 374 | |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 375 | static int clock_find(const char *name) |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 376 | { |
| 377 | struct tree **ptree = NULL; |
| 378 | int i, nr, line = 0, ret = 0; |
| 379 | |
| 380 | nr = tree_finds(clock_tree, name, &ptree); |
| 381 | |
| 382 | display_reset_cursor(CLOCK); |
| 383 | |
| 384 | for (i = 0; i < nr; i++) { |
| 385 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 386 | ret = _clock_print_info_cb(ptree[i], &line); |
| 387 | if (ret) |
| 388 | break; |
Daniel Lezcano | d577aaa | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 389 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | display_refresh_pad(CLOCK); |
| 393 | |
| 394 | free(ptree); |
| 395 | |
| 396 | return ret; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 397 | } |
| 398 | |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 399 | static int clock_selectf(void) |
| 400 | { |
| 401 | struct tree *t = display_get_row_data(CLOCK); |
| 402 | int line = 0; |
| 403 | |
| 404 | display_reset_cursor(CLOCK); |
| 405 | |
| 406 | if (tree_for_each_parent(t, _clock_print_info_cb, &line)) |
| 407 | return -1; |
| 408 | |
| 409 | return display_refresh_pad(CLOCK); |
| 410 | } |
| 411 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 412 | /* |
| 413 | * Read the clock information and fill the tree with the information |
| 414 | * found in the files. Then dump to stdout a formatted result. |
| 415 | * @clk : a name for a specific clock we want to show |
| 416 | * Return 0 on success, < 0 otherwise |
| 417 | */ |
Daniel Lezcano | 597892a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 418 | int clock_dump(char *clk) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 419 | { |
| 420 | int ret; |
| 421 | |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 422 | if (read_clock_info(clock_tree)) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 423 | return -1; |
Amit Arora | eb6cba9 | 2010-10-25 16:03:21 +0530 | [diff] [blame] | 424 | |
Daniel Lezcano | c789194 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 425 | if (clk) { |
| 426 | printf("\nParents for \"%s\" Clock :\n\n", clk); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 427 | ret = dump_all_parents(clk); |
Daniel Lezcano | c789194 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 428 | printf("\n\n"); |
| 429 | } else { |
| 430 | printf("\nClock Tree :\n"); |
| 431 | printf("**********\n"); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 432 | ret = dump_clock_info(); |
Daniel Lezcano | c789194 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 433 | printf("\n\n"); |
| 434 | } |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 435 | |
| 436 | return ret; |
Daniel Lezcano | 28b53cd | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 437 | } |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 438 | |
| 439 | static struct display_ops clock_ops = { |
| 440 | .display = clock_display, |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 441 | .select = clock_select, |
Daniel Lezcano | a12163d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 442 | .find = clock_find, |
Daniel Lezcano | 73b4002 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 443 | .selectf = clock_selectf, |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 444 | }; |
| 445 | |
| 446 | /* |
| 447 | * Initialize the clock framework |
| 448 | */ |
| 449 | int clock_init(void) |
| 450 | { |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 451 | char clk_dir_path[MAX+1][PATH_MAX]; |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 452 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 453 | 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] | 454 | return -1; |
| 455 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 456 | sprintf(clk_dir_path[CCF], "%s/clk", clk_dir_path[CCF]); |
| 457 | sprintf(clk_dir_path[OCF], "%s/clock", clk_dir_path[OCF]); |
| 458 | if (!access(clk_dir_path[CCF], F_OK)) { |
| 459 | clock_fw = CCF; |
| 460 | strcpy(clk_dir_path[MAX],clk_dir_path[CCF]); |
| 461 | } |
| 462 | else if(!access(clk_dir_path[OCF], F_OK)) { |
| 463 | clock_fw = OCF; |
| 464 | strcpy(clk_dir_path[MAX],clk_dir_path[OCF]); |
| 465 | } |
| 466 | else |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 467 | return -1; |
| 468 | |
Sanjay Singh Rawat | 88fdebb | 2013-01-24 18:13:47 +0530 | [diff] [blame] | 469 | clock_tree = tree_load(clk_dir_path[MAX], NULL, false); |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 470 | if (!clock_tree) |
| 471 | return -1; |
| 472 | |
Daniel Lezcano | caafece | 2011-06-27 22:59:17 +0200 | [diff] [blame] | 473 | if (fill_clock_tree()) |
| 474 | return -1; |
| 475 | |
| 476 | return display_register(CLOCK, &clock_ops); |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 477 | } |