From 24297c1295873ecdb729903aa2f53fe0ec1203d5 Mon Sep 17 00:00:00 2001 From: John Klug Date: Fri, 20 Apr 2018 15:26:43 -0500 Subject: Add has-radio flag to mts-io, and remove compiler warnings --- io-module/mts_io.c | 205 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 180 insertions(+), 25 deletions(-) (limited to 'io-module/mts_io.c') diff --git a/io-module/mts_io.c b/io-module/mts_io.c index fba83de..abac4bb 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -47,7 +47,7 @@ #include "mts_io.h" -#define DRIVER_VERSION "v2.0.0" +#define DRIVER_VERSION "v2.0.1" #define DRIVER_AUTHOR "James Maki " #define DRIVER_DESC "MTS-IO Controller" #define DRIVER_NAME "mts-io" @@ -116,6 +116,62 @@ static void reset_callback(struct work_struct *ignored); static DECLARE_DELAYED_WORK(reset_work, reset_callback); +/* + * This function takes the product_id and tries to check + * for a modem. If there is an error, assume there is a + * modem. Saying there is a modem when there is not + * just results in a slower boot. + * If no hyphen in product ID, or no product ID, + * assume we have a radio. + * If there is a hyphen test the character after the + * first hyphen: + * If the character is numeric, we have no modem. + * if the chracter is not a B, we have a modem. + * If the character is a B, and it is followed + * by a numeric, we have no modem. + * If the B is the last character or is followed + * by a numeric, we have no modem. + * All other cases, we have a modem. + */ +static int +has_radio(const char *product_id, size_t len) +{ + char *p; + if (!product_id || ! *product_id) + return 1; /* No Product ID? */ + p = memchr(product_id,'-',len); + if (p) { /* Found a hyphen */ + log_debug("Found hyphen"); + p++; + if (p >= product_id+len) { + log_debug("End of string -- hyphen"); + return 1; /* Last character was hyphen */ + } + if (isdigit(*p)) { + log_debug("Found digit after hypen"); + return 0; /* Modem name never starts with a digit */ + } + if (*p != 'B') { + log_debug("Found neither B nor digit after hypen"); + return 1; /* Modem starting with a letter, but not B */ + } + /* Found a B */ + p++; + if (p >= product_id+len) { + log_debug("B at end of product-id string"); + return 1; /* Last character was B */ + } + if (isdigit(*p)) { + log_debug("B followed by digit after hyphen - no modem"); + return 0; /* B[numeric] is MTR Build number */ + } + log_debug("B followed by non-digit after hyphen - has modem"); + return 1; /* B[non-numeric] so assume a modem that starts with B */ + } /* End of found hyphen case */ + log_debug("Undefined product-id - has modem"); + return 1; /* Product id invalid or empty, so instantiate a radio anyway */ +} + static void reset_callback(struct work_struct *ignored) { struct gpio_pin *pin; @@ -173,7 +229,7 @@ static ssize_t mts_attr_show_reset_monitor_intervals(struct device *dev, struct return ret; } -static ssize_t mts_attr_store_reset_monitor_intervals(struct device *dev, struct device_attribute *attr, char *buf, size_t count) +static ssize_t mts_attr_store_reset_monitor_intervals(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int short_int; int long_int; @@ -571,6 +627,9 @@ static ssize_t mts_attr_show_product_info(struct device *dev, value = sprintf(buf, "%.32s\n", id_eeprom.vendor_id); } else if (strcmp(attr->attr.name, "product-id") == 0) { value = sprintf(buf, "%.32s\n", id_eeprom.product_id); + } else if (strcmp(attr->attr.name, "has-radio") == 0) { + value = sprintf(buf, "%1d\n", + has_radio(id_eeprom.product_id,sizeof id_eeprom.product_id)); } else if (strcmp(attr->attr.name, "device-id") == 0) { value = sprintf(buf, "%.32s\n", id_eeprom.device_id); } else if (strcmp(attr->attr.name, "uuid") == 0) { @@ -631,6 +690,8 @@ static DEVICE_ATTR_RO_MTS(dev_attr_vendor_id, "vendor-id", mts_attr_show_product_info); static DEVICE_ATTR_RO_MTS(dev_attr_product_id, "product-id", mts_attr_show_product_info); +static DEVICE_ATTR_RO_MTS(dev_attr_has_radio, "has-radio", + mts_attr_show_product_info); static DEVICE_ATTR_RO_MTS(dev_attr_device_id, "device-id", mts_attr_show_product_info); static DEVICE_ATTR_RO_MTS(dev_attr_uuid, "uuid", @@ -642,7 +703,7 @@ static DEVICE_ATTR_RO_MTS(dev_attr_imei, "imei", static DEVICE_ATTR_RO_MTS(dev_attr_eth_mac, "mac-eth", mts_attr_show_product_info); -static int get_radio_model_from_product_id() { +static int get_radio_model_from_product_id(void) { int rc = RADIO_UNKNOWN; if (strstr(id_eeprom.product_id, "LEU1")) rc = RADIO_LEU1; @@ -825,21 +886,25 @@ mts_id_eeprom_load(void) int current_count; // Number of items in array struct attribute **all_attrs = NULL; char *tmp; + int noradio; //The mts_id_eeprom buffer is initialize once on boot //reloading the mts_io.ko module will not reinitialize this buffer //only rebooting will reinitialize this buffer memcpy(&id_eeprom, mts_id_eeprom, sizeof(mts_id_eeprom)); - if (mts_id_eeprom[0] == 0xFF) { - log_error("uninitialized eeprom"); - return -EIO; - } else if (((tmp=HW_VERSION_MTCAP_0_0),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) || + if (mts_id_eeprom[0] == 0xFF) { + log_error("uninitialized eeprom"); + return -EIO; + } + + noradio = ! has_radio(id_eeprom.product_id,sizeof id_eeprom.product_id); + log_debug("mts_id_eeprom: noradio=%d",noradio); + + if (((tmp=HW_VERSION_MTCAP_0_0),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) || ((tmp=HW_VERSION_MTCAP_0_1),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0)) { /* See if we have no radio, and if so, prune out the stuff that follows */ - if((strncmp(id_eeprom.product_id, PRODUCT_ID_MTCAP, sizeof PRODUCT_ID_MTCAP - 1) == 0) && - (id_eeprom.product_id[sizeof PRODUCT_ID_MTCAP-1] == '-') && - isdigit(id_eeprom.product_id[sizeof PRODUCT_ID_MTCAP])) { + if(noradio) { struct attribute **ap = mtcap_0_0_platform_attribute_group.attrs; while(1) { if(ap[j] == NULL) { @@ -847,7 +912,7 @@ mts_id_eeprom_load(void) break; } j++; - if (is_radio_power_attr(ap[j])) { + if (is_radio_power_attr_mtcap(ap[j])) { log_info("Pruning radio feature from mts-io",j); ap[j] = NULL; break; @@ -861,21 +926,117 @@ mts_id_eeprom_load(void) } log_info("detected board %s", tmp); } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTR_0_0, strlen(HW_VERSION_MTR_0_0)) == 0) { + if(noradio) { + struct attribute **ap = mtcap_0_0_platform_attribute_group.attrs; + while(1) { + if(ap[j] == NULL) { + log_info("Did not find radio power attribute. Possible driver fault."); + break; + } + j++; + if (is_radio_power_attr_mtr(ap[j])) { + log_info("Pruning radio feature from mts-io",j); + ap[j] = NULL; + break; + } + } + } + attr_group = &mtr_platform_attribute_group; gpio_pins = gpio_pins_mtr_0_0; mts_hw_version = MTR_0_0; log_info("detected board %s", HW_VERSION_MTR_0_0); } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTR_0_1, strlen(HW_VERSION_MTR_0_1)) == 0) { + if(noradio) { + struct attribute **ap = mtr_platform_attribute_group.attrs; + while(1) { + if(ap[j] == NULL) { + log_info("Did not find radio power attribute. Possible driver fault."); + break; + } + j++; + if (is_radio_power_attr_mtr(ap[j])) { + log_info("Pruning radio feature from mts-io",j); + ap[j] = NULL; + break; + } + } + } + attr_group = &mtr_platform_attribute_group; gpio_pins = gpio_pins_mtr_0_1; mts_hw_version = MTR_0_1; log_info("detected board %s", HW_VERSION_MTR_0_1); } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTRV1_0_0, strlen(HW_VERSION_MTRV1_0_0)) == 0) { - attr_group = &mtr_platform_attribute_group; - gpio_pins = gpio_pins_mtrv1_0_0; - mts_hw_version = MTRV1_0_0; - log_info("detected board %s", HW_VERSION_MTRV1_0_0); + if(noradio) { + struct attribute **ap = mtr_platform_attribute_group.attrs; + while(1) { + if(ap[j] == NULL) { + log_info("Did not find radio power attribute. Possible driver fault."); + break; + } + j++; + if (is_radio_power_attr_mtr(ap[j])) { + log_info("Pruning radio feature from mts-io",j); + ap[j] = NULL; + break; + } + } + } + + attr_group = &mtr_platform_attribute_group; + gpio_pins = gpio_pins_mtrv1_0_0; + mts_hw_version = MTRV1_0_0; + log_info("detected board %s", HW_VERSION_MTRV1_0_0); } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTRV1_0_1, strlen(HW_VERSION_MTRV1_0_1)) == 0) { + current_blength = attr_blength = sizeof mtrv1_0_1_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 = mtrv1_0_1_platform_attribute_group.attrs; + while(1) { + if(ap[j] == NULL) { + log_info("Did not find radio power attribute. Possible driver fault."); + break; + } + j++; + if (is_radio_power_attr_mtr(ap[j])) { + log_info("Pruning radio feature from mts-io",j); + ap[j] = NULL; + current_blength = attr_blength = j * sizeof (ap[j]); + break; + } + } + } + + /* mtcdt gnss and wifi for future devices. We assume the same + * pinout as mtcdt on MTR. */ + if(DEVICE_CAPA(id_eeprom.capa, CAPA_WIFI)) { + attr_blength += sizeof mtcdt_0_1_wifi_bt_attributes; + } + if(DEVICE_CAPA(id_eeprom.capa, CAPA_GPS)) { + attr_blength += sizeof mtcdt_0_1_gnss_attributes; + } + if (current_blength+(sizeof(struct attribute *)) != attr_blength) { + freelater = all_attrs = kmalloc(attr_blength,GFP_KERNEL); + current_count = current_blength/(sizeof (struct attribute *)); + memcpy(all_attrs,mtrv1_0_1_platform_attributes,current_blength); + if(DEVICE_CAPA(id_eeprom.capa, CAPA_WIFI)) { + log_info("Adding WiFi/BT to mts-io driver"); + memcpy(all_attrs + current_count,mtcdt_0_1_wifi_bt_attributes,sizeof mtcdt_0_1_wifi_bt_attributes); + current_count += sizeof mtcdt_0_1_wifi_bt_attributes / (sizeof (struct attribute *)); + } + if(DEVICE_CAPA(id_eeprom.capa, CAPA_GPS)) { + log_info("Adding GPS to mts-io driver"); + attr_blength += sizeof mtcdt_0_1_gnss_attributes; + memcpy(all_attrs + current_count,mtcdt_0_1_gnss_attributes,sizeof mtcdt_0_1_gnss_attributes); + current_count += sizeof mtcdt_0_1_gnss_attributes / (sizeof (struct attribute *)); + } + all_attrs[current_count] = (struct attribute *)NULL; + mtrv1_0_1_platform_attribute_group.attrs = all_attrs; + } + attr_group = &mtrv1_0_1_platform_attribute_group; gpio_pins = gpio_pins_mtrv1_0_1; mts_hw_version = MTRV1_0_1; @@ -886,9 +1047,7 @@ mts_id_eeprom_load(void) 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((strncmp(id_eeprom.product_id, PRODUCT_ID_MTCDT, sizeof PRODUCT_ID_MTCDT - 1) == 0) && - (id_eeprom.product_id[sizeof PRODUCT_ID_MTCDT-1] == '-') && - isdigit(id_eeprom.product_id[sizeof PRODUCT_ID_MTCDT])) { + if(noradio) { struct attribute **ap = mtcdt_0_1_platform_attribute_group.attrs; while(1) { if(ap[j] == NULL) { @@ -938,9 +1097,7 @@ mts_id_eeprom_load(void) 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((strncmp(id_eeprom.product_id, PRODUCT_ID_MTCDTIPHP, sizeof PRODUCT_ID_MTCDTIPHP - 1) == 0) && - (id_eeprom.product_id[sizeof PRODUCT_ID_MTCDTIPHP-1] == '-') && - isdigit(id_eeprom.product_id[sizeof PRODUCT_ID_MTCDTIPHP])) { + if(noradio) { struct attribute **ap = mtcdt_0_1_platform_attribute_group.attrs; while(1) { if(ap[j] == NULL) { @@ -981,10 +1138,8 @@ mts_id_eeprom_load(void) } log_info("detected board %s", tmp); } else { - if((strncmp(id_eeprom.product_id, PRODUCT_ID_MTCDT, sizeof PRODUCT_ID_MTCDT - 1) == 0) && - (id_eeprom.product_id[sizeof PRODUCT_ID_MTCDT-1] == '-') && - isdigit(id_eeprom.product_id[sizeof PRODUCT_ID_MTCDT])) { - struct attribute **ap = mtcdt_0_1_platform_attribute_group.attrs; + if(noradio) { + struct attribute **ap = mtcdt_platform_attribute_group.attrs; while(1) { if(ap[j] == NULL) { log_info("Did not find radio power attribute. Possible driver fault."); -- cgit v1.2.3