Amit Arora | 39f2954 | 2010-09-14 12:03:22 +0530 | [diff] [blame] | 1 | /******************************************************************************* |
Amit Kucheria | c0e17fc | 2011-01-17 09:35:52 +0200 | [diff] [blame] | 2 | * Copyright (C) 2010, Linaro Limited. |
Amit Arora | 39f2954 | 2010-09-14 12:03:22 +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 |
| 14 | *******************************************************************************/ |
| 15 | |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 16 | #include <getopt.h> |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 17 | #include <stdbool.h> |
Daniel Lezcano | cac52d9 | 2011-03-26 22:05:49 +0100 | [diff] [blame] | 18 | #include "regulator.h" |
Daniel Lezcano | 192c1d2 | 2011-03-26 22:06:14 +0100 | [diff] [blame] | 19 | #include "display.h" |
Daniel Lezcano | f0e0665 | 2011-03-26 22:06:19 +0100 | [diff] [blame] | 20 | #include "clocks.h" |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 21 | #include "powerdebug.h" |
| 22 | |
Daniel Lezcano | 20be678 | 2011-03-26 22:06:03 +0100 | [diff] [blame] | 23 | static int highlighted_row; |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 24 | |
Amit Arora | 422c52f | 2010-12-02 16:22:29 +0530 | [diff] [blame] | 25 | void usage(void) |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 26 | { |
Amit Arora | 422c52f | 2010-12-02 16:22:29 +0530 | [diff] [blame] | 27 | printf("Usage: powerdebug [OPTIONS]\n"); |
| 28 | printf("\n"); |
| 29 | printf("powerdebug -d [ -r ] [ -s ] [ -c [ -p <clock-name> ] ] " |
| 30 | "[ -v ]\n"); |
| 31 | printf("powerdebug [ -r | -s | -c ]\n"); |
Amit Arora | 1755278 | 2010-12-02 12:23:14 +0530 | [diff] [blame] | 32 | printf(" -r, --regulator Show regulator information\n"); |
| 33 | printf(" -s, --sensor Show sensor information\n"); |
| 34 | printf(" -c, --clock Show clock information\n"); |
Amit Arora | 422c52f | 2010-12-02 16:22:29 +0530 | [diff] [blame] | 35 | printf(" -p, --findparents Show all parents for a particular" |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 36 | " clock\n"); |
Amit Arora | 1755278 | 2010-12-02 12:23:14 +0530 | [diff] [blame] | 37 | printf(" -t, --time Set ticktime in seconds (eg. 10.0)\n"); |
| 38 | printf(" -d, --dump Dump information once (no refresh)\n"); |
Amit Arora | 422c52f | 2010-12-02 16:22:29 +0530 | [diff] [blame] | 39 | printf(" -v, --verbose Verbose mode (use with -r and/or" |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 40 | " -s)\n"); |
Amit Arora | 1755278 | 2010-12-02 12:23:14 +0530 | [diff] [blame] | 41 | printf(" -V, --version Show Version\n"); |
| 42 | printf(" -h, --help Help\n"); |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 43 | } |
| 44 | |
Amit Arora | 1755278 | 2010-12-02 12:23:14 +0530 | [diff] [blame] | 45 | void version() |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 46 | { |
Amit Arora | 1755278 | 2010-12-02 12:23:14 +0530 | [diff] [blame] | 47 | printf("powerdebug version %s\n", VERSION); |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 48 | } |
| 49 | |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 50 | /* |
| 51 | * Options: |
| 52 | * -r, --regulator : regulator |
| 53 | * -s, --sensor : sensors |
| 54 | * -c, --clock : clocks |
| 55 | * -p, --findparents : clockname whose parents have to be found |
| 56 | * -t, --time : ticktime |
| 57 | * -d, --dump : dump |
| 58 | * -v, --verbose : verbose |
| 59 | * -V, --version : version |
| 60 | * -h, --help : help |
| 61 | * no option / default : show usage! |
| 62 | */ |
| 63 | |
| 64 | static struct option long_options[] = { |
| 65 | { "regulator", 0, 0, 'r' }, |
| 66 | { "sensor", 0, 0, 's' }, |
| 67 | { "clock", 0, 0, 'c' }, |
| 68 | { "findparents", 1, 0, 'p' }, |
| 69 | { "time", 1, 0, 't' }, |
| 70 | { "dump", 0, 0, 'd' }, |
| 71 | { "verbose", 0, 0, 'v' }, |
| 72 | { "version", 0, 0, 'V' }, |
| 73 | { "help", 0, 0, 'h' }, |
| 74 | { 0, 0, 0, 0 } |
| 75 | }; |
| 76 | |
| 77 | struct powerdebug_options { |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 78 | bool verbose; |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 79 | bool regulators; |
| 80 | bool sensors; |
| 81 | bool clocks; |
Daniel Lezcano | a70d949 | 2011-03-23 14:37:40 +0100 | [diff] [blame] | 82 | bool dump; |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 83 | unsigned int ticktime; |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 84 | int selectedwindow; |
Daniel Lezcano | 6e0c9c8 | 2011-03-26 22:06:07 +0100 | [diff] [blame] | 85 | char *clkname; |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | int getoptions(int argc, char *argv[], struct powerdebug_options *options) |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 89 | { |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 90 | int c; |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 91 | |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 92 | memset(options, 0, sizeof(*options)); |
| 93 | options->ticktime = 10; |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 94 | options->selectedwindow = -1; |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 95 | |
Amit Arora | fefe8bf | 2010-08-05 13:31:20 +0530 | [diff] [blame] | 96 | while (1) { |
| 97 | int optindex = 0; |
Amit Arora | fefe8bf | 2010-08-05 13:31:20 +0530 | [diff] [blame] | 98 | |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 99 | c = getopt_long(argc, argv, "rscp:t:dvVh", |
| 100 | long_options, &optindex); |
Amit Arora | fefe8bf | 2010-08-05 13:31:20 +0530 | [diff] [blame] | 101 | if (c == -1) |
| 102 | break; |
| 103 | |
| 104 | switch (c) { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 105 | case 'r': |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 106 | options->regulators = true; |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 107 | options->selectedwindow = REGULATOR; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 108 | break; |
| 109 | case 's': |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 110 | options->sensors = true; |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 111 | options->selectedwindow = SENSOR; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 112 | break; |
| 113 | case 'c': |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 114 | options->clocks = true; |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 115 | options->selectedwindow = CLOCK; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 116 | break; |
Amit Arora | f4fb810 | 2010-11-30 13:55:50 +0530 | [diff] [blame] | 117 | case 'p': |
Daniel Lezcano | 6e0c9c8 | 2011-03-26 22:06:07 +0100 | [diff] [blame] | 118 | options->clkname = strdup(optarg); |
| 119 | if (!options->clkname) { |
Daniel Lezcano | 9420fde | 2011-03-23 14:37:31 +0100 | [diff] [blame] | 120 | fprintf(stderr, "failed to allocate memory"); |
| 121 | return -1; |
| 122 | } |
Amit Kucheria | eab558a | 2011-03-25 09:51:41 +0200 | [diff] [blame] | 123 | options->dump = true; /* Assume -dc in case of -p */ |
| 124 | options->clocks = true; |
Amit Arora | f4fb810 | 2010-11-30 13:55:50 +0530 | [diff] [blame] | 125 | break; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 126 | case 't': |
Daniel Lezcano | 7f112da | 2011-03-23 14:37:32 +0100 | [diff] [blame] | 127 | options->ticktime = atoi(optarg); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 128 | break; |
| 129 | case 'd': |
Daniel Lezcano | a70d949 | 2011-03-23 14:37:40 +0100 | [diff] [blame] | 130 | options->dump = true; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 131 | break; |
| 132 | case 'v': |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 133 | options->verbose = true; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 134 | break; |
| 135 | case 'V': |
| 136 | version(); |
| 137 | break; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 138 | case '?': |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 139 | fprintf(stderr, "%s: Unknown option %c'.\n", |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 140 | argv[0], optopt); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 141 | default: |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 142 | return -1; |
Amit Arora | fefe8bf | 2010-08-05 13:31:20 +0530 | [diff] [blame] | 143 | } |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 144 | } |
Amit Arora | a06a730 | 2010-12-02 15:59:37 +0530 | [diff] [blame] | 145 | |
Daniel Lezcano | 934fc09 | 2011-03-26 22:06:18 +0100 | [diff] [blame] | 146 | /* No system specified to be dump, let's default to all */ |
| 147 | if (!options->regulators && !options->clocks && !options->sensors) |
| 148 | options->regulators = options->clocks = options->sensors = true; |
Amit Arora | fefe8bf | 2010-08-05 13:31:20 +0530 | [diff] [blame] | 149 | |
Daniel Lezcano | c9c1462 | 2011-03-26 22:06:10 +0100 | [diff] [blame] | 150 | if (options->selectedwindow == -1) |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 151 | options->selectedwindow = CLOCK; |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 152 | |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 153 | return 0; |
| 154 | } |
| 155 | |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 156 | int keystroke_callback(bool *enter_hit, bool *findparent_ncurses, |
| 157 | char *clkname_str, bool *refreshwin, |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 158 | struct powerdebug_options *options) |
| 159 | { |
| 160 | char keychar; |
| 161 | int keystroke = getch(); |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 162 | int oldselectedwin = options->selectedwindow; |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 163 | |
| 164 | if (keystroke == EOF) |
| 165 | exit(0); |
| 166 | |
| 167 | if (keystroke == KEY_RIGHT || keystroke == 9) |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 168 | options->selectedwindow++; |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 169 | |
| 170 | if (keystroke == KEY_LEFT || keystroke == 353) |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 171 | options->selectedwindow--; |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 172 | |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 173 | if (options->selectedwindow >= TOTAL_FEATURE_WINS) |
| 174 | options->selectedwindow = 0; |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 175 | |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 176 | if (options->selectedwindow < 0) |
| 177 | options->selectedwindow = TOTAL_FEATURE_WINS - 1; |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 178 | |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 179 | if (options->selectedwindow == CLOCK) { |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 180 | if (keystroke == KEY_DOWN) |
| 181 | highlighted_row++; |
| 182 | if (keystroke == KEY_UP && highlighted_row > 0) |
| 183 | highlighted_row--; |
| 184 | if (keystroke == 47) |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 185 | *findparent_ncurses = true; |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 186 | |
| 187 | if ((keystroke == 27 || oldselectedwin != |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 188 | options->selectedwindow) && *findparent_ncurses) { |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 189 | *findparent_ncurses = false; |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 190 | clkname_str[0] = '\0'; |
| 191 | } |
| 192 | |
| 193 | if (*findparent_ncurses && keystroke != 13) { |
| 194 | int len = strlen(clkname_str); |
| 195 | char str[2]; |
| 196 | |
| 197 | if (keystroke == 263) { |
| 198 | if (len > 0) |
| 199 | len--; |
| 200 | |
| 201 | clkname_str[len] = '\0'; |
| 202 | } else { |
| 203 | if (strlen(clkname_str) || |
| 204 | keystroke != '/') { |
| 205 | str[0] = keystroke; |
| 206 | str[1] = '\0'; |
| 207 | if (len < 63) |
| 208 | strcat(clkname_str, |
| 209 | str); |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | keychar = toupper(keystroke); |
| 216 | //#define DEBUG |
| 217 | #ifdef DEBUG |
| 218 | killall_windows(1); fini_curses(); |
| 219 | printf("key entered %d:%c\n", keystroke, keychar); |
| 220 | exit(1); |
| 221 | #endif |
| 222 | |
| 223 | if (keystroke == 13) |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 224 | *enter_hit = true; |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 225 | |
| 226 | if (keychar == 'Q' && !*findparent_ncurses) |
| 227 | return 1; |
| 228 | if (keychar == 'R') { |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 229 | *refreshwin = true; |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 230 | options->ticktime = 3; |
| 231 | } else |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 232 | *refreshwin = false; |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 233 | |
| 234 | return 0; |
| 235 | } |
| 236 | |
Daniel Lezcano | 0819826 | 2011-03-26 22:06:02 +0100 | [diff] [blame] | 237 | int mainloop(struct powerdebug_options *options, |
| 238 | struct regulator_info *reg_info, int nr_reg) |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 239 | { |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 240 | bool findparent_ncurses = false; |
| 241 | bool refreshwin = false; |
| 242 | bool enter_hit = false; |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 243 | char clkname_str[64]; |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 244 | |
Daniel Lezcano | 934fc09 | 2011-03-26 22:06:18 +0100 | [diff] [blame] | 245 | strcpy(clkname_str, ""); |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 246 | |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 247 | while (1) { |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 248 | int key = 0; |
| 249 | struct timeval tval; |
| 250 | fd_set readfds; |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 251 | |
Daniel Lezcano | b574671 | 2011-03-26 22:06:05 +0100 | [diff] [blame] | 252 | create_windows(options->selectedwindow); |
| 253 | show_header(options->selectedwindow); |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 254 | |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 255 | if (options->regulators || options->selectedwindow == REGULATOR) { |
Daniel Lezcano | 0819826 | 2011-03-26 22:06:02 +0100 | [diff] [blame] | 256 | regulator_read_info(reg_info, nr_reg); |
Daniel Lezcano | b574671 | 2011-03-26 22:06:05 +0100 | [diff] [blame] | 257 | create_selectedwindow(options->selectedwindow); |
| 258 | show_regulator_info(reg_info, nr_reg, |
| 259 | options->verbose); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 260 | } |
| 261 | |
Daniel Lezcano | 934fc09 | 2011-03-26 22:06:18 +0100 | [diff] [blame] | 262 | if (options->selectedwindow == CLOCK) { |
| 263 | |
| 264 | if (options->clocks) { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 265 | int hrow; |
Amit Arora | 0e51272 | 2010-10-01 12:24:16 +0530 | [diff] [blame] | 266 | |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 267 | create_selectedwindow(options->selectedwindow); |
Amit Arora | 3bd7916 | 2010-12-01 13:51:42 +0530 | [diff] [blame] | 268 | if (!findparent_ncurses) { |
Amit Arora | a06a730 | 2010-12-02 15:59:37 +0530 | [diff] [blame] | 269 | int command = 0; |
| 270 | |
| 271 | if (enter_hit) |
| 272 | command = CLOCK_SELECTED; |
| 273 | if (refreshwin) |
| 274 | command = REFRESH_WINDOW; |
Amit Arora | 3bd7916 | 2010-12-01 13:51:42 +0530 | [diff] [blame] | 275 | hrow = read_and_print_clock_info( |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 276 | options->verbose, |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 277 | highlighted_row, |
| 278 | command); |
Amit Arora | 3bd7916 | 2010-12-01 13:51:42 +0530 | [diff] [blame] | 279 | highlighted_row = hrow; |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 280 | enter_hit = false; |
Amit Arora | 3bd7916 | 2010-12-01 13:51:42 +0530 | [diff] [blame] | 281 | } else |
| 282 | find_parents_for_clock(clkname_str, |
Daniel Lezcano | 897f733 | 2011-03-26 22:06:06 +0100 | [diff] [blame] | 283 | enter_hit); |
Amit Arora | 04f9774 | 2010-11-16 11:28:57 +0530 | [diff] [blame] | 284 | } |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 285 | } |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 286 | |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 287 | if (options->sensors || options->selectedwindow == SENSOR) { |
Daniel Lezcano | b574671 | 2011-03-26 22:06:05 +0100 | [diff] [blame] | 288 | create_selectedwindow(options->selectedwindow); |
| 289 | print_sensor_header(); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 290 | } |
| 291 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 292 | FD_ZERO(&readfds); |
| 293 | FD_SET(0, &readfds); |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 294 | tval.tv_sec = options->ticktime; |
| 295 | tval.tv_usec = (options->ticktime - tval.tv_sec) * 1000000; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 296 | |
| 297 | key = select(1, &readfds, NULL, NULL, &tval); |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 298 | if (!key) |
| 299 | continue; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 300 | |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 301 | if (keystroke_callback(&enter_hit, &findparent_ncurses, |
| 302 | clkname_str, &refreshwin, options)) |
| 303 | break; |
Amit Arora | 97006e5 | 2010-10-28 11:56:08 +0530 | [diff] [blame] | 304 | |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 305 | } |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
Daniel Lezcano | 21c04d4 | 2011-03-26 22:06:04 +0100 | [diff] [blame] | 310 | static int powerdebug_dump(struct powerdebug_options *options, |
| 311 | struct regulator_info *reg_info, int nr_reg) |
| 312 | { |
Daniel Lezcano | b574671 | 2011-03-26 22:06:05 +0100 | [diff] [blame] | 313 | if (options->regulators) { |
| 314 | regulator_read_info(reg_info, nr_reg); |
| 315 | regulator_print_info(reg_info, nr_reg, options->verbose); |
| 316 | } |
| 317 | |
| 318 | if (options->clocks) { |
Daniel Lezcano | b574671 | 2011-03-26 22:06:05 +0100 | [diff] [blame] | 319 | |
Daniel Lezcano | 6e0c9c8 | 2011-03-26 22:06:07 +0100 | [diff] [blame] | 320 | if (options->clkname) |
| 321 | read_and_dump_clock_info_one(options->clkname, |
Daniel Lezcano | b574671 | 2011-03-26 22:06:05 +0100 | [diff] [blame] | 322 | options->dump); |
| 323 | else |
| 324 | read_and_dump_clock_info(options->verbose); |
| 325 | } |
| 326 | |
| 327 | if (options->sensors) |
| 328 | read_and_print_sensor_info(options->verbose); |
| 329 | |
Daniel Lezcano | 21c04d4 | 2011-03-26 22:06:04 +0100 | [diff] [blame] | 330 | return 0; |
| 331 | } |
| 332 | |
Daniel Lezcano | c08f1f2 | 2011-03-26 22:06:21 +0100 | [diff] [blame] | 333 | static int powerdebug_display(struct powerdebug_options *options, |
| 334 | struct regulator_info *reg_info, int nr_reg) |
| 335 | { |
| 336 | if (display_init()) { |
| 337 | printf("failed to initialize display\n"); |
| 338 | return -1; |
| 339 | } |
| 340 | |
| 341 | if (mainloop(options, reg_info, nr_reg)) |
| 342 | return -1; |
| 343 | |
| 344 | return 0; |
| 345 | } |
| 346 | |
Daniel Lezcano | 6e0c9c8 | 2011-03-26 22:06:07 +0100 | [diff] [blame] | 347 | static struct powerdebug_options *powerdebug_init(void) |
| 348 | { |
| 349 | struct powerdebug_options *options; |
| 350 | |
| 351 | options = malloc(sizeof(*options)); |
| 352 | if (!options) |
| 353 | return NULL; |
| 354 | |
| 355 | memset(options, 0, sizeof(*options)); |
| 356 | |
| 357 | return options; |
| 358 | } |
| 359 | |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 360 | int main(int argc, char **argv) |
| 361 | { |
| 362 | struct powerdebug_options *options; |
Daniel Lezcano | 0819826 | 2011-03-26 22:06:02 +0100 | [diff] [blame] | 363 | struct regulator_info *regulators_info; |
Daniel Lezcano | c08f1f2 | 2011-03-26 22:06:21 +0100 | [diff] [blame] | 364 | int numregulators, ret; |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 365 | |
Daniel Lezcano | 6e0c9c8 | 2011-03-26 22:06:07 +0100 | [diff] [blame] | 366 | options = powerdebug_init(); |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 367 | if (!options) { |
Daniel Lezcano | 6e0c9c8 | 2011-03-26 22:06:07 +0100 | [diff] [blame] | 368 | fprintf(stderr, "not enough memory to allocate options\n"); |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 369 | return 1; |
| 370 | } |
| 371 | |
Daniel Lezcano | c08f1f2 | 2011-03-26 22:06:21 +0100 | [diff] [blame] | 372 | if (getoptions(argc, argv, options)) { |
| 373 | usage(); |
| 374 | return 1; |
| 375 | } |
| 376 | |
Daniel Lezcano | 4aab2fe | 2011-03-26 22:05:53 +0100 | [diff] [blame] | 377 | regulators_info = regulator_init(&numregulators); |
| 378 | if (!regulators_info) { |
| 379 | printf("not enough memory to allocate regulators info\n"); |
Daniel Lezcano | 6e48fa4 | 2011-03-26 22:06:23 +0100 | [diff] [blame^] | 380 | options->regulators = false; |
Daniel Lezcano | 4aab2fe | 2011-03-26 22:05:53 +0100 | [diff] [blame] | 381 | } |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 382 | |
Daniel Lezcano | f0e0665 | 2011-03-26 22:06:19 +0100 | [diff] [blame] | 383 | if (clock_init()) { |
| 384 | printf("failed to initialize clock details (check debugfs)\n"); |
| 385 | options->clocks = false; |
| 386 | } |
| 387 | |
Daniel Lezcano | c08f1f2 | 2011-03-26 22:06:21 +0100 | [diff] [blame] | 388 | ret = options->dump ? |
| 389 | powerdebug_dump(options, regulators_info, numregulators) : |
| 390 | powerdebug_display(options, regulators_info, numregulators); |
Daniel Lezcano | 21c04d4 | 2011-03-26 22:06:04 +0100 | [diff] [blame] | 391 | |
Daniel Lezcano | c08f1f2 | 2011-03-26 22:06:21 +0100 | [diff] [blame] | 392 | return ret < 0; |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 393 | } |