blob: dd5543cfe806501d0941bb2bf140b07490bc6c81 [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
Daniel Lezcano3abd8b12011-03-26 22:06:15 +010048static void display_fini(void)
49{
50 endwin();
51}
52
Daniel Lezcanoca17a722011-03-26 22:06:16 +010053int display_init(void)
Amit Arora47fd9182010-08-24 13:26:06 +053054{
Daniel Lezcanoca17a722011-03-26 22:06:16 +010055 if (!initscr())
56 return -1;
57
Amit Arora6e774cd2010-10-28 11:31:24 +053058 start_color();
Daniel Lezcanoca17a722011-03-26 22:06:16 +010059 use_default_colors();
60
Amit Arora6e774cd2010-10-28 11:31:24 +053061 keypad(stdscr, TRUE);
62 noecho();
63 cbreak();
64 curs_set(0);
65 nonl();
Amit Arora47fd9182010-08-24 13:26:06 +053066
Daniel Lezcanoca17a722011-03-26 22:06:16 +010067 if (init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK) ||
68 init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED) ||
69 init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK) ||
70 init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW) ||
71 init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN) ||
72 init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK) ||
73 init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE) ||
74 init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED))
75 return -1;
Amit Arora47fd9182010-08-24 13:26:06 +053076
Daniel Lezcano1c25df92011-06-08 23:30:00 +020077 if (atexit(display_fini))
78 return -1;
79
80 getmaxyx(stdscr, maxy, maxx);
81
82 regulator_win = subwin(stdscr, maxy - 2, maxx, 1, 0);
83 if (!regulator_win)
84 return -1;
85
86 clock_win = subwin(stdscr, maxy - 2, maxx, 1, 0);
87 if (!clock_win)
88 return -1;
89
90 sensor_win = subwin(stdscr, maxy - 2, maxx, 1, 0);
91 if (!sensor_win)
92 return -1;
93
94 header_win = subwin(stdscr, 1, maxx, 0, 0);
95 if (!header_win)
96 return -1;
97
98 footer_win = subwin(stdscr, 1, maxx, maxy-1, 0);
99 if (!footer_win)
100 return -1;
101
102 return 0;
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{
Amit Arora47fd9182010-08-24 13:26:06 +0530107 strcpy(footer_items[0], " Q (Quit) ");
108 strcpy(footer_items[1], " R (Refresh) ");
109
Amit Arora83ae6cb2010-12-02 12:22:19 +0530110 if (selectedwindow == CLOCK)
111 strcpy(footer_items[2], " Other Keys: 'Left', 'Right', 'Up', 'Down', 'enter', "
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600112 " '/', 'Esc' ");
Amit Arora83ae6cb2010-12-02 12:22:19 +0530113 else
114 strcpy(footer_items[2], " Other Keys: 'Left', 'Right' ");
115
116 strcpy(footer_items[3], "");
117
Amit Arora47fd9182010-08-24 13:26:06 +0530118 werase(stdscr);
119 refresh();
120
121}
122
Daniel Lezcano558a6d52011-03-23 14:37:41 +0100123void create_selectedwindow(int selectedwindow)
Amit Arora728e0c92010-09-14 12:06:09 +0530124{
Amit Arora6e774cd2010-10-28 11:31:24 +0530125 switch (selectedwindow) {
Daniel Lezcano1c25df92011-06-08 23:30:00 +0200126 case REGULATOR:
127 wrefresh(regulator_win);
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600128 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530129
Daniel Lezcano1c25df92011-06-08 23:30:00 +0200130 case CLOCK:
131 wrefresh(clock_win);
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600132 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530133
Daniel Lezcano1c25df92011-06-08 23:30:00 +0200134 case SENSOR:
135 wrefresh(sensor_win);
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600136 break;
Amit Arora6e774cd2010-10-28 11:31:24 +0530137 }
Amit Arora728e0c92010-09-14 12:06:09 +0530138}
Amit Arora47fd9182010-08-24 13:26:06 +0530139
Daniel Lezcano558a6d52011-03-23 14:37:41 +0100140void show_header(int selectedwindow)
Amit Arora47fd9182010-08-24 13:26:06 +0530141{
142 int i, j = 0;
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530143 int curr_pointer = 0;
Amit Arora47fd9182010-08-24 13:26:06 +0530144
145 wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
146 wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
147 werase(header_win);
148
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530149 print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION);
150 curr_pointer += 20;
Amit Arora47fd9182010-08-24 13:26:06 +0530151
Amit Arora6e774cd2010-10-28 11:31:24 +0530152 for (i = 0; i < TOTAL_FEATURE_WINS; i++) {
153 if (selectedwindow == i)
154 wattron(header_win, A_REVERSE);
155 else
156 wattroff(header_win, A_REVERSE);
Amit Arorac93e0712010-10-07 13:51:53 +0530157
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530158 print(header_win, curr_pointer, 0, " %s ", win_names[i]);
159 curr_pointer += strlen(win_names[i]) + 2;
Amit Arora6e774cd2010-10-28 11:31:24 +0530160 }
161 wrefresh(header_win);
Amit Arora47fd9182010-08-24 13:26:06 +0530162 werase(footer_win);
163
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600164 for (i = 0; i < NUM_FOOTER_ITEMS; i++) {
165 if (strlen(footer_items[i]) == 0)
Amit Arora47fd9182010-08-24 13:26:06 +0530166 continue;
167 wattron(footer_win, A_REVERSE);
168 print(footer_win, j, 0, "%s", footer_items[i]);
169 wattroff(footer_win, A_REVERSE);
170 j+= strlen(footer_items[i])+1;
171 }
172 wrefresh(footer_win);
173}
174
175
Daniel Lezcano833b63a2011-03-26 22:06:00 +0100176void show_regulator_info(struct regulator_info *reg_info, int nr_reg, int verbose)
Amit Arora47fd9182010-08-24 13:26:06 +0530177{
Amit Arorac93e0712010-10-07 13:51:53 +0530178 int i, count = 1;
Amit Arora47fd9182010-08-24 13:26:06 +0530179
Amit Arora6e774cd2010-10-28 11:31:24 +0530180 (void)verbose;
Amit Arorabf50db92010-10-07 14:09:05 +0530181
Amit Arora47fd9182010-08-24 13:26:06 +0530182 werase(regulator_win);
183 wattron(regulator_win, A_BOLD);
Amit Arorac93e0712010-10-07 13:51:53 +0530184 print(regulator_win, 0, 0, "Name");
185 print(regulator_win, 12, 0, "Status");
186 print(regulator_win, 24, 0, "State");
187 print(regulator_win, 36, 0, "Type");
188 print(regulator_win, 48, 0, "Users");
189 print(regulator_win, 60, 0, "Microvolts");
190 print(regulator_win, 72, 0, "Min u-volts");
191 print(regulator_win, 84, 0, "Max u-volts");
Amit Arora47fd9182010-08-24 13:26:06 +0530192 wattroff(regulator_win, A_BOLD);
193
Daniel Lezcano833b63a2011-03-26 22:06:00 +0100194 for (i = 0; i < nr_reg; i++) {
Amit Arora47fd9182010-08-24 13:26:06 +0530195 int col = 0;
196
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600197 if ((i + 2) > (maxy-2))
Amit Arora47fd9182010-08-24 13:26:06 +0530198 break;
199
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100200 if (reg_info[i].num_users > 0)
Amit Arora6e774cd2010-10-28 11:31:24 +0530201 wattron(regulator_win, WA_BOLD);
202 else
203 wattroff(regulator_win, WA_BOLD);
204
Amit Arora47fd9182010-08-24 13:26:06 +0530205 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100206 reg_info[i].name);
Amit Arora47fd9182010-08-24 13:26:06 +0530207 col += 12;
208 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100209 reg_info[i].status);
Amit Arora47fd9182010-08-24 13:26:06 +0530210 col += 12;
211 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100212 reg_info[i].state);
Amit Arora47fd9182010-08-24 13:26:06 +0530213 col += 12;
214 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100215 reg_info[i].type);
Amit Arora47fd9182010-08-24 13:26:06 +0530216 col += 12;
217 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100218 reg_info[i].num_users);
Amit Arora6a943ec2010-10-07 11:49:25 +0530219 col += 12;
220 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100221 reg_info[i].microvolts);
Amit Arora47fd9182010-08-24 13:26:06 +0530222 col += 12;
223 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100224 reg_info[i].min_microvolts);
Amit Arora47fd9182010-08-24 13:26:06 +0530225 col += 12;
226 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100227 reg_info[i].max_microvolts);
Amit Arora47fd9182010-08-24 13:26:06 +0530228
229 count++;
230 }
231 wrefresh(regulator_win);
232}
233
Amit Arora728e0c92010-09-14 12:06:09 +0530234
Amit Aroraac4e8652010-11-09 11:16:53 +0530235void print_clock_header(void)
Amit Arora728e0c92010-09-14 12:06:09 +0530236{
Amit Arora6e774cd2010-10-28 11:31:24 +0530237 werase(clock_win);
238 wattron(clock_win, A_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530239 print(clock_win, 0, 0, "Name");
Amit Arora031263a2010-11-09 11:12:41 +0530240 print(clock_win, 54, 0, "Flags");
241 print(clock_win, 64, 0, "Rate");
Amit Arora6e774cd2010-10-28 11:31:24 +0530242 print(clock_win, 72, 0, "Usecount");
Amit Arora04f97742010-11-16 11:28:57 +0530243 print(clock_win, 84, 0, "Children");
Amit Arora6e774cd2010-10-28 11:31:24 +0530244 wattroff(clock_win, A_BOLD);
Amit Arora728e0c92010-09-14 12:06:09 +0530245 wrefresh(clock_win);
246}
247
248void print_sensor_header(void)
249{
Amit Arora6e774cd2010-10-28 11:31:24 +0530250 werase(sensor_win);
251 wattron(sensor_win, A_BOLD);
252 print(sensor_win, 0, 0, "Name");
253 print(sensor_win, 36, 0, "Temperature");
254 wattroff(sensor_win, A_BOLD);
255 wattron(sensor_win, A_BLINK);
256 print(sensor_win, 0, 1, "Currently Sensor information available"
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600257 " only in Dump mode!");
Amit Arora6e774cd2010-10-28 11:31:24 +0530258 wattroff(sensor_win, A_BLINK);
Amit Arora728e0c92010-09-14 12:06:09 +0530259 wrefresh(sensor_win);
260}
261
Amit Aroraac4e8652010-11-09 11:16:53 +0530262void print_one_clock(int line, char *str, int bold, int highlight)
Amit Arora728e0c92010-09-14 12:06:09 +0530263{
Amit Arora031263a2010-11-09 11:12:41 +0530264 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530265 wattron(clock_win, WA_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530266 if (highlight)
267 wattron(clock_win, WA_STANDOUT);
268
Amit Arora031263a2010-11-09 11:12:41 +0530269 print(clock_win, 0, line + 1, "%s", str);
270 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530271 wattroff(clock_win, WA_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530272 if (highlight)
273 wattroff(clock_win, WA_STANDOUT);
Amit Arora6e774cd2010-10-28 11:31:24 +0530274 wrefresh(clock_win);
Amit Arora728e0c92010-09-14 12:06:09 +0530275}