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