blob: aee5503ee9770f0d29b42f79e5b66bf7caf4cabc [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
23static WINDOW *header_win;
24static WINDOW *regulator_win;
Amit Arora728e0c92010-09-14 12:06:09 +053025static WINDOW *clock_win;
26static WINDOW *sensor_win;
Amit Arorac93e0712010-10-07 13:51:53 +053027static WINDOW *selected_win;
Amit Arora47fd9182010-08-24 13:26:06 +053028static WINDOW *footer_win;
29
30int maxx, maxy;
31char footer_items[NUM_FOOTER_ITEMS][64];
32
Daniel Lezcanod5a2c6d2011-03-23 14:37:38 +010033static char *win_names[TOTAL_FEATURE_WINS] = {
34 "Clocks",
35 "Regulators",
36 "Sensors"
37};
Amit Arora47fd9182010-08-24 13:26:06 +053038
Amit Arorac93e0712010-10-07 13:51:53 +053039/* "all" : Kill header and footer windows too ? */
40void killall_windows(int all)
Amit Arora47fd9182010-08-24 13:26:06 +053041{
Amit Arorac93e0712010-10-07 13:51:53 +053042 if (all && header_win) {
Amit Arora47fd9182010-08-24 13:26:06 +053043 delwin(header_win);
44 header_win = NULL;
45 }
46 if (regulator_win) {
47 delwin(regulator_win);
48 regulator_win = NULL;
49 }
Amit Arora728e0c92010-09-14 12:06:09 +053050 if (clock_win) {
51 delwin(clock_win);
52 clock_win = NULL;
53 }
54 if (sensor_win) {
55 delwin(sensor_win);
56 sensor_win = NULL;
57 }
Amit Arorac93e0712010-10-07 13:51:53 +053058 if (all && footer_win) {
Amit Arora47fd9182010-08-24 13:26:06 +053059 delwin(footer_win);
60 footer_win = NULL;
61 }
62}
63
Daniel Lezcano3abd8b12011-03-26 22:06:15 +010064static void display_fini(void)
65{
66 endwin();
67}
68
Daniel Lezcanoca17a722011-03-26 22:06:16 +010069int display_init(void)
Amit Arora47fd9182010-08-24 13:26:06 +053070{
Daniel Lezcanoca17a722011-03-26 22:06:16 +010071 if (!initscr())
72 return -1;
73
Amit Arora6e774cd2010-10-28 11:31:24 +053074 start_color();
Daniel Lezcanoca17a722011-03-26 22:06:16 +010075 use_default_colors();
76
Amit Arora6e774cd2010-10-28 11:31:24 +053077 keypad(stdscr, TRUE);
78 noecho();
79 cbreak();
80 curs_set(0);
81 nonl();
Amit Arora47fd9182010-08-24 13:26:06 +053082
Daniel Lezcanoca17a722011-03-26 22:06:16 +010083 if (init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK) ||
84 init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED) ||
85 init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK) ||
86 init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW) ||
87 init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN) ||
88 init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK) ||
89 init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE) ||
90 init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED))
91 return -1;
Amit Arora47fd9182010-08-24 13:26:06 +053092
Daniel Lezcanoca17a722011-03-26 22:06:16 +010093 return atexit(display_fini);
Amit Arora47fd9182010-08-24 13:26:06 +053094}
95
Daniel Lezcano558a6d52011-03-23 14:37:41 +010096void create_windows(int selectedwindow)
Amit Arora47fd9182010-08-24 13:26:06 +053097{
98
99 getmaxyx(stdscr, maxy, maxx);
Amit Arorac93e0712010-10-07 13:51:53 +0530100 killall_windows(1);
Amit Arora47fd9182010-08-24 13:26:06 +0530101
102 header_win = subwin(stdscr, 1, maxx, 0, 0);
Amit Arora47fd9182010-08-24 13:26:06 +0530103 footer_win = subwin(stdscr, 1, maxx, maxy-1, 0);
104
105 strcpy(footer_items[0], " Q (Quit) ");
106 strcpy(footer_items[1], " R (Refresh) ");
107
Amit Arora83ae6cb2010-12-02 12:22:19 +0530108 if (selectedwindow == CLOCK)
109 strcpy(footer_items[2], " Other Keys: 'Left', 'Right', 'Up', 'Down', 'enter', "
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600110 " '/', 'Esc' ");
Amit Arora83ae6cb2010-12-02 12:22:19 +0530111 else
112 strcpy(footer_items[2], " Other Keys: 'Left', 'Right' ");
113
114 strcpy(footer_items[3], "");
115
Amit Arora47fd9182010-08-24 13:26:06 +0530116 werase(stdscr);
117 refresh();
118
119}
120
Daniel Lezcano558a6d52011-03-23 14:37:41 +0100121void create_selectedwindow(int selectedwindow)
Amit Arora728e0c92010-09-14 12:06:09 +0530122{
Amit Arora6e774cd2010-10-28 11:31:24 +0530123 WINDOW *win;
Amit Arora728e0c92010-09-14 12:06:09 +0530124
Amit Arora6e774cd2010-10-28 11:31:24 +0530125 killall_windows(0);
Amit Arora728e0c92010-09-14 12:06:09 +0530126
Amit Arora6e774cd2010-10-28 11:31:24 +0530127 getmaxyx(stdscr, maxy, maxx);
Amit Arora24ed7d12010-09-14 12:12:58 +0530128
Amit Arora6e774cd2010-10-28 11:31:24 +0530129 win = subwin(stdscr, maxy - 2, maxx, 1, 0);
Amit Arora728e0c92010-09-14 12:06:09 +0530130
Amit Arora6e774cd2010-10-28 11:31:24 +0530131 switch (selectedwindow) {
132 case REGULATOR: regulator_win = win;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600133 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530134
Amit Arora6e774cd2010-10-28 11:31:24 +0530135 case CLOCK: clock_win = win;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600136 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530137
Amit Arora6e774cd2010-10-28 11:31:24 +0530138 case SENSOR: sensor_win = win;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600139 break;
Amit Arora6e774cd2010-10-28 11:31:24 +0530140 }
Amit Arora728e0c92010-09-14 12:06:09 +0530141
Amit Arora6e774cd2010-10-28 11:31:24 +0530142 selected_win = win;
143
144 refresh();
Amit Arora728e0c92010-09-14 12:06:09 +0530145}
Amit Arora47fd9182010-08-24 13:26:06 +0530146
Daniel Lezcano558a6d52011-03-23 14:37:41 +0100147void show_header(int selectedwindow)
Amit Arora47fd9182010-08-24 13:26:06 +0530148{
149 int i, j = 0;
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530150 int curr_pointer = 0;
Amit Arora47fd9182010-08-24 13:26:06 +0530151
152 wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
153 wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
154 werase(header_win);
155
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530156 print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION);
157 curr_pointer += 20;
Amit Arora47fd9182010-08-24 13:26:06 +0530158
Amit Arora6e774cd2010-10-28 11:31:24 +0530159 for (i = 0; i < TOTAL_FEATURE_WINS; i++) {
160 if (selectedwindow == i)
161 wattron(header_win, A_REVERSE);
162 else
163 wattroff(header_win, A_REVERSE);
Amit Arorac93e0712010-10-07 13:51:53 +0530164
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530165 print(header_win, curr_pointer, 0, " %s ", win_names[i]);
166 curr_pointer += strlen(win_names[i]) + 2;
Amit Arora6e774cd2010-10-28 11:31:24 +0530167 }
168 wrefresh(header_win);
Amit Arora47fd9182010-08-24 13:26:06 +0530169 werase(footer_win);
170
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600171 for (i = 0; i < NUM_FOOTER_ITEMS; i++) {
172 if (strlen(footer_items[i]) == 0)
Amit Arora47fd9182010-08-24 13:26:06 +0530173 continue;
174 wattron(footer_win, A_REVERSE);
175 print(footer_win, j, 0, "%s", footer_items[i]);
176 wattroff(footer_win, A_REVERSE);
177 j+= strlen(footer_items[i])+1;
178 }
179 wrefresh(footer_win);
180}
181
182
Daniel Lezcano833b63a2011-03-26 22:06:00 +0100183void show_regulator_info(struct regulator_info *reg_info, int nr_reg, int verbose)
Amit Arora47fd9182010-08-24 13:26:06 +0530184{
Amit Arorac93e0712010-10-07 13:51:53 +0530185 int i, count = 1;
Amit Arora47fd9182010-08-24 13:26:06 +0530186
Amit Arora6e774cd2010-10-28 11:31:24 +0530187 (void)verbose;
Amit Arorabf50db92010-10-07 14:09:05 +0530188
Amit Arora47fd9182010-08-24 13:26:06 +0530189 werase(regulator_win);
190 wattron(regulator_win, A_BOLD);
Amit Arorac93e0712010-10-07 13:51:53 +0530191 print(regulator_win, 0, 0, "Name");
192 print(regulator_win, 12, 0, "Status");
193 print(regulator_win, 24, 0, "State");
194 print(regulator_win, 36, 0, "Type");
195 print(regulator_win, 48, 0, "Users");
196 print(regulator_win, 60, 0, "Microvolts");
197 print(regulator_win, 72, 0, "Min u-volts");
198 print(regulator_win, 84, 0, "Max u-volts");
Amit Arora47fd9182010-08-24 13:26:06 +0530199 wattroff(regulator_win, A_BOLD);
200
Daniel Lezcano833b63a2011-03-26 22:06:00 +0100201 for (i = 0; i < nr_reg; i++) {
Amit Arora47fd9182010-08-24 13:26:06 +0530202 int col = 0;
203
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600204 if ((i + 2) > (maxy-2))
Amit Arora47fd9182010-08-24 13:26:06 +0530205 break;
206
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100207 if (reg_info[i].num_users > 0)
Amit Arora6e774cd2010-10-28 11:31:24 +0530208 wattron(regulator_win, WA_BOLD);
209 else
210 wattroff(regulator_win, WA_BOLD);
211
Amit Arora47fd9182010-08-24 13:26:06 +0530212 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100213 reg_info[i].name);
Amit Arora47fd9182010-08-24 13:26:06 +0530214 col += 12;
215 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100216 reg_info[i].status);
Amit Arora47fd9182010-08-24 13:26:06 +0530217 col += 12;
218 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100219 reg_info[i].state);
Amit Arora47fd9182010-08-24 13:26:06 +0530220 col += 12;
221 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100222 reg_info[i].type);
Amit Arora47fd9182010-08-24 13:26:06 +0530223 col += 12;
224 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100225 reg_info[i].num_users);
Amit Arora6a943ec2010-10-07 11:49:25 +0530226 col += 12;
227 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100228 reg_info[i].microvolts);
Amit Arora47fd9182010-08-24 13:26:06 +0530229 col += 12;
230 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100231 reg_info[i].min_microvolts);
Amit Arora47fd9182010-08-24 13:26:06 +0530232 col += 12;
233 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100234 reg_info[i].max_microvolts);
Amit Arora47fd9182010-08-24 13:26:06 +0530235
236 count++;
237 }
238 wrefresh(regulator_win);
239}
240
Amit Arora728e0c92010-09-14 12:06:09 +0530241
Amit Aroraac4e8652010-11-09 11:16:53 +0530242void print_clock_header(void)
Amit Arora728e0c92010-09-14 12:06:09 +0530243{
Amit Arora6e774cd2010-10-28 11:31:24 +0530244 werase(clock_win);
245 wattron(clock_win, A_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530246 print(clock_win, 0, 0, "Name");
Amit Arora031263a2010-11-09 11:12:41 +0530247 print(clock_win, 54, 0, "Flags");
248 print(clock_win, 64, 0, "Rate");
Amit Arora6e774cd2010-10-28 11:31:24 +0530249 print(clock_win, 72, 0, "Usecount");
Amit Arora04f97742010-11-16 11:28:57 +0530250 print(clock_win, 84, 0, "Children");
Amit Arora6e774cd2010-10-28 11:31:24 +0530251 wattroff(clock_win, A_BOLD);
Amit Arora728e0c92010-09-14 12:06:09 +0530252 wrefresh(clock_win);
253}
254
255void print_sensor_header(void)
256{
Amit Arora6e774cd2010-10-28 11:31:24 +0530257 werase(sensor_win);
258 wattron(sensor_win, A_BOLD);
259 print(sensor_win, 0, 0, "Name");
260 print(sensor_win, 36, 0, "Temperature");
261 wattroff(sensor_win, A_BOLD);
262 wattron(sensor_win, A_BLINK);
263 print(sensor_win, 0, 1, "Currently Sensor information available"
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600264 " only in Dump mode!");
Amit Arora6e774cd2010-10-28 11:31:24 +0530265 wattroff(sensor_win, A_BLINK);
Amit Arora728e0c92010-09-14 12:06:09 +0530266 wrefresh(sensor_win);
267}
268
Amit Aroraac4e8652010-11-09 11:16:53 +0530269void print_one_clock(int line, char *str, int bold, int highlight)
Amit Arora728e0c92010-09-14 12:06:09 +0530270{
Amit Arora031263a2010-11-09 11:12:41 +0530271 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530272 wattron(clock_win, WA_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530273 if (highlight)
274 wattron(clock_win, WA_STANDOUT);
275
Amit Arora031263a2010-11-09 11:12:41 +0530276 print(clock_win, 0, line + 1, "%s", str);
277 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530278 wattroff(clock_win, WA_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530279 if (highlight)
280 wattroff(clock_win, WA_STANDOUT);
Amit Arora6e774cd2010-10-28 11:31:24 +0530281 wrefresh(clock_win);
Amit Arora728e0c92010-09-14 12:06:09 +0530282}