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 | 1562748 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 18 | #include <string.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <stdio.h> |
| 21 | #include <errno.h> |
| 22 | #include <ncurses.h> |
Daniel Lezcano | cac52d9 | 2011-03-26 22:05:49 +0100 | [diff] [blame] | 23 | #include "regulator.h" |
Daniel Lezcano | 192c1d2 | 2011-03-26 22:06:14 +0100 | [diff] [blame] | 24 | #include "display.h" |
Daniel Lezcano | f0e0665 | 2011-03-26 22:06:19 +0100 | [diff] [blame] | 25 | #include "clocks.h" |
Daniel Lezcano | 597892a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 26 | #include "sensor.h" |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 27 | #include "powerdebug.h" |
| 28 | |
Amit Arora | 422c52f | 2010-12-02 16:22:29 +0530 | [diff] [blame] | 29 | void usage(void) |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 30 | { |
Amit Arora | 422c52f | 2010-12-02 16:22:29 +0530 | [diff] [blame] | 31 | printf("Usage: powerdebug [OPTIONS]\n"); |
| 32 | printf("\n"); |
| 33 | printf("powerdebug -d [ -r ] [ -s ] [ -c [ -p <clock-name> ] ] " |
| 34 | "[ -v ]\n"); |
| 35 | printf("powerdebug [ -r | -s | -c ]\n"); |
Amit Arora | 1755278 | 2010-12-02 12:23:14 +0530 | [diff] [blame] | 36 | printf(" -r, --regulator Show regulator information\n"); |
| 37 | printf(" -s, --sensor Show sensor information\n"); |
| 38 | printf(" -c, --clock Show clock information\n"); |
Amit Arora | 422c52f | 2010-12-02 16:22:29 +0530 | [diff] [blame] | 39 | printf(" -p, --findparents Show all parents for a particular" |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 40 | " clock\n"); |
Amit Arora | 1755278 | 2010-12-02 12:23:14 +0530 | [diff] [blame] | 41 | printf(" -t, --time Set ticktime in seconds (eg. 10.0)\n"); |
| 42 | printf(" -d, --dump Dump information once (no refresh)\n"); |
Amit Arora | 422c52f | 2010-12-02 16:22:29 +0530 | [diff] [blame] | 43 | printf(" -v, --verbose Verbose mode (use with -r and/or" |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 44 | " -s)\n"); |
Amit Arora | 1755278 | 2010-12-02 12:23:14 +0530 | [diff] [blame] | 45 | printf(" -V, --version Show Version\n"); |
| 46 | printf(" -h, --help Help\n"); |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 47 | } |
| 48 | |
Amit Arora | 1755278 | 2010-12-02 12:23:14 +0530 | [diff] [blame] | 49 | void version() |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 50 | { |
Amit Arora | 1755278 | 2010-12-02 12:23:14 +0530 | [diff] [blame] | 51 | printf("powerdebug version %s\n", VERSION); |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 52 | } |
| 53 | |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 54 | /* |
| 55 | * Options: |
| 56 | * -r, --regulator : regulator |
| 57 | * -s, --sensor : sensors |
| 58 | * -c, --clock : clocks |
| 59 | * -p, --findparents : clockname whose parents have to be found |
| 60 | * -t, --time : ticktime |
| 61 | * -d, --dump : dump |
| 62 | * -v, --verbose : verbose |
| 63 | * -V, --version : version |
| 64 | * -h, --help : help |
| 65 | * no option / default : show usage! |
| 66 | */ |
| 67 | |
| 68 | static struct option long_options[] = { |
| 69 | { "regulator", 0, 0, 'r' }, |
| 70 | { "sensor", 0, 0, 's' }, |
| 71 | { "clock", 0, 0, 'c' }, |
| 72 | { "findparents", 1, 0, 'p' }, |
| 73 | { "time", 1, 0, 't' }, |
| 74 | { "dump", 0, 0, 'd' }, |
| 75 | { "verbose", 0, 0, 'v' }, |
| 76 | { "version", 0, 0, 'V' }, |
| 77 | { "help", 0, 0, 'h' }, |
| 78 | { 0, 0, 0, 0 } |
| 79 | }; |
| 80 | |
| 81 | struct powerdebug_options { |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 82 | bool verbose; |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 83 | bool regulators; |
| 84 | bool sensors; |
| 85 | bool clocks; |
Daniel Lezcano | a70d949 | 2011-03-23 14:37:40 +0100 | [diff] [blame] | 86 | bool dump; |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 87 | unsigned int ticktime; |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 88 | int selectedwindow; |
Daniel Lezcano | 6e0c9c8 | 2011-03-26 22:06:07 +0100 | [diff] [blame] | 89 | char *clkname; |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | int getoptions(int argc, char *argv[], struct powerdebug_options *options) |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 93 | { |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 94 | int c; |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 95 | |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 96 | memset(options, 0, sizeof(*options)); |
| 97 | options->ticktime = 10; |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 98 | options->selectedwindow = -1; |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 99 | |
Amit Arora | fefe8bf | 2010-08-05 13:31:20 +0530 | [diff] [blame] | 100 | while (1) { |
| 101 | int optindex = 0; |
Amit Arora | fefe8bf | 2010-08-05 13:31:20 +0530 | [diff] [blame] | 102 | |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 103 | c = getopt_long(argc, argv, "rscp:t:dvVh", |
| 104 | long_options, &optindex); |
Amit Arora | fefe8bf | 2010-08-05 13:31:20 +0530 | [diff] [blame] | 105 | if (c == -1) |
| 106 | break; |
| 107 | |
| 108 | switch (c) { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 109 | case 'r': |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 110 | options->regulators = true; |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 111 | options->selectedwindow = REGULATOR; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 112 | break; |
| 113 | case 's': |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 114 | options->sensors = true; |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 115 | options->selectedwindow = SENSOR; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 116 | break; |
| 117 | case 'c': |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 118 | options->clocks = true; |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 119 | options->selectedwindow = CLOCK; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 120 | break; |
Amit Arora | f4fb810 | 2010-11-30 13:55:50 +0530 | [diff] [blame] | 121 | case 'p': |
Daniel Lezcano | 6e0c9c8 | 2011-03-26 22:06:07 +0100 | [diff] [blame] | 122 | options->clkname = strdup(optarg); |
| 123 | if (!options->clkname) { |
Daniel Lezcano | 9420fde | 2011-03-23 14:37:31 +0100 | [diff] [blame] | 124 | fprintf(stderr, "failed to allocate memory"); |
| 125 | return -1; |
| 126 | } |
Amit Kucheria | eab558a | 2011-03-25 09:51:41 +0200 | [diff] [blame] | 127 | options->dump = true; /* Assume -dc in case of -p */ |
| 128 | options->clocks = true; |
Amit Arora | f4fb810 | 2010-11-30 13:55:50 +0530 | [diff] [blame] | 129 | break; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 130 | case 't': |
Daniel Lezcano | 7f112da | 2011-03-23 14:37:32 +0100 | [diff] [blame] | 131 | options->ticktime = atoi(optarg); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 132 | break; |
| 133 | case 'd': |
Daniel Lezcano | a70d949 | 2011-03-23 14:37:40 +0100 | [diff] [blame] | 134 | options->dump = true; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 135 | break; |
| 136 | case 'v': |
Daniel Lezcano | c5afe83 | 2011-03-23 14:37:36 +0100 | [diff] [blame] | 137 | options->verbose = true; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 138 | break; |
| 139 | case 'V': |
| 140 | version(); |
| 141 | break; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 142 | case '?': |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 143 | fprintf(stderr, "%s: Unknown option %c'.\n", |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 144 | argv[0], optopt); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 145 | default: |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 146 | return -1; |
Amit Arora | fefe8bf | 2010-08-05 13:31:20 +0530 | [diff] [blame] | 147 | } |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 148 | } |
Amit Arora | a06a730 | 2010-12-02 15:59:37 +0530 | [diff] [blame] | 149 | |
Daniel Lezcano | 934fc09 | 2011-03-26 22:06:18 +0100 | [diff] [blame] | 150 | /* No system specified to be dump, let's default to all */ |
| 151 | if (!options->regulators && !options->clocks && !options->sensors) |
| 152 | options->regulators = options->clocks = options->sensors = true; |
Amit Arora | fefe8bf | 2010-08-05 13:31:20 +0530 | [diff] [blame] | 153 | |
Daniel Lezcano | c9c1462 | 2011-03-26 22:06:10 +0100 | [diff] [blame] | 154 | if (options->selectedwindow == -1) |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 155 | options->selectedwindow = CLOCK; |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 156 | |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 157 | return 0; |
| 158 | } |
| 159 | |
Daniel Lezcano | 271fd90 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 160 | int keystroke_callback(struct powerdebug_options *options) |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 161 | { |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 162 | int keystroke = getch(); |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 163 | |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 164 | switch (keystroke) { |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 165 | |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 166 | case KEY_RIGHT: |
| 167 | case '\t': |
Daniel Lezcano | 271fd90 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 168 | display_next_panel(); |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 169 | break; |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 170 | |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 171 | case KEY_LEFT: |
| 172 | case KEY_BTAB: |
Daniel Lezcano | 271fd90 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 173 | display_prev_panel(); |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 174 | break; |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 175 | |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 176 | case KEY_DOWN: |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 177 | display_next_line(); |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 178 | break; |
Daniel Lezcano | 2e9df76 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 179 | |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 180 | case KEY_UP: |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 181 | display_prev_line(); |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 182 | break; |
Daniel Lezcano | 2e9df76 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 183 | |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 184 | case '\r': |
Daniel Lezcano | 271fd90 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 185 | display_select(); |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 186 | break; |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 187 | |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 188 | case EOF: |
| 189 | case 'q': |
| 190 | case 'Q': |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 191 | return 1; |
Daniel Lezcano | 2c3a9df | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 192 | |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 193 | case 'r': |
| 194 | case 'R': |
Daniel Lezcano | 271fd90 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 195 | display_refresh(); |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 196 | options->ticktime = 3; |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 197 | break; |
Daniel Lezcano | 2c3a9df | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 198 | } |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 203 | int mainloop(struct powerdebug_options *options) |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 204 | { |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 205 | while (1) { |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 206 | int ret; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 207 | struct timeval tval; |
| 208 | fd_set readfds; |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 209 | |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 210 | display_refresh(); |
| 211 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 212 | FD_ZERO(&readfds); |
| 213 | FD_SET(0, &readfds); |
Daniel Lezcano | 316bcae | 2011-03-23 14:37:30 +0100 | [diff] [blame] | 214 | tval.tv_sec = options->ticktime; |
| 215 | tval.tv_usec = (options->ticktime - tval.tv_sec) * 1000000; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 216 | |
Daniel Lezcano | e8cf9b8 | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 217 | again: |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 218 | ret = select(1, &readfds, NULL, NULL, &tval); |
| 219 | if (!ret) |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 220 | continue; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 221 | |
Daniel Lezcano | c44764a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 222 | if (ret < 0) { |
Daniel Lezcano | e8cf9b8 | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 223 | if (errno == EINTR) |
| 224 | goto again; |
| 225 | break; |
| 226 | } |
| 227 | |
Daniel Lezcano | 271fd90 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 228 | if (keystroke_callback(options)) |
Daniel Lezcano | 60a4102 | 2011-03-23 14:37:35 +0100 | [diff] [blame] | 229 | break; |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 230 | } |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 235 | static int powerdebug_dump(struct powerdebug_options *options) |
Daniel Lezcano | 21c04d4 | 2011-03-26 22:06:04 +0100 | [diff] [blame] | 236 | { |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 237 | if (options->regulators) |
| 238 | regulator_dump(); |
Daniel Lezcano | b574671 | 2011-03-26 22:06:05 +0100 | [diff] [blame] | 239 | |
Daniel Lezcano | c789194 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 240 | if (options->clocks) |
Daniel Lezcano | 597892a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 241 | clock_dump(options->clkname); |
Daniel Lezcano | b574671 | 2011-03-26 22:06:05 +0100 | [diff] [blame] | 242 | |
| 243 | if (options->sensors) |
Daniel Lezcano | 3d0aef4 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 244 | sensor_dump(); |
Daniel Lezcano | b574671 | 2011-03-26 22:06:05 +0100 | [diff] [blame] | 245 | |
Daniel Lezcano | 21c04d4 | 2011-03-26 22:06:04 +0100 | [diff] [blame] | 246 | return 0; |
| 247 | } |
| 248 | |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 249 | static int powerdebug_display(struct powerdebug_options *options) |
Daniel Lezcano | c08f1f2 | 2011-03-26 22:06:21 +0100 | [diff] [blame] | 250 | { |
Daniel Lezcano | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 251 | if (display_init(options->selectedwindow)) { |
Daniel Lezcano | c08f1f2 | 2011-03-26 22:06:21 +0100 | [diff] [blame] | 252 | printf("failed to initialize display\n"); |
| 253 | return -1; |
| 254 | } |
| 255 | |
Daniel Lezcano | 271fd90 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 256 | if (display_refresh()) |
| 257 | return -1; |
| 258 | |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 259 | if (mainloop(options)) |
Daniel Lezcano | c08f1f2 | 2011-03-26 22:06:21 +0100 | [diff] [blame] | 260 | return -1; |
| 261 | |
| 262 | return 0; |
| 263 | } |
| 264 | |
Daniel Lezcano | 6e0c9c8 | 2011-03-26 22:06:07 +0100 | [diff] [blame] | 265 | static struct powerdebug_options *powerdebug_init(void) |
| 266 | { |
| 267 | struct powerdebug_options *options; |
| 268 | |
| 269 | options = malloc(sizeof(*options)); |
| 270 | if (!options) |
| 271 | return NULL; |
| 272 | |
| 273 | memset(options, 0, sizeof(*options)); |
| 274 | |
| 275 | return options; |
| 276 | } |
| 277 | |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 278 | int main(int argc, char **argv) |
| 279 | { |
| 280 | struct powerdebug_options *options; |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 281 | int ret; |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 282 | |
Daniel Lezcano | 6e0c9c8 | 2011-03-26 22:06:07 +0100 | [diff] [blame] | 283 | options = powerdebug_init(); |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 284 | if (!options) { |
Daniel Lezcano | 6e0c9c8 | 2011-03-26 22:06:07 +0100 | [diff] [blame] | 285 | fprintf(stderr, "not enough memory to allocate options\n"); |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 286 | return 1; |
| 287 | } |
| 288 | |
Daniel Lezcano | c08f1f2 | 2011-03-26 22:06:21 +0100 | [diff] [blame] | 289 | if (getoptions(argc, argv, options)) { |
| 290 | usage(); |
| 291 | return 1; |
| 292 | } |
| 293 | |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 294 | if (regulator_init()) { |
Daniel Lezcano | 4aab2fe | 2011-03-26 22:05:53 +0100 | [diff] [blame] | 295 | printf("not enough memory to allocate regulators info\n"); |
Daniel Lezcano | 6e48fa4 | 2011-03-26 22:06:23 +0100 | [diff] [blame] | 296 | options->regulators = false; |
Daniel Lezcano | 4aab2fe | 2011-03-26 22:05:53 +0100 | [diff] [blame] | 297 | } |
Daniel Lezcano | 0051f4f | 2011-03-23 14:37:34 +0100 | [diff] [blame] | 298 | |
Daniel Lezcano | f0e0665 | 2011-03-26 22:06:19 +0100 | [diff] [blame] | 299 | if (clock_init()) { |
| 300 | printf("failed to initialize clock details (check debugfs)\n"); |
| 301 | options->clocks = false; |
| 302 | } |
| 303 | |
Daniel Lezcano | 3d0aef4 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 304 | if (sensor_init()) { |
| 305 | printf("failed to initialize sensors\n"); |
| 306 | options->sensors = false; |
| 307 | } |
| 308 | |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 309 | ret = options->dump ? powerdebug_dump(options) : |
| 310 | powerdebug_display(options); |
Daniel Lezcano | 21c04d4 | 2011-03-26 22:06:04 +0100 | [diff] [blame] | 311 | |
Daniel Lezcano | c08f1f2 | 2011-03-26 22:06:21 +0100 | [diff] [blame] | 312 | return ret < 0; |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 313 | } |