blob: 2d63908a2371aa2d61084463dee4be8a1590d9c4 [file] [log] [blame]
Amit Arora39f29542010-09-14 12:03:22 +05301/*******************************************************************************
Amit Kucheriac0e17fc2011-01-17 09:35:52 +02002 * Copyright (C) 2010, Linaro Limited.
Amit Arora39f29542010-09-14 12:03:22 +05303 *
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 Arora47fd9182010-08-24 13:26:06 +053016#include "powerdebug.h"
Amit Arora17552782010-12-02 12:23:14 +053017#include "regulator.h"
Amit Aroraed3e5652010-10-27 12:02:53 +053018#include "display.h"
Amit Arora47fd9182010-08-24 13:26:06 +053019
20#define print(w, x, y, fmt, args...) do { mvwprintw(w, y, x, fmt, ##args); } while (0)
21#define NUM_FOOTER_ITEMS 5
22
Daniel Lezcanoeeb13762011-03-26 22:06:17 +010023enum { PT_COLOR_DEFAULT = 1,
24 PT_COLOR_HEADER_BAR,
25 PT_COLOR_ERROR,
26 PT_COLOR_RED,
27 PT_COLOR_YELLOW,
28 PT_COLOR_GREEN,
29 PT_COLOR_BRIGHT,
30 PT_COLOR_BLUE,
31};
32
Amit Arora47fd9182010-08-24 13:26:06 +053033static WINDOW *header_win;
34static WINDOW *regulator_win;
Amit Arora728e0c92010-09-14 12:06:09 +053035static WINDOW *clock_win;
36static WINDOW *sensor_win;
Amit Arorac93e0712010-10-07 13:51:53 +053037static WINDOW *selected_win;
Amit Arora47fd9182010-08-24 13:26:06 +053038static WINDOW *footer_win;
39
40int maxx, maxy;
41char footer_items[NUM_FOOTER_ITEMS][64];
42
Daniel Lezcanod5a2c6d2011-03-23 14:37:38 +010043static char *win_names[TOTAL_FEATURE_WINS] = {
44 "Clocks",
45 "Regulators",
46 "Sensors"
47};
Amit Arora47fd9182010-08-24 13:26:06 +053048
Amit Arorac93e0712010-10-07 13:51:53 +053049/* "all" : Kill header and footer windows too ? */
50void killall_windows(int all)
Amit Arora47fd9182010-08-24 13:26:06 +053051{
Amit Arorac93e0712010-10-07 13:51:53 +053052 if (all && header_win) {
Amit Arora47fd9182010-08-24 13:26:06 +053053 delwin(header_win);
54 header_win = NULL;
55 }
56 if (regulator_win) {
57 delwin(regulator_win);
58 regulator_win = NULL;
59 }
Amit Arora728e0c92010-09-14 12:06:09 +053060 if (clock_win) {
61 delwin(clock_win);
62 clock_win = NULL;
63 }
64 if (sensor_win) {
65 delwin(sensor_win);
66 sensor_win = NULL;
67 }
Amit Arorac93e0712010-10-07 13:51:53 +053068 if (all && footer_win) {
Amit Arora47fd9182010-08-24 13:26:06 +053069 delwin(footer_win);
70 footer_win = NULL;
71 }
72}
73
Daniel Lezcano3abd8b12011-03-26 22:06:15 +010074static void display_fini(void)
75{
76 endwin();
77}
78
Daniel Lezcanoca17a722011-03-26 22:06:16 +010079int display_init(void)
Amit Arora47fd9182010-08-24 13:26:06 +053080{
Daniel Lezcanoca17a722011-03-26 22:06:16 +010081 if (!initscr())
82 return -1;
83
Amit Arora6e774cd2010-10-28 11:31:24 +053084 start_color();
Daniel Lezcanoca17a722011-03-26 22:06:16 +010085 use_default_colors();
86
Amit Arora6e774cd2010-10-28 11:31:24 +053087 keypad(stdscr, TRUE);
88 noecho();
89 cbreak();
90 curs_set(0);
91 nonl();
Amit Arora47fd9182010-08-24 13:26:06 +053092
Daniel Lezcanoca17a722011-03-26 22:06:16 +010093 if (init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK) ||
94 init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED) ||
95 init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK) ||
96 init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW) ||
97 init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN) ||
98 init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK) ||
99 init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE) ||
100 init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED))
101 return -1;
Amit Arora47fd9182010-08-24 13:26:06 +0530102
Daniel Lezcanoca17a722011-03-26 22:06:16 +0100103 return atexit(display_fini);
Amit Arora47fd9182010-08-24 13:26:06 +0530104}
105
Daniel Lezcano558a6d52011-03-23 14:37:41 +0100106void create_windows(int selectedwindow)
Amit Arora47fd9182010-08-24 13:26:06 +0530107{
108
109 getmaxyx(stdscr, maxy, maxx);
Amit Arorac93e0712010-10-07 13:51:53 +0530110 killall_windows(1);
Amit Arora47fd9182010-08-24 13:26:06 +0530111
112 header_win = subwin(stdscr, 1, maxx, 0, 0);
Amit Arora47fd9182010-08-24 13:26:06 +0530113 footer_win = subwin(stdscr, 1, maxx, maxy-1, 0);
114
115 strcpy(footer_items[0], " Q (Quit) ");
116 strcpy(footer_items[1], " R (Refresh) ");
117
Amit Arora83ae6cb2010-12-02 12:22:19 +0530118 if (selectedwindow == CLOCK)
119 strcpy(footer_items[2], " Other Keys: 'Left', 'Right', 'Up', 'Down', 'enter', "
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600120 " '/', 'Esc' ");
Amit Arora83ae6cb2010-12-02 12:22:19 +0530121 else
122 strcpy(footer_items[2], " Other Keys: 'Left', 'Right' ");
123
124 strcpy(footer_items[3], "");
125
Amit Arora47fd9182010-08-24 13:26:06 +0530126 werase(stdscr);
127 refresh();
128
129}
130
Daniel Lezcano558a6d52011-03-23 14:37:41 +0100131void create_selectedwindow(int selectedwindow)
Amit Arora728e0c92010-09-14 12:06:09 +0530132{
Amit Arora6e774cd2010-10-28 11:31:24 +0530133 WINDOW *win;
Amit Arora728e0c92010-09-14 12:06:09 +0530134
Amit Arora6e774cd2010-10-28 11:31:24 +0530135 killall_windows(0);
Amit Arora728e0c92010-09-14 12:06:09 +0530136
Amit Arora6e774cd2010-10-28 11:31:24 +0530137 getmaxyx(stdscr, maxy, maxx);
Amit Arora24ed7d12010-09-14 12:12:58 +0530138
Amit Arora6e774cd2010-10-28 11:31:24 +0530139 win = subwin(stdscr, maxy - 2, maxx, 1, 0);
Amit Arora728e0c92010-09-14 12:06:09 +0530140
Amit Arora6e774cd2010-10-28 11:31:24 +0530141 switch (selectedwindow) {
142 case REGULATOR: regulator_win = win;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600143 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530144
Amit Arora6e774cd2010-10-28 11:31:24 +0530145 case CLOCK: clock_win = win;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600146 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530147
Amit Arora6e774cd2010-10-28 11:31:24 +0530148 case SENSOR: sensor_win = win;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600149 break;
Amit Arora6e774cd2010-10-28 11:31:24 +0530150 }
Amit Arora728e0c92010-09-14 12:06:09 +0530151
Amit Arora6e774cd2010-10-28 11:31:24 +0530152 selected_win = win;
153
154 refresh();
Amit Arora728e0c92010-09-14 12:06:09 +0530155}
Amit Arora47fd9182010-08-24 13:26:06 +0530156
Daniel Lezcano558a6d52011-03-23 14:37:41 +0100157void show_header(int selectedwindow)
Amit Arora47fd9182010-08-24 13:26:06 +0530158{
159 int i, j = 0;
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530160 int curr_pointer = 0;
Amit Arora47fd9182010-08-24 13:26:06 +0530161
162 wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
163 wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
164 werase(header_win);
165
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530166 print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION);
167 curr_pointer += 20;
Amit Arora47fd9182010-08-24 13:26:06 +0530168
Amit Arora6e774cd2010-10-28 11:31:24 +0530169 for (i = 0; i < TOTAL_FEATURE_WINS; i++) {
170 if (selectedwindow == i)
171 wattron(header_win, A_REVERSE);
172 else
173 wattroff(header_win, A_REVERSE);
Amit Arorac93e0712010-10-07 13:51:53 +0530174
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530175 print(header_win, curr_pointer, 0, " %s ", win_names[i]);
176 curr_pointer += strlen(win_names[i]) + 2;
Amit Arora6e774cd2010-10-28 11:31:24 +0530177 }
178 wrefresh(header_win);
Amit Arora47fd9182010-08-24 13:26:06 +0530179 werase(footer_win);
180
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600181 for (i = 0; i < NUM_FOOTER_ITEMS; i++) {
182 if (strlen(footer_items[i]) == 0)
Amit Arora47fd9182010-08-24 13:26:06 +0530183 continue;
184 wattron(footer_win, A_REVERSE);
185 print(footer_win, j, 0, "%s", footer_items[i]);
186 wattroff(footer_win, A_REVERSE);
187 j+= strlen(footer_items[i])+1;
188 }
189 wrefresh(footer_win);
190}
191
192
Daniel Lezcano833b63a2011-03-26 22:06:00 +0100193void show_regulator_info(struct regulator_info *reg_info, int nr_reg, int verbose)
Amit Arora47fd9182010-08-24 13:26:06 +0530194{
Amit Arorac93e0712010-10-07 13:51:53 +0530195 int i, count = 1;
Amit Arora47fd9182010-08-24 13:26:06 +0530196
Amit Arora6e774cd2010-10-28 11:31:24 +0530197 (void)verbose;
Amit Arorabf50db92010-10-07 14:09:05 +0530198
Amit Arora47fd9182010-08-24 13:26:06 +0530199 werase(regulator_win);
200 wattron(regulator_win, A_BOLD);
Amit Arorac93e0712010-10-07 13:51:53 +0530201 print(regulator_win, 0, 0, "Name");
202 print(regulator_win, 12, 0, "Status");
203 print(regulator_win, 24, 0, "State");
204 print(regulator_win, 36, 0, "Type");
205 print(regulator_win, 48, 0, "Users");
206 print(regulator_win, 60, 0, "Microvolts");
207 print(regulator_win, 72, 0, "Min u-volts");
208 print(regulator_win, 84, 0, "Max u-volts");
Amit Arora47fd9182010-08-24 13:26:06 +0530209 wattroff(regulator_win, A_BOLD);
210
Daniel Lezcano833b63a2011-03-26 22:06:00 +0100211 for (i = 0; i < nr_reg; i++) {
Amit Arora47fd9182010-08-24 13:26:06 +0530212 int col = 0;
213
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600214 if ((i + 2) > (maxy-2))
Amit Arora47fd9182010-08-24 13:26:06 +0530215 break;
216
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100217 if (reg_info[i].num_users > 0)
Amit Arora6e774cd2010-10-28 11:31:24 +0530218 wattron(regulator_win, WA_BOLD);
219 else
220 wattroff(regulator_win, WA_BOLD);
221
Amit Arora47fd9182010-08-24 13:26:06 +0530222 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100223 reg_info[i].name);
Amit Arora47fd9182010-08-24 13:26:06 +0530224 col += 12;
225 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100226 reg_info[i].status);
Amit Arora47fd9182010-08-24 13:26:06 +0530227 col += 12;
228 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100229 reg_info[i].state);
Amit Arora47fd9182010-08-24 13:26:06 +0530230 col += 12;
231 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100232 reg_info[i].type);
Amit Arora47fd9182010-08-24 13:26:06 +0530233 col += 12;
234 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100235 reg_info[i].num_users);
Amit Arora6a943ec2010-10-07 11:49:25 +0530236 col += 12;
237 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100238 reg_info[i].microvolts);
Amit Arora47fd9182010-08-24 13:26:06 +0530239 col += 12;
240 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100241 reg_info[i].min_microvolts);
Amit Arora47fd9182010-08-24 13:26:06 +0530242 col += 12;
243 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100244 reg_info[i].max_microvolts);
Amit Arora47fd9182010-08-24 13:26:06 +0530245
246 count++;
247 }
248 wrefresh(regulator_win);
249}
250
Amit Arora728e0c92010-09-14 12:06:09 +0530251
Amit Aroraac4e8652010-11-09 11:16:53 +0530252void print_clock_header(void)
Amit Arora728e0c92010-09-14 12:06:09 +0530253{
Amit Arora6e774cd2010-10-28 11:31:24 +0530254 werase(clock_win);
255 wattron(clock_win, A_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530256 print(clock_win, 0, 0, "Name");
Amit Arora031263a2010-11-09 11:12:41 +0530257 print(clock_win, 54, 0, "Flags");
258 print(clock_win, 64, 0, "Rate");
Amit Arora6e774cd2010-10-28 11:31:24 +0530259 print(clock_win, 72, 0, "Usecount");
Amit Arora04f97742010-11-16 11:28:57 +0530260 print(clock_win, 84, 0, "Children");
Amit Arora6e774cd2010-10-28 11:31:24 +0530261 wattroff(clock_win, A_BOLD);
Amit Arora728e0c92010-09-14 12:06:09 +0530262 wrefresh(clock_win);
263}
264
265void print_sensor_header(void)
266{
Amit Arora6e774cd2010-10-28 11:31:24 +0530267 werase(sensor_win);
268 wattron(sensor_win, A_BOLD);
269 print(sensor_win, 0, 0, "Name");
270 print(sensor_win, 36, 0, "Temperature");
271 wattroff(sensor_win, A_BOLD);
272 wattron(sensor_win, A_BLINK);
273 print(sensor_win, 0, 1, "Currently Sensor information available"
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600274 " only in Dump mode!");
Amit Arora6e774cd2010-10-28 11:31:24 +0530275 wattroff(sensor_win, A_BLINK);
Amit Arora728e0c92010-09-14 12:06:09 +0530276 wrefresh(sensor_win);
277}
278
Amit Aroraac4e8652010-11-09 11:16:53 +0530279void print_one_clock(int line, char *str, int bold, int highlight)
Amit Arora728e0c92010-09-14 12:06:09 +0530280{
Amit Arora031263a2010-11-09 11:12:41 +0530281 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530282 wattron(clock_win, WA_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530283 if (highlight)
284 wattron(clock_win, WA_STANDOUT);
285
Amit Arora031263a2010-11-09 11:12:41 +0530286 print(clock_win, 0, line + 1, "%s", str);
287 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530288 wattroff(clock_win, WA_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530289 if (highlight)
290 wattroff(clock_win, WA_STANDOUT);
Amit Arora6e774cd2010-10-28 11:31:24 +0530291 wrefresh(clock_win);
Amit Arora728e0c92010-09-14 12:06:09 +0530292}