aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bts-sysmo/hw_misc.c
blob: 6aa3b83f85d39e7accd5f39caf0966ef8f1417f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* Misc HW routines for Sysmocom BTS */

/* (C) 2012 by Harald Welte <laforge@gnumonks.org>
 *
 * All Rights Reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <stdint.h>
#include <unistd.h>
#include <limits.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>

#include <sys/types.h>
#include <sys/stat.h>

#include <osmocom/core/utils.h>

#include "hw_misc.h"

static const struct value_string sysmobts_led_names[] = {
	{ LED_RF_ACTIVE,	"activity_led" },
	{ LED_ONLINE,		"online_led" },
	{ 0, NULL }
};

int sysmobts_led_set(enum sysmobts_led nr, int on)
{
	char tmp[PATH_MAX+1];
	const char *filename;
	int fd;
	uint8_t byte;

	if (on)
		byte = '1';
	else
		byte = '0';

	filename = get_value_string(sysmobts_led_names, nr);
	if (!filename)
		return -EINVAL;

	snprintf(tmp, sizeof(tmp)-1, "/sys/class/leds/%s/brightness", filename);
	tmp[sizeof(tmp)-1] = '\0';

	fd = open(tmp, O_WRONLY);
	if (fd < 0)
		return -ENODEV;

	write(fd, &byte, 1);

	close(fd);

	return 0;
}

#if 0
#define HWMON_PREFIX "/sys/class/hwmon/hwmon0/device"

static FILE *temperature_f[NUM_TEMP];

int sysmobts_temp_init()
{
	char tmp[PATH_MAX+1];
	FILE *in;
	int rc = 0;

	for (i = 0; i < NUM_TEMP; i++) {
		snprintf(tmp, sizeof(tmp)-1, HWMON_PREFIX "/temp%u_input", i+1),
		tmp[sizeof(tmp)-1] = '\0';

		temperature_f[i] = fopen(tmp, "r");
		if (!temperature_f[i])
			rc = -ENODEV;
	}

	return 0;
}

int sysmobts_temp_get(uint8_t num)
{
	if (num >= NUM_TEMP)
		return -EINVAL;

	if (!temperature_f[num])
		return -ENODEV;


	in = fopen(tmp, "r");
	if (!in)
		return -ENODEV;

	fclose(tmp);

	return 0;
}
#endif