aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bts-sysmo/misc/sob_bts_pa.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2015-02-15 19:48:34 +0100
committerHarald Welte <laforge@gnumonks.org>2015-02-15 19:48:34 +0100
commit398459b5998ed1a3f9b82d6ca85f0c62e55445ba (patch)
tree8e673ce13b75218488b53fa7e8a438de11b91a17 /src/osmo-bts-sysmo/misc/sob_bts_pa.c
parentb631bd21d21b10f8e0344dc47af34ef09306d0fb (diff)
Add code to control the PA of the SOB-BTSlaforge/sob-bts-pa-ctrl
At least in v1 of the SOB-BTS, there is a SX1502 I2C GPIO expander to control the two different PAs in the system. This adds a SX150x driver on top of Linux userspae i2c-dev access, and a thin layer of API functions as well as a command line tool. The code is currently still untested.
Diffstat (limited to 'src/osmo-bts-sysmo/misc/sob_bts_pa.c')
-rw-r--r--src/osmo-bts-sysmo/misc/sob_bts_pa.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/osmo-bts-sysmo/misc/sob_bts_pa.c b/src/osmo-bts-sysmo/misc/sob_bts_pa.c
new file mode 100644
index 00000000..24240884
--- /dev/null
+++ b/src/osmo-bts-sysmo/misc/sob_bts_pa.c
@@ -0,0 +1,73 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <errno.h>
+#include <limits.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "i2c-dev.h"
+#include "sx150x.h"
+
+#define SOB_BTS_NUM_PA 2
+
+static int g_pa_gpio_offset;
+static int g_i2c_fd;
+
+int sob_bts_pa_enable(int pa_num, int enable)
+{
+ int level;
+
+ if (pa_num >= SOB_BTS_NUM_PA)
+ return -EINVAL;
+
+ if (enable)
+ level = 0;
+ else
+ level = 1;
+
+ return sx150x_gpio_set(g_i2c_fd, g_pa_gpio_offset + pa_num, level);
+}
+
+int sob_bts_pa_init(int adapter_nr)
+{
+ char filename[PATH_MAX];
+ int rc;
+
+ snprintf(filename, sizeof(filename)-1, "/dev/i2c-%d", adapter_nr);
+ rc = open(filename, O_RDWR);
+ if (rc < 0) {
+ fprintf(stderr, "Error opening the device: %d\n", rc);
+ return rc;
+ }
+
+ g_i2c_fd = rc;
+
+ rc = ioctl(g_i2c_fd, I2C_SLAVE, SX150x_ADDR_ADDR0);
+ if (rc < 0) {
+ fprintf(stderr, "Error setting slave addr: %d\n", rc);
+ close(g_i2c_fd);
+ return rc;
+ }
+
+ /* enable pull-up on GPIO7 */
+ sx150x_gpio_pull_up_set(g_i2c_fd, 7, 1);
+
+ if (sx150x_gpio_get(g_i2c_fd, 7) == 0) {
+ /* daughter board installed: PAs connected to IO2+3 */
+ g_pa_gpio_offset = 2;
+ } else {
+ /* PAs directly connected to 0+1 */
+ g_pa_gpio_offset = 0;
+ }
+
+ /* set both as output */
+ sx150x_gpio_direction_set(g_i2c_fd, g_pa_gpio_offset, SX150x_DIR_OUTPUT);
+ sx150x_gpio_direction_set(g_i2c_fd, g_pa_gpio_offset+1, SX150x_DIR_OUTPUT);
+
+ /* disable them as default */
+ sob_bts_pa_enable(0, 0);
+ sob_bts_pa_enable(1, 0);
+
+ return 0;
+}