1
/*******************************************************************************
2
* Copyright (C) 2010, Linaro Limited.
4
* This file is part of PowerDebug.
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
12
* Amit Arora <amit.arora@linaro.org> (IBM Corporation)
13
* - initial API and implementation
14
*******************************************************************************/
16
#include "powerdebug.h"
19
char *get_num(char *fname, char *sensor)
21
char tmpstr[NAME_MAX];
24
strcpy(tmpstr, (fname+strlen(sensor)));
26
str = strrchr(tmpstr, '_');
33
void get_sensor_info(char *path, char *fname, char *sensor, int verbose)
36
char filename[PATH_MAX];
37
char **items = NULL, **suffix = NULL;
38
char *item, result[NAME_MAX], *num;
41
(void)verbose; // get rid of warning
43
sprintf(filename, "%s/%s", path, fname);
45
if (!strcmp(sensor, "in")) {
46
items = (char **)items_in;
47
suffix = (char **)suffix_in;
50
if (!strcmp(sensor, "temp")) {
51
items = (char **)items_temp;
52
suffix = (char **)suffix_temp;
55
if (!strcmp(sensor, "fan")) {
56
items = (char **)items_fan;
57
suffix = (char **)suffix_fan;
59
if (!strcmp(sensor, "pwm")) {
60
items = (char **)items_pwm;
61
suffix = (char **)suffix_pwm;
65
if (!items || !suffix)
68
item = strrchr(fname, '_');
75
if (item > (fname + strlen(fname)))
78
num = get_num(fname, sensor);
79
filep = fopen(filename, "r");
83
ret = fscanf(filep, "%s", result);
89
while (strcmp(items[count], "")) {
90
if (!strcmp(items[count], item))
91
printf("\'temp\' %s sensor %s\t\t%d%s\n",
92
num, items[count], atoi(result)/1000,
101
int read_and_print_sensor_info(int verbose)
105
char filename[PATH_MAX], devpath[PATH_MAX];
106
char device[PATH_MAX];
107
struct dirent *item, *subitem;
109
printf("\nSensor Information:\n");
110
printf("******************\n");
112
sprintf(filename, "%s", "/sys/class/hwmon");
113
dir = opendir(filename);
117
while ((item = readdir(dir))) {
118
if (item->d_name[0] == '.') /* skip the hidden files */
123
sprintf(filename, "/sys/class/hwmon/%s", item->d_name);
124
sprintf(devpath, "%s/device", filename);
126
len = readlink(devpath, device, PATH_MAX - 1);
129
strcpy(devpath, filename);
133
subdir = opendir(devpath);
135
printf("\nSensor Information for %s :\n", item->d_name);
138
while ((subitem = readdir(subdir))) {
139
if (subitem->d_name[0] == '.') /* skip hidden files */
142
if (!strncmp(subitem->d_name, "in", 2))
143
get_sensor_info(devpath, subitem->d_name, "in",
145
else if (!strncmp(subitem->d_name, "temp", 4))
146
get_sensor_info(devpath, subitem->d_name,
148
else if (!strncmp(subitem->d_name, "fan", 4))
149
get_sensor_info(devpath, subitem->d_name,
151
else if (!strncmp(subitem->d_name, "pwm", 4))
152
get_sensor_info(devpath, subitem->d_name,
161
if (!found && verbose) {
162
printf("Could not find sensor information!");
163
printf(" Looks like /sys/class/hwmon is empty.\n");