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 --- configure.ac | 2 +- io-module/machine/mtcap.c | 81 +++++++++++++++++++++++++++++++++++++++++++++-- io-module/mts-io.c | 33 +++++++++++++------ io-module/mts_io_module.h | 2 +- 4 files changed, 104 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 511de1c..c9bc1d9 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([mts-io], [4.4.1]) +AC_INIT([mts-io], [4.4.2]) AC_CONFIG_SRCDIR([util/mts_util_lora2_reset.c]) AM_INIT_AUTOMAKE AM_CONFIG_HEADER([config.h]) 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, diff --git a/io-module/mts-io.c b/io-module/mts-io.c index 0f4854b..09f0eef 100644 --- a/io-module/mts-io.c +++ b/io-module/mts-io.c @@ -540,7 +540,7 @@ static ssize_t mts_attr_show_product_info(struct device *dev, value = sprintf(buf, "%.32s\n", id_eeprom.product_id); } else if (strcmp(attr->attr.name, "has-radio") == 0) { if(id_eeprom.eeprom_layout_version == 0) - value = sprintf(buf, "%1lu\n", + value = sprintf(buf, "%d\n", mts_has_radio(id_eeprom.product_id,sizeof id_eeprom.product_id)); else /* Newer EEPROM version with CAPA_CELLULAR */ @@ -700,8 +700,9 @@ mts_id_eeprom_load(void) ((tmp=HW_VERSION_MTCAP_0_1),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) || ((tmp=HW_VERSION_MTCAP_0_2),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) || ((tmp=HW_VERSION_MTCAP_0_3),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0)) { - current_blength = attr_blength = sizeof mtcap_0_0_platform_attributes; - current_blength -= sizeof(struct attribute *); /* Length without terminating NULL */ + int need_radio_enable = 0; + current_blength = attr_blength = sizeof mtcap_0_0_platform_attributes; + current_blength -= sizeof(struct attribute *); /* Length without terminating NULL */ /* See if we have no radio, and if so, prune out the stuff that follows */ if(noradio) { struct attribute **ap = mtcap_0_0_platform_attribute_group.attrs; @@ -729,6 +730,12 @@ mts_id_eeprom_load(void) if(DEVICE_CAPA(id_eeprom.capa, CAPA_WIFI)) { attr_blength += sizeof mtcap_0_0_wifi_attributes; } + if(((tmp=HW_VERSION_MTCAP_0_2),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) || + ((tmp=HW_VERSION_MTCAP_0_3),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0)) { + need_radio_enable = 1; + attr_blength += sizeof mtcap_0_2_enable_radio_attribute; + } + if (current_blength+(sizeof(struct attribute *)) != attr_blength) { freelater = all_attrs = kmalloc(attr_blength,GFP_KERNEL); current_count = current_blength/(sizeof (struct attribute *)); @@ -748,12 +755,18 @@ mts_id_eeprom_load(void) memcpy(all_attrs + current_count,mtcap_0_0_wifi_attributes,sizeof mtcap_0_0_wifi_attributes); current_count += sizeof mtcap_0_0_wifi_attributes / (sizeof (struct attribute *)); } + if (need_radio_enable) { + log_info("Adding Radio Enable to mts-io driver"); + memcpy(all_attrs + current_count,mtcap_0_2_enable_radio_attribute,sizeof mtcap_0_2_enable_radio_attribute); + current_count += sizeof mtcap_0_2_enable_radio_attribute / (sizeof (struct attribute *)); + } + all_attrs[current_count] = (struct attribute *)NULL; mtcap_0_0_platform_attribute_group.attrs = all_attrs; } attr_group = &mtcap_0_0_platform_attribute_group; - gpio_pins = gpio_pins_mtcap_0_0; - set_buttons(default_buttons); + gpio_pins = gpio_pins_mtcap_0_0; + set_buttons(default_buttons); if (DEVICE_CAPA(id_eeprom.capa, CAPA_LORA)) { attr_group_lora = &mtcap_0_0_lora_attribute_group; } @@ -983,12 +996,12 @@ mts_id_eeprom_load(void) log_info("capa-adc: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_ADC) ? "yes" : "no"); log_info("capa-wifi: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_WIFI) ? "yes" : "no"); log_info("capa-bluetooth: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_BLUETOOTH) ? "yes" : "no"); - if (!(mts_hw_version != HW_VERSION_MTCPM_0_0)) /* Moved to mtcdt3b driver in MTCDT3 baseboard hardware */ - log_info("capa-lora: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_LORA) ? "yes" : "no"); - log_info("capa-battery: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_BATTERY) ? "yes" : "no"); + if (!(mts_hw_version != MTCPM_0_0)) /* Moved to mtcdt3b driver in MTCDT3 baseboard hardware */ + log_info("capa-lora: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_LORA) ? "yes" : "no"); + log_info("capa-battery: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_BATTERY) ? "yes" : "no"); log_info("capa-supercap: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_SUPERCAP) ? "yes" : "no"); - if(has_cellular_capaflag) - log_info("capa-cellular: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_CELLULAR) ? "yes" : "no"); + if(has_cellular_capaflag) + log_info("capa-cellular: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_CELLULAR) ? "yes" : "no"); if (DEVICE_CAPA(id_eeprom.capa, CAPA_BLUETOOTH)) { log_info("mac-bluetooth: %02X:%02X:%02X:%02X:%02X:%02X", diff --git a/io-module/mts_io_module.h b/io-module/mts_io_module.h index 14a5592..6863150 100644 --- a/io-module/mts_io_module.h +++ b/io-module/mts_io_module.h @@ -5,7 +5,7 @@ * MTAC cards. */ -#define DRIVER_VERSION "v4.4.1" +#define DRIVER_VERSION "v4.4.2" #define DRIVER_AUTHOR "Multitech Systems" #define DRIVER_DESC "MTS-IO Controller" #define DRIVER_NAME "mts-io" -- cgit v1.2.3