From e49bd7bdea873ec11db79d97dd8aebad3f69164d Mon Sep 17 00:00:00 2001 From: John Klug Date: Tue, 20 Oct 2020 10:53:55 -0500 Subject: Add radio-enable, the cellular power supply control --- io-module/machine/mtcap.c | 81 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 2 deletions(-) (limited to 'io-module/machine') diff --git a/io-module/machine/mtcap.c b/io-module/machine/mtcap.c index f701e93..99e1999 100644 --- a/io-module/machine/mtcap.c +++ b/io-module/machine/mtcap.c @@ -74,7 +74,7 @@ static struct gpio_pin gpio_pins_mtcap_0_0[] = { .name = "GNSS_RESET", .pin = { .gpio = AT91_PIN_PD15, - .flags = GPIOF_OUT_INIT_LOW, + .flags = GPIOF_OUT_INIT_LOW, .label = "gnss-reset", }, .capability = CAPA_GPS, @@ -117,6 +117,23 @@ static struct gpio_pin gpio_pins_mtcap_0_0[] = { }, .capability = CAPA_SUPERCAP, }, + /* Cellular power supply */ + { + .name = "RADIO_ENABLE_BBREG", + .pin = { + .gpio = AT91_PIN_PB12, // Radio Buck Boost + .flags = GPIOF_OUT_INIT_HIGH, + .label = "radio-enable-bbreg", + }, + }, + { + .name = "RADIO_ENABLE_LDOREG", + .pin = { + .gpio = AT91_PIN_PB11, // Radio LDO + .flags = GPIOF_OUT_INIT_HIGH, + .label = "radio-enable-ldoreg", + }, + }, /* LEDs */ { .name = "STATUS_LED", // DEV_LED_GN @@ -403,6 +420,36 @@ static ssize_t mts_attr_store_radio_power_mtcap(struct device *dev, return count; } +/* bb and ldo do not exist at the same time, so set both together */ +static ssize_t mts_attr_store_radio_enable_mtcap(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + int value; + int err; + struct gpio_pin *enable_pin_bb = gpio_pin_by_attr_name("radio-enable-bbreg"); + struct gpio_pin *enable_pin_ldo = gpio_pin_by_attr_name("radio-enable-ldoreg"); + + if (sscanf(buf, "%i", &value) != 1) { + return -EINVAL; + } + + mutex_lock(&mts_io_mutex); + if (value == 0) { + gpio_set_value(enable_pin_bb->pin.gpio, 0); + gpio_set_value(enable_pin_ldo->pin.gpio, 0); + } else { + gpio_set_value(enable_pin_bb->pin.gpio, 1); + gpio_set_value(enable_pin_ldo->pin.gpio, 1); + } + mutex_unlock(&mts_io_mutex); + + if (err) { + return err; + } + + return count; +} + static ssize_t mts_attr_store_radio_reset_mtcap(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -468,6 +515,30 @@ static ssize_t mts_attr_show_radio_power_mtcap(struct device *dev, return sprintf(buf, "%d\n", value); } +static ssize_t mts_attr_show_radio_enable_mtcap(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + int value; + struct gpio_pin *enable_pin_bb = gpio_pin_by_attr_name("radio-enable-bbreg"); + struct gpio_pin *enable_pin_ldo = gpio_pin_by_attr_name("radio-enable-ldoreg"); + + if ( !enable_pin_bb ) { + return -ENODEV; + } + if ( !enable_pin_ldo ) { + return -ENODEV; + } + + + value = gpio_get_value(enable_pin_bb->pin.gpio); + value += (gpio_get_value(enable_pin_ldo->pin.gpio) * 2); + + + return sprintf(buf, "%d\n", value); +} + + static DEVICE_ATTR_MTS(dev_attr_radio_reset_mtcap, "radio-reset", mts_attr_show_gpio_pin, mts_attr_store_radio_reset_mtcap); @@ -529,7 +600,6 @@ static struct attribute_group mtcap_0_0_platform_attribute_group = { .attrs = mtcap_0_0_platform_attributes }; - // // on-board LORA attributes are to be stored in the lora/ sub-directory // @@ -593,12 +663,19 @@ static DEVICE_ATTR_RO_MTS(dev_attr_supercap_power_fail_mtcap, "power-fail", static DEVICE_ATTR_RO_MTS(dev_attr_supercap_supercap_full_mtcap, "supercap-full", mts_attr_show_gpio_pin); +static DEVICE_ATTR_MTS(dev_attr_radio_enable_mtcap, "radio-enable", + mts_attr_show_radio_enable_mtcap, mts_attr_store_radio_enable_mtcap); + static struct attribute *mtcap_0_3_supercap_attributes[] = { &dev_attr_supercap_allow_reset_mtcap.attr, &dev_attr_supercap_power_fail_mtcap.attr, &dev_attr_supercap_supercap_full_mtcap.attr, }; +static struct attribute *mtcap_0_2_enable_radio_attribute[] = { + &dev_attr_radio_enable_mtcap.attr, +}; + static struct attribute *mtcap_0_0_wifi_attributes[] = { &dev_attr_wlan_en_gpio_mtcap.attr, &dev_attr_wlan_rst_gpio_mtcap.attr, -- cgit v1.2.3