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