aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bts-litecell15/misc/lc15bts_temp.c
diff options
context:
space:
mode:
authorYves Godin <support@nuranwireless.com>2015-11-12 08:32:07 -0500
committerHarald Welte <laforge@gnumonks.org>2016-02-15 14:26:33 +0100
commit2a711887b7e91893555891e5c033189d6705eec3 (patch)
tree00abee90a3e8d04f01f34df54f7d7f1c3494fd50 /src/osmo-bts-litecell15/misc/lc15bts_temp.c
parent5a945dad0cb34dc351427b33a3ce0ed9dd0e394f (diff)
LC15: Add initial support for the NuRAN Wireless Litecell 1.5
This commit adds basic support for the Litecell 1.5. Multi-TRX is not supported yet. Instead, multiple instances of the BTS can be launched using command line parameter -n <HW_TRX_NR> to specify if TRX 1 or 2 must be used by the bts. Note that only TRX 1 opens a connection to the PCU. Full support for GPRS on both TRX will come at the same time than the multi-TRX support. The BTS manager has been adapted to match the new hardware but otherwise it has not been improved or changed compared to the one used on the SuperFemto/Litecell (sysmobts).
Diffstat (limited to 'src/osmo-bts-litecell15/misc/lc15bts_temp.c')
-rw-r--r--src/osmo-bts-litecell15/misc/lc15bts_temp.c117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/osmo-bts-litecell15/misc/lc15bts_temp.c b/src/osmo-bts-litecell15/misc/lc15bts_temp.c
new file mode 100644
index 00000000..fa6300e7
--- /dev/null
+++ b/src/osmo-bts-litecell15/misc/lc15bts_temp.c
@@ -0,0 +1,117 @@
+/* Copyright (C) 2015 by Yves Godin <support@nuranwireless.com>
+ *
+ * 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 <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+
+#include <osmocom/core/utils.h>
+
+#include "lc15bts_temp.h"
+
+
+static const char *temp_devs[_NUM_TEMP_SENSORS] = {
+ [LC15BTS_TEMP_SUPPLY] = "/sys/bus/i2c/devices/2-004d/hwmon/hwmon5/temp1_",
+ [LC15BTS_TEMP_SOC] = "/sys/class/hwmon/hwmon1/temp1_",
+ [LC15BTS_TEMP_FPGA] = "/sys/devices/0.iio_hwmon/temp1_",
+ [LC15BTS_TEMP_MEMORY] = "/sys/bus/i2c/devices/2-004c/hwmon/hwmon4/temp1_",
+ [LC15BTS_TEMP_TX1] = "/sys/devices/0.ncp15xh103_tx1/temp1_",
+ [LC15BTS_TEMP_TX2] = "/sys/devices/0.ncp15xh103_tx2/temp1_",
+ [LC15BTS_TEMP_PA1] = "/sys/bus/i2c/devices/2-004d/hwmon/hwmon5/temp2_",
+ [LC15BTS_TEMP_PA2] = "/sys/bus/i2c/devices/2-004c/hwmon/hwmon4/temp2_",
+};
+
+static const int temp_has_fault[_NUM_TEMP_SENSORS] = {
+ [LC15BTS_TEMP_PA1] = 1,
+ [LC15BTS_TEMP_PA2] = 1,
+};
+
+static const char *temp_type_str[_NUM_TEMP_TYPES] = {
+ [LC15BTS_TEMP_INPUT] = "input",
+ [LC15BTS_TEMP_LOWEST] = "lowest",
+ [LC15BTS_TEMP_HIGHEST] = "highest",
+ [LC15BTS_TEMP_FAULT] = "fault",
+};
+
+int lc15bts_temp_get(enum lc15bts_temp_sensor sensor,
+ enum lc15bts_temp_type type)
+{
+ char buf[PATH_MAX];
+ char tempstr[8];
+ char faultstr[8];
+ int fd, rc;
+
+ if (sensor < 0 || sensor >= _NUM_TEMP_SENSORS)
+ return -EINVAL;
+
+ if (type >= ARRAY_SIZE(temp_type_str))
+ return -EINVAL;
+
+ snprintf(buf, sizeof(buf)-1, "%s%s", temp_devs[sensor], temp_type_str[type]);
+ buf[sizeof(buf)-1] = '\0';
+
+ fd = open(buf, O_RDONLY);
+ if (fd < 0)
+ return fd;
+
+ rc = read(fd, tempstr, sizeof(tempstr));
+ tempstr[sizeof(tempstr)-1] = '\0';
+ if (rc < 0) {
+ close(fd);
+ return rc;
+ }
+ if (rc == 0) {
+ close(fd);
+ return -EIO;
+ }
+ close(fd);
+
+ // Check fault
+ if (type == LC15BTS_TEMP_FAULT || !temp_has_fault[sensor])
+ return atoi(tempstr);
+
+ snprintf(buf, sizeof(buf)-1, "%s%s", temp_devs[sensor], temp_type_str[LC15BTS_TEMP_FAULT]);
+ buf[sizeof(buf)-1] = '\0';
+
+ fd = open(buf, O_RDONLY);
+ if (fd < 0)
+ return fd;
+
+ rc = read(fd, faultstr, sizeof(faultstr));
+ tempstr[sizeof(faultstr)-1] = '\0';
+ if (rc < 0) {
+ close(fd);
+ return rc;
+ }
+ if (rc == 0) {
+ close(fd);
+ return -EIO;
+ }
+ close(fd);
+
+ if (atoi(faultstr))
+ return -EIO;
+
+ return atoi(tempstr);
+}
+