blob: 2ab2167c66c2c668fc8b175b22e5442a92b7bfaa [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 Arora47fd9182010-08-24 13:26:06 +053037static WINDOW *footer_win;
38
39int maxx, maxy;
Daniel Lezcano68500e82011-06-08 23:30:00 +020040static char footer_items[NUM_FOOTER_ITEMS][64];
Amit Arora47fd9182010-08-24 13:26:06 +053041
Daniel Lezcanod5a2c6d2011-03-23 14:37:38 +010042static char *win_names[TOTAL_FEATURE_WINS] = {
43 "Clocks",
44 "Regulators",
45 "Sensors"
46};
Amit Arora47fd9182010-08-24 13:26:06 +053047
Amit Arorac93e0712010-10-07 13:51:53 +053048/* "all" : Kill header and footer windows too ? */
49void killall_windows(int all)
Amit Arora47fd9182010-08-24 13:26:06 +053050{
Amit Arorac93e0712010-10-07 13:51:53 +053051 if (all && header_win) {
Amit Arora47fd9182010-08-24 13:26:06 +053052 delwin(header_win);
53 header_win = NULL;
54 }
55 if (regulator_win) {
56 delwin(regulator_win);
57 regulator_win = NULL;
58 }
Amit Arora728e0c92010-09-14 12:06:09 +053059 if (clock_win) {
60 delwin(clock_win);
61 clock_win = NULL;
62 }
63 if (sensor_win) {
64 delwin(sensor_win);
65 sensor_win = NULL;
66 }
Amit Arorac93e0712010-10-07 13:51:53 +053067 if (all && footer_win) {
Amit Arora47fd9182010-08-24 13:26:06 +053068 delwin(footer_win);
69 footer_win = NULL;
70 }
71}
72
Daniel Lezcano3abd8b12011-03-26 22:06:15 +010073static void display_fini(void)
74{
75 endwin();
76}
77
Daniel Lezcanoca17a722011-03-26 22:06:16 +010078int display_init(void)
Amit Arora47fd9182010-08-24 13:26:06 +053079{
Daniel Lezcanoca17a722011-03-26 22:06:16 +010080 if (!initscr())
81 return -1;
82
Amit Arora6e774cd2010-10-28 11:31:24 +053083 start_color();
Daniel Lezcanoca17a722011-03-26 22:06:16 +010084 use_default_colors();
85
Amit Arora6e774cd2010-10-28 11:31:24 +053086 keypad(stdscr, TRUE);
87 noecho();
88 cbreak();
89 curs_set(0);
90 nonl();
Amit Arora47fd9182010-08-24 13:26:06 +053091
Daniel Lezcanoca17a722011-03-26 22:06:16 +010092 if (init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK) ||
93 init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED) ||
94 init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK) ||
95 init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW) ||
96 init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN) ||
97 init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK) ||
98 init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE) ||
99 init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED))
100 return -1;
Amit Arora47fd9182010-08-24 13:26:06 +0530101
Daniel Lezcanoca17a722011-03-26 22:06:16 +0100102 return atexit(display_fini);
Amit Arora47fd9182010-08-24 13:26:06 +0530103}
104
Daniel Lezcano558a6d52011-03-23 14:37:41 +0100105void create_windows(int selectedwindow)
Amit Arora47fd9182010-08-24 13:26:06 +0530106{
107
108 getmaxyx(stdscr, maxy, maxx);
Amit Arorac93e0712010-10-07 13:51:53 +0530109 killall_windows(1);
Amit Arora47fd9182010-08-24 13:26:06 +0530110
111 header_win = subwin(stdscr, 1, maxx, 0, 0);
Amit Arora47fd9182010-08-24 13:26:06 +0530112 footer_win = subwin(stdscr, 1, maxx, maxy-1, 0);
113
114 strcpy(footer_items[0], " Q (Quit) ");
115 strcpy(footer_items[1], " R (Refresh) ");
116
Amit Arora83ae6cb2010-12-02 12:22:19 +0530117 if (selectedwindow == CLOCK)
118 strcpy(footer_items[2], " Other Keys: 'Left', 'Right', 'Up', 'Down', 'enter', "
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600119 " '/', 'Esc' ");
Amit Arora83ae6cb2010-12-02 12:22:19 +0530120 else
121 strcpy(footer_items[2], " Other Keys: 'Left', 'Right' ");
122
123 strcpy(footer_items[3], "");
124
Amit Arora47fd9182010-08-24 13:26:06 +0530125 werase(stdscr);
126 refresh();
127
128}
129
Daniel Lezcano558a6d52011-03-23 14:37:41 +0100130void create_selectedwindow(int selectedwindow)
Amit Arora728e0c92010-09-14 12:06:09 +0530131{
Amit Arora6e774cd2010-10-28 11:31:24 +0530132 WINDOW *win;
Amit Arora728e0c92010-09-14 12:06:09 +0530133
Amit Arora6e774cd2010-10-28 11:31:24 +0530134 killall_windows(0);
Amit Arora728e0c92010-09-14 12:06:09 +0530135
Amit Arora6e774cd2010-10-28 11:31:24 +0530136 getmaxyx(stdscr, maxy, maxx);
Amit Arora24ed7d12010-09-14 12:12:58 +0530137
Amit Arora6e774cd2010-10-28 11:31:24 +0530138 win = subwin(stdscr, maxy - 2, maxx, 1, 0);
Amit Arora728e0c92010-09-14 12:06:09 +0530139
Amit Arora6e774cd2010-10-28 11:31:24 +0530140 switch (selectedwindow) {
141 case REGULATOR: regulator_win = win;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600142 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530143
Amit Arora6e774cd2010-10-28 11:31:24 +0530144 case CLOCK: clock_win = win;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600145 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530146
Amit Arora6e774cd2010-10-28 11:31:24 +0530147 case SENSOR: sensor_win = win;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600148 break;
Amit Arora6e774cd2010-10-28 11:31:24 +0530149 }
Amit Arora728e0c92010-09-14 12:06:09 +0530150
Amit Arora6e774cd2010-10-28 11:31:24 +0530151 refresh();
Amit Arora728e0c92010-09-14 12:06:09 +0530152}
Amit Arora47fd9182010-08-24 13:26:06 +0530153
Daniel Lezcano558a6d52011-03-23 14:37:41 +0100154void show_header(int selectedwindow)
Amit Arora47fd9182010-08-24 13:26:06 +0530155{
156 int i, j = 0;
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530157 int curr_pointer = 0;
Amit Arora47fd9182010-08-24 13:26:06 +0530158
159 wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
160 wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
161 werase(header_win);
162
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530163 print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION);
164 curr_pointer += 20;
Amit Arora47fd9182010-08-24 13:26:06 +0530165
Amit Arora6e774cd2010-10-28 11:31:24 +0530166 for (i = 0; i < TOTAL_FEATURE_WINS; i++) {
167 if (selectedwindow == i)
168 wattron(header_win, A_REVERSE);
169 else
170 wattroff(header_win, A_REVERSE);
Amit Arorac93e0712010-10-07 13:51:53 +0530171
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530172 print(header_win, curr_pointer, 0, " %s ", win_names[i]);
173 curr_pointer += strlen(win_names[i]) + 2;
Amit Arora6e774cd2010-10-28 11:31:24 +0530174 }
175 wrefresh(header_win);
Amit Arora47fd9182010-08-24 13:26:06 +0530176 werase(footer_win);
177
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600178 for (i = 0; i < NUM_FOOTER_ITEMS; i++) {
179 if (strlen(footer_items[i]) == 0)
Amit Arora47fd9182010-08-24 13:26:06 +0530180 continue;
181 wattron(footer_win, A_REVERSE);
182 print(footer_win, j, 0, "%s", footer_items[i]);
183 wattroff(footer_win, A_REVERSE);
184 j+= strlen(footer_items[i])+1;
185 }
186 wrefresh(footer_win);
187}
188
189
Daniel Lezcano833b63a2011-03-26 22:06:00 +0100190void show_regulator_info(struct regulator_info *reg_info, int nr_reg, int verbose)
Amit Arora47fd9182010-08-24 13:26:06 +0530191{
Amit Arorac93e0712010-10-07 13:51:53 +0530192 int i, count = 1;
Amit Arora47fd9182010-08-24 13:26:06 +0530193
Amit Arora6e774cd2010-10-28 11:31:24 +0530194 (void)verbose;
Amit Arorabf50db92010-10-07 14:09:05 +0530195
Amit Arora47fd9182010-08-24 13:26:06 +0530196 werase(regulator_win);
197 wattron(regulator_win, A_BOLD);
Amit Arorac93e0712010-10-07 13:51:53 +0530198 print(regulator_win, 0, 0, "Name");
199 print(regulator_win, 12, 0, "Status");
200 print(regulator_win, 24, 0, "State");
201 print(regulator_win, 36, 0, "Type");
202 print(regulator_win, 48, 0, "Users");
203 print(regulator_win, 60, 0, "Microvolts");
204 print(regulator_win, 72, 0, "Min u-volts");
205 print(regulator_win, 84, 0, "Max u-volts");
Amit Arora47fd9182010-08-24 13:26:06 +0530206 wattroff(regulator_win, A_BOLD);
207
Daniel Lezcano833b63a2011-03-26 22:06:00 +0100208 for (i = 0; i < nr_reg; i++) {
Amit Arora47fd9182010-08-24 13:26:06 +0530209 int col = 0;
210
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600211 if ((i + 2) > (maxy-2))
Amit Arora47fd9182010-08-24 13:26:06 +0530212 break;
213
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100214 if (reg_info[i].num_users > 0)
Amit Arora6e774cd2010-10-28 11:31:24 +0530215 wattron(regulator_win, WA_BOLD);
216 else
217 wattroff(regulator_win, WA_BOLD);
218
Amit Arora47fd9182010-08-24 13:26:06 +0530219 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100220 reg_info[i].name);
Amit Arora47fd9182010-08-24 13:26:06 +0530221 col += 12;
222 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100223 reg_info[i].status);
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].state);
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].type);
Amit Arora47fd9182010-08-24 13:26:06 +0530230 col += 12;
231 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100232 reg_info[i].num_users);
Amit Arora6a943ec2010-10-07 11:49:25 +0530233 col += 12;
234 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100235 reg_info[i].microvolts);
Amit Arora47fd9182010-08-24 13:26:06 +0530236 col += 12;
237 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100238 reg_info[i].min_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].max_microvolts);
Amit Arora47fd9182010-08-24 13:26:06 +0530242
243 count++;
244 }
245 wrefresh(regulator_win);
246}
247
Amit Arora728e0c92010-09-14 12:06:09 +0530248
Amit Aroraac4e8652010-11-09 11:16:53 +0530249void print_clock_header(void)
Amit Arora728e0c92010-09-14 12:06:09 +0530250{
Amit Arora6e774cd2010-10-28 11:31:24 +0530251 werase(clock_win);
252 wattron(clock_win, A_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530253 print(clock_win, 0, 0, "Name");
Amit Arora031263a2010-11-09 11:12:41 +0530254 print(clock_win, 54, 0, "Flags");
255 print(clock_win, 64, 0, "Rate");
Amit Arora6e774cd2010-10-28 11:31:24 +0530256 print(clock_win, 72, 0, "Usecount");
Amit Arora04f97742010-11-16 11:28:57 +0530257 print(clock_win, 84, 0, "Children");
Amit Arora6e774cd2010-10-28 11:31:24 +0530258 wattroff(clock_win, A_BOLD);
Amit Arora728e0c92010-09-14 12:06:09 +0530259 wrefresh(clock_win);
260}
261
262void print_sensor_header(void)
263{
Amit Arora6e774cd2010-10-28 11:31:24 +0530264 werase(sensor_win);
265 wattron(sensor_win, A_BOLD);
266 print(sensor_win, 0, 0, "Name");
267 print(sensor_win, 36, 0, "Temperature");
268 wattroff(sensor_win, A_BOLD);
269 wattron(sensor_win, A_BLINK);
270 print(sensor_win, 0, 1, "Currently Sensor information available"
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600271 " only in Dump mode!");
Amit Arora6e774cd2010-10-28 11:31:24 +0530272 wattroff(sensor_win, A_BLINK);
Amit Arora728e0c92010-09-14 12:06:09 +0530273 wrefresh(sensor_win);
274}
275
Amit Aroraac4e8652010-11-09 11:16:53 +0530276void print_one_clock(int line, char *str, int bold, int highlight)
Amit Arora728e0c92010-09-14 12:06:09 +0530277{
Amit Arora031263a2010-11-09 11:12:41 +0530278 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530279 wattron(clock_win, WA_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530280 if (highlight)
281 wattron(clock_win, WA_STANDOUT);
282
Amit Arora031263a2010-11-09 11:12:41 +0530283 print(clock_win, 0, line + 1, "%s", str);
284 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530285 wattroff(clock_win, WA_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530286 if (highlight)
287 wattroff(clock_win, WA_STANDOUT);
Amit Arora6e774cd2010-10-28 11:31:24 +0530288 wrefresh(clock_win);
Amit Arora728e0c92010-09-14 12:06:09 +0530289}