From 398459b5998ed1a3f9b82d6ca85f0c62e55445ba Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 15 Feb 2015 19:48:34 +0100 Subject: Add code to control the PA of the SOB-BTS 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. --- src/osmo-bts-sysmo/misc/sob_bts_pa.c | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/osmo-bts-sysmo/misc/sob_bts_pa.c (limited to 'src/osmo-bts-sysmo/misc/sob_bts_pa.c') 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 +#include +#include +#include +#include +#include +#include + +#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; +} -- cgit v1.2.3