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