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 | 2ef06e9 | 2011-05-24 15:27:49 +0200 | [diff] [blame] | 18 | #include <math.h> |
Daniel Lezcano | cac52d9 | 2011-03-26 22:05:49 +0100 | [diff] [blame] | 19 | #include "regulator.h" |
Daniel Lezcano | 192c1d2 | 2011-03-26 22:06:14 +0100 | [diff] [blame] | 20 | #include "display.h" |
Daniel Lezcano | f0e0665 | 2011-03-26 22:06:19 +0100 | [diff] [blame] | 21 | #include "clocks.h" |
Daniel Lezcano | 597892a | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 22 | #include "sensor.h" |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 23 | #include "powerdebug.h" |
| 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, |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 157 | char *clkname_str, bool *refreshwin, bool *cont, |
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 | |
Daniel Lezcano | 2ef06e9 | 2011-05-24 15:27:49 +0200 | [diff] [blame] | 167 | if (keystroke == KEY_RIGHT || keystroke == '\t') { |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 168 | options->selectedwindow++; |
Daniel Lezcano | 2ef06e9 | 2011-05-24 15:27:49 +0200 | [diff] [blame] | 169 | options->selectedwindow %= TOTAL_FEATURE_WINS; |
| 170 | } |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 171 | |
Daniel Lezcano | 2ef06e9 | 2011-05-24 15:27:49 +0200 | [diff] [blame] | 172 | if (keystroke == KEY_LEFT || keystroke == KEY_BTAB) { |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 173 | options->selectedwindow--; |
Daniel Lezcano | 2ef06e9 | 2011-05-24 15:27:49 +0200 | [diff] [blame] | 174 | if (options->selectedwindow < 0) |
| 175 | options->selectedwindow = TOTAL_FEATURE_WINS - 1; |
| 176 | } |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 177 | |
Daniel Lezcano | 2e9df76 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 178 | if (keystroke == KEY_DOWN) { |
| 179 | display_next_line(options->selectedwindow); |
| 180 | *cont = true; |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 181 | } |
Daniel Lezcano | 2e9df76 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 182 | |
| 183 | if (keystroke == KEY_UP) { |
| 184 | display_prev_line(options->selectedwindow); |
| 185 | *cont = true; |
| 186 | } |
| 187 | |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 188 | if (options->selectedwindow == CLOCK) { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 189 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 190 | #if 0 |
| 191 | /* TODO : fix with a new panel applicable for all subsystems */ |
Daniel Lezcano | 3b42b5e | 2011-05-24 15:27:49 +0200 | [diff] [blame] | 192 | if (keystroke == '/') |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 193 | *findparent_ncurses = true; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 194 | #endif |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 195 | |
Daniel Lezcano | 3b42b5e | 2011-05-24 15:27:49 +0200 | [diff] [blame] | 196 | if ((keystroke == '\e' || oldselectedwin != |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 197 | options->selectedwindow) && *findparent_ncurses) { |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 198 | *findparent_ncurses = false; |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 199 | clkname_str[0] = '\0'; |
| 200 | } |
| 201 | |
Daniel Lezcano | 3b42b5e | 2011-05-24 15:27:49 +0200 | [diff] [blame] | 202 | if (*findparent_ncurses && keystroke != '\r') { |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 203 | int len = strlen(clkname_str); |
| 204 | char str[2]; |
| 205 | |
Daniel Lezcano | 3b42b5e | 2011-05-24 15:27:49 +0200 | [diff] [blame] | 206 | if (keystroke == KEY_BACKSPACE) { |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 207 | if (len > 0) |
| 208 | len--; |
| 209 | |
| 210 | clkname_str[len] = '\0'; |
| 211 | } else { |
| 212 | if (strlen(clkname_str) || |
| 213 | keystroke != '/') { |
| 214 | str[0] = keystroke; |
| 215 | str[1] = '\0'; |
| 216 | if (len < 63) |
| 217 | strcat(clkname_str, |
| 218 | str); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | keychar = toupper(keystroke); |
| 225 | //#define DEBUG |
| 226 | #ifdef DEBUG |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 227 | fini_curses(); |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 228 | printf("key entered %d:%c\n", keystroke, keychar); |
| 229 | exit(1); |
| 230 | #endif |
| 231 | |
Daniel Lezcano | 3b42b5e | 2011-05-24 15:27:49 +0200 | [diff] [blame] | 232 | if (keystroke == '\r') |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 233 | *enter_hit = true; |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 234 | |
| 235 | if (keychar == 'Q' && !*findparent_ncurses) |
| 236 | return 1; |
| 237 | if (keychar == 'R') { |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 238 | *refreshwin = true; |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 239 | options->ticktime = 3; |
| 240 | } else |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 241 | *refreshwin = false; |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 246 | int mainloop(struct powerdebug_options *options) |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 247 | { |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 248 | bool findparent_ncurses = false; |
| 249 | bool refreshwin = false; |
| 250 | bool enter_hit = false; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 251 | bool cont = false; |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 252 | char clkname_str[64]; |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 253 | |
Daniel Lezcano | 934fc09 | 2011-03-26 22:06:18 +0100 | [diff] [blame] | 254 | strcpy(clkname_str, ""); |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 255 | |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 256 | while (1) { |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 257 | int key = 0; |
| 258 | struct timeval tval; |
| 259 | fd_set readfds; |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 260 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 261 | if (options->selectedwindow != CLOCK || !cont) { |
| 262 | create_windows(options->selectedwindow); |
| 263 | show_header(options->selectedwindow); |
| 264 | create_selectedwindow(options->selectedwindow); |
| 265 | } |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 266 | |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 267 | if (options->selectedwindow == REGULATOR) |
| 268 | regulator_display(); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 269 | |
Daniel Lezcano | 95b0dac | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 270 | if (options->selectedwindow == CLOCK) { |
Daniel Lezcano | 934fc09 | 2011-03-26 22:06:18 +0100 | [diff] [blame] | 271 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 272 | if (!cont) { |
Amit Arora | a06a730 | 2010-12-02 15:59:37 +0530 | [diff] [blame] | 273 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 274 | if (!findparent_ncurses) { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 275 | |
Daniel Lezcano | 05916f8 | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 276 | if (enter_hit) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 277 | clock_toggle_expanded(); |
Daniel Lezcano | 05916f8 | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 278 | |
Daniel Lezcano | 597892a | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 279 | clock_display(); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 280 | enter_hit = false; |
| 281 | } else |
| 282 | find_parents_for_clock(clkname_str, |
| 283 | enter_hit); |
| 284 | } else cont = false; |
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 | 95b0dac | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 287 | if (options->selectedwindow == SENSOR) |
Daniel Lezcano | 2e9df76 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 288 | sensor_display(); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 289 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 290 | FD_ZERO(&readfds); |
| 291 | FD_SET(0, &readfds); |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 292 | tval.tv_sec = options->ticktime; |
| 293 | tval.tv_usec = (options->ticktime - tval.tv_sec) * 1000000; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 294 | |
Daniel Lezcano | e8cf9b8 | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 295 | again: |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 296 | key = select(1, &readfds, NULL, NULL, &tval); |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 297 | if (!key) |
| 298 | continue; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 299 | |
Daniel Lezcano | e8cf9b8 | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 300 | if (key < 0) { |
| 301 | if (errno == EINTR) |
| 302 | goto again; |
| 303 | break; |
| 304 | } |
| 305 | |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 306 | if (keystroke_callback(&enter_hit, &findparent_ncurses, |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 307 | clkname_str, &refreshwin, &cont, options)) |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 308 | break; |
Amit Arora | 97006e5 | 2010-10-28 11:56:08 +0530 | [diff] [blame] | 309 | |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 310 | } |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 315 | static int powerdebug_dump(struct powerdebug_options *options) |
Daniel Lezcano | 21c04d4 | 2011-03-26 22:06:04 +0100 | [diff] [blame] | 316 | { |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 317 | if (options->regulators) |
| 318 | regulator_dump(); |
Daniel Lezcano | b574671 | 2011-03-26 22:06:05 +0100 | [diff] [blame] | 319 | |
Daniel Lezcano | c789194 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 320 | if (options->clocks) |
Daniel Lezcano | 597892a | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 321 | clock_dump(options->clkname); |
Daniel Lezcano | b574671 | 2011-03-26 22:06:05 +0100 | [diff] [blame] | 322 | |
| 323 | if (options->sensors) |
Daniel Lezcano | 3d0aef4 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 324 | sensor_dump(); |
Daniel Lezcano | b574671 | 2011-03-26 22:06:05 +0100 | [diff] [blame] | 325 | |
Daniel Lezcano | 21c04d4 | 2011-03-26 22:06:04 +0100 | [diff] [blame] | 326 | return 0; |
| 327 | } |
| 328 | |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 329 | static int powerdebug_display(struct powerdebug_options *options) |
Daniel Lezcano | c08f1f2 | 2011-03-26 22:06:21 +0100 | [diff] [blame] | 330 | { |
| 331 | if (display_init()) { |
| 332 | printf("failed to initialize display\n"); |
| 333 | return -1; |
| 334 | } |
| 335 | |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 336 | if (mainloop(options)) |
Daniel Lezcano | c08f1f2 | 2011-03-26 22:06:21 +0100 | [diff] [blame] | 337 | return -1; |
| 338 | |
| 339 | return 0; |
| 340 | } |
| 341 | |
Daniel Lezcano | 6e0c9c8 | 2011-03-26 22:06:07 +0100 | [diff] [blame] | 342 | static struct powerdebug_options *powerdebug_init(void) |
| 343 | { |
| 344 | struct powerdebug_options *options; |
| 345 | |
| 346 | options = malloc(sizeof(*options)); |
| 347 | if (!options) |
| 348 | return NULL; |
| 349 | |
| 350 | memset(options, 0, sizeof(*options)); |
| 351 | |
| 352 | return options; |
| 353 | } |
| 354 | |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 355 | int main(int argc, char **argv) |
| 356 | { |
| 357 | struct powerdebug_options *options; |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 358 | int ret; |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 359 | |
Daniel Lezcano | 6e0c9c8 | 2011-03-26 22:06:07 +0100 | [diff] [blame] | 360 | options = powerdebug_init(); |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 361 | if (!options) { |
Daniel Lezcano | 6e0c9c8 | 2011-03-26 22:06:07 +0100 | [diff] [blame] | 362 | fprintf(stderr, "not enough memory to allocate options\n"); |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 363 | return 1; |
| 364 | } |
| 365 | |
Daniel Lezcano | c08f1f2 | 2011-03-26 22:06:21 +0100 | [diff] [blame] | 366 | if (getoptions(argc, argv, options)) { |
| 367 | usage(); |
| 368 | return 1; |
| 369 | } |
| 370 | |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 371 | if (regulator_init()) { |
Daniel Lezcano | 4aab2fe | 2011-03-26 22:05:53 +0100 | [diff] [blame] | 372 | printf("not enough memory to allocate regulators info\n"); |
Daniel Lezcano | 6e48fa4 | 2011-03-26 22:06:23 +0100 | [diff] [blame] | 373 | options->regulators = false; |
Daniel Lezcano | 4aab2fe | 2011-03-26 22:05:53 +0100 | [diff] [blame] | 374 | } |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 375 | |
Daniel Lezcano | f0e0665 | 2011-03-26 22:06:19 +0100 | [diff] [blame] | 376 | if (clock_init()) { |
| 377 | printf("failed to initialize clock details (check debugfs)\n"); |
| 378 | options->clocks = false; |
| 379 | } |
| 380 | |
Daniel Lezcano | 3d0aef4 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 381 | if (sensor_init()) { |
| 382 | printf("failed to initialize sensors\n"); |
| 383 | options->sensors = false; |
| 384 | } |
| 385 | |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 386 | ret = options->dump ? powerdebug_dump(options) : |
| 387 | powerdebug_display(options); |
Daniel Lezcano | 21c04d4 | 2011-03-26 22:06:04 +0100 | [diff] [blame] | 388 | |
Daniel Lezcano | c08f1f2 | 2011-03-26 22:06:21 +0100 | [diff] [blame] | 389 | return ret < 0; |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 390 | } |