diff options
-rw-r--r-- | io-module/mts-io.c | 94 | ||||
-rw-r--r-- | io-module/version.h | 2 |
2 files changed, 60 insertions, 36 deletions
diff --git a/io-module/mts-io.c b/io-module/mts-io.c index d65c7ea..ca7fdcb 100644 --- a/io-module/mts-io.c +++ b/io-module/mts-io.c @@ -715,6 +715,26 @@ static int get_radio_model_from_product_id(void) { struct attribute **freelater = NULL; // Storage to free when driver is unloaded. struct attribute **lora_freelater = NULL; // Lora storage to free when driver is unloaded. +/* input: version_string - string to match the EEPROM version + * input: hw_enum - Enum value that matches version_string + * output: found_string - version string if matches, otherwise NULL + * output: found_hw - hw_enum if found or MTHWUNKNOWN + * output: return value - hw_enum if found or MTHWUNKNOWN + */ +int +found_board(char *version_string, uint8_t hw_enum, char **found_string, uint8_t *found_hw) +{ + if (strncmp(id_eeprom.hw_version, version_string, strlen(version_string)) == 0) { + *found_hw = hw_enum; + *found_string = version_string; + return hw_enum; + } else { + *found_hw = MTHWUNKNOWN; + *found_string = NULL; + return MTHWUNKNOWN; + } +} + static int mts_id_eeprom_load(void) { @@ -729,7 +749,7 @@ mts_id_eeprom_load(void) int current_lora_blength; // Current length in bytes of attribute lora array int current_lora_count; // Number of items in lora array struct attribute **all_lora_attrs = NULL; - char *tmp; + char *hw_version_str; int noradio = 0; // MTCPM-0.0 does not trim off radio-reset, etc. int has_cellular_capaflag = 0; int need_append; @@ -765,10 +785,10 @@ mts_id_eeprom_load(void) log_debug("mts_id_eeprom_load: noradio=%d",noradio); } - if (((tmp=HW_VERSION_MTCAP_0_0),(mts_hw_version=MTCAP_0_0),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) || - ((tmp=HW_VERSION_MTCAP_0_1),(mts_hw_version=MTCAP_0_1),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) || - ((tmp=HW_VERSION_MTCAP_0_2),(mts_hw_version=MTCAP_0_2),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) || - ((tmp=HW_VERSION_MTCAP_0_3),(mts_hw_version=MTCAP_0_3),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0)) { + if (found_board(HW_VERSION_MTCAP_0_0,MTCAP_0_0,&hw_version_str,&mts_hw_version) || + found_board(HW_VERSION_MTCAP_0_1,MTCAP_0_1,&hw_version_str,&mts_hw_version) || + found_board(HW_VERSION_MTCAP_0_2,MTCAP_0_2,&hw_version_str,&mts_hw_version) || + found_board(HW_VERSION_MTCAP_0_3,MTCAP_0_3,&hw_version_str,&mts_hw_version)) { int need_radio_enable = 0; need_append = 0; current_blength = attr_blength = sizeof mtcap_0_0_platform_attributes; @@ -803,8 +823,7 @@ mts_id_eeprom_load(void) attr_blength += sizeof mtcap_0_0_wifi_attributes; need_append = 1; } - 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)) { + if ((mts_hw_version == MTCAP_0_2) || (mts_hw_version == MTCAP_0_3)) { need_radio_enable = 1; need_append = 1; attr_blength += sizeof mtcap_0_2_enable_radio_attribute; @@ -844,8 +863,8 @@ mts_id_eeprom_load(void) if (DEVICE_CAPA(id_eeprom.capa, CAPA_LORA)) { attr_group_lora = &mtcap_0_0_lora_attribute_group; } - log_info("detected board %s", tmp); - } else if ((tmp=HW_VERSION_MTCAP3_0_0),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) { + log_info("detected board %s", hw_version_str); + } else if (found_board(HW_VERSION_MTCAP3_0_0,MTCAP3_0_0,&hw_version_str,&mts_hw_version)) { current_blength = attr_blength = sizeof mtcap3_0_0_platform_attributes; current_blength -= sizeof(struct attribute *); /* Length without terminating NULL */ @@ -898,70 +917,70 @@ mts_id_eeprom_load(void) set_buttons(default_buttons); mts_hw_version = MTCAP3_0_0; log_info("detected board %s", HW_VERSION_MTCAP3_0_0); - } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTRE, strlen(HW_VERSION_MTRE)) == 0) { + } else if (found_board(HW_VERSION_MTRE,MTRE_0_0,&hw_version_str,&mts_hw_version)) { attr_group = &mtre_0_0_platform_attribute_group; gpio_pins = gpio_pins_mtre_0_0; set_buttons(default_buttons); mts_leds = mtre_0_0_leds; mts_hw_version = MTRE_0_0; log_info("detected board %s", HW_VERSION_MTRE); - } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTR_0_0, strlen(HW_VERSION_MTR_0_0)) == 0) { + } else if (found_board(HW_VERSION_MTR_0_0,MTR_0_0,&hw_version_str,&mts_hw_version)) { attr_group = &mtr_platform_attribute_group; gpio_pins = gpio_pins_mtr_0_0; set_buttons(default_buttons); 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) { + } else if (found_board(HW_VERSION_MTR_0_1,MTR_0_1,&hw_version_str,&mts_hw_version)) { attr_group = &mtr_platform_attribute_group; gpio_pins = gpio_pins_mtr_0_1; set_buttons(default_buttons); 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) { + } else if (found_board(HW_VERSION_MTRV1_0_0,MTRV1_0_0,&hw_version_str,&mts_hw_version)) { attr_group = &mtr_platform_attribute_group; gpio_pins = gpio_pins_mtrv1_0_0; set_buttons(default_buttons); 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) { + } else if (found_board(HW_VERSION_MTRV1_0_1,MTRV1_0_1,&hw_version_str,&mts_hw_version)) { attr_group = &mtrv1_0_1_platform_attribute_group; gpio_pins = gpio_pins_mtrv1_0_1; set_buttons(default_buttons); mts_hw_version = MTRV1_0_1; log_info("detected board %s", HW_VERSION_MTRV1_0_1); - } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTRV1_0_2, strlen(HW_VERSION_MTRV1_0_2)) == 0) { + } else if (found_board(HW_VERSION_MTRV1_0_2,MTRV1_0_2,&hw_version_str,&mts_hw_version)) { attr_group = &mtrv1_0_2_platform_attribute_group; gpio_pins = gpio_pins_mtrv1_0_2; set_buttons(default_buttons); mts_hw_version = MTRV1_0_2; log_info("detected board %s", HW_VERSION_MTRV1_0_2); - } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTRV1_0_3, strlen(HW_VERSION_MTRV1_0_3)) == 0) { + } else if (found_board(HW_VERSION_MTRV1_0_3,MTRV1_0_3,&hw_version_str,&mts_hw_version)) { attr_group = &mtrv1_0_3_platform_attribute_group; gpio_pins = gpio_pins_mtrv1_0_3; set_buttons(default_buttons); mts_hw_version = MTRV1_0_3; log_info("detected board %s", HW_VERSION_MTRV1_0_3); - } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTRV1_0_4, strlen(HW_VERSION_MTRV1_0_4)) == 0) { + } else if (found_board(HW_VERSION_MTRV1_0_4,MTRV1_0_4,&hw_version_str,&mts_hw_version)) { attr_group = &mtrv1_0_4_platform_attribute_group; gpio_pins = gpio_pins_mtrv1_0_4; set_buttons(default_buttons); mts_hw_version = MTRV1_0_4; mtr_setup_radio_status(id_eeprom.product_id); log_info("detected board %s", HW_VERSION_MTRV1_0_4); - } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTHS_0_0, strlen(HW_VERSION_MTHS_0_0)) == 0) { + } else if (found_board(HW_VERSION_MTHS_0_0,MTHS_0_0,&hw_version_str,&mts_hw_version)) { attr_group = &mths_0_0_platform_attribute_group; gpio_pins = gpio_pins_mths_0_0; set_buttons(mths_buttons_0_0); mts_hw_version = MTHS_0_0; log_info("detected board %s", HW_VERSION_MTHS_0_0); - } else if (strncmp(id_eeprom.hw_version, HW_VERSION_MTHS_0_1, strlen(HW_VERSION_MTHS_0_1)) == 0) { + } else if (found_board(HW_VERSION_MTHS_0_1,MTHS_0_1,&hw_version_str,&mts_hw_version)) { attr_group = &mths_0_0_platform_attribute_group; gpio_pins = gpio_pins_mths_0_1; set_buttons(mths_buttons_0_0); /* Only one button version */ mts_hw_version = MTHS_0_1; log_info("detected board %s", HW_VERSION_MTHS_0_1); - } else if (((tmp=HW_VERSION_MTCDT_0_1),(mts_hw_version=MTCDT_0_1),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) || - ((tmp=HW_VERSION_MTCDTIP_0_0),(mts_hw_version=MTCDTIP_0_0),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0)) { + } else if (found_board(HW_VERSION_MTCDT_0_1,MTCDT_0_1,&hw_version_str,&mts_hw_version) || + found_board(HW_VERSION_MTCDTIP_0_0,MTCDTIP_0_0,&hw_version_str,&mts_hw_version)) { need_append = 0; current_blength = attr_blength = sizeof mtcdt_0_1_platform_attributes; current_blength -= sizeof(struct attribute *); /* Length without terminating NULL */ @@ -1015,9 +1034,9 @@ mts_id_eeprom_load(void) attr_group = &mtcdt_0_1_platform_attribute_group; gpio_pins = gpio_pins_mtcdt_0_1; set_buttons(default_buttons); - log_info("detected board %s", tmp); - } else if (((tmp=HW_VERSION_MTCDT_0_2),(mts_hw_version=MTCDT_0_2),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) || - ((tmp=HW_VERSION_MTCDTIP_0_1),(mts_hw_version=MTCDTIP_0_1),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0)) { + log_info("detected board %s", hw_version_str); + } else if (found_board(HW_VERSION_MTCDT_0_2,MTCDT_0_2,&hw_version_str,&mts_hw_version) || + found_board(HW_VERSION_MTCDTIP_0_1,MTCDTIP_0_1,&hw_version_str,&mts_hw_version)) { need_append = 0; current_blength = attr_blength = sizeof mtcdt_0_2_platform_attributes; current_blength -= sizeof(struct attribute *); /* Length without terminating NULL */ @@ -1071,8 +1090,8 @@ mts_id_eeprom_load(void) attr_group = &mtcdt_0_2_platform_attribute_group; gpio_pins = gpio_pins_mtcdt_0_2; set_buttons(default_buttons); - log_info("detected board %s", tmp); - } else if ((tmp=HW_VERSION_MTCDTIPHP_0_0),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) { + log_info("detected board %s", hw_version_str); + } else if (found_board(HW_VERSION_MTCDTIPHP_0_0,MTCDTIPHP_0_0,&hw_version_str,&mts_hw_version)) { need_append = 0; current_blength = attr_blength = sizeof mtcdt_0_1_platform_attributes; current_blength -= sizeof(struct attribute *); /* Length without terminating NULL */ @@ -1121,8 +1140,8 @@ mts_id_eeprom_load(void) } set_buttons(default_buttons); mts_hw_version = MTCDTIPHP_0_0; - log_info("detected board %s", tmp); - } else if ((tmp=HW_VERSION_MTCDT_0_0),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) { + log_info("detected board %s", hw_version_str); + } else if (found_board(HW_VERSION_MTCDT_0_0,MTCDT_0_0,&hw_version_str,&mts_hw_version)) { if(noradio) { struct attribute **ap = mtcdt_platform_attribute_group.attrs; while(1) { @@ -1143,9 +1162,9 @@ mts_id_eeprom_load(void) gpio_pins = gpio_pins_mtcdt_0_0; mts_hw_version = MTCDT_0_0; set_buttons(default_buttons); - log_info("detected board %s", tmp); - } else if (((tmp=HW_VERSION_MTCPM_0_0),(mts_hw_version=MTCPM_0_0),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) || - ((tmp=HW_VERSION_MTCPM_0_1),(mts_hw_version=MTCPM_0_1),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0)) { + log_info("detected board %s", hw_version_str); + } else if (found_board(HW_VERSION_MTCPM_0_0,MTCPM_0_0,&hw_version_str,&mts_hw_version) || + found_board(HW_VERSION_MTCPM_0_1,MTCPM_0_1,&hw_version_str,&mts_hw_version)) { need_append = 0; current_blength = attr_blength = sizeof mtcpm_platform_attributes; current_blength -= sizeof(struct attribute *); /* Length without terminating NULL */ @@ -1168,7 +1187,7 @@ mts_id_eeprom_load(void) } } } - if (tmp != HW_VERSION_MTCPM_0_0) { + if (hw_version_str != HW_VERSION_MTCPM_0_0) { attr_blength += sizeof mtcpm_has_radio_attribute; need_append = 1; } @@ -1184,7 +1203,7 @@ mts_id_eeprom_load(void) freelater = all_attrs = kmalloc(attr_blength,GFP_KERNEL); current_count = current_blength/(sizeof (struct attribute *)); memcpy(all_attrs,mtcpm_platform_attributes,current_blength); - if(tmp != HW_VERSION_MTCPM_0_0) { + if(hw_version_str != HW_VERSION_MTCPM_0_0) { log_info("Adding has_radio to mts-io driver"); memcpy(all_attrs + current_count,mtcpm_has_radio_attribute,sizeof mtcpm_has_radio_attribute); current_count += sizeof mtcpm_has_radio_attribute / (sizeof (struct attribute *)); @@ -1208,8 +1227,8 @@ mts_id_eeprom_load(void) attr_group = &mtcpm_platform_attribute_group; gpio_pins = gpio_pins_mtcpm; set_buttons(default_buttons); - log_info("detected board %s", tmp); - } else if (strncmp(id_eeprom.product_id, PRODUCT_ID_MT100EOCG, strlen(PRODUCT_ID_MT100EOCG)) == 0) { + log_info("detected board %s", hw_version_str); + } else if (found_board(HW_VERSION_MT100EOCG_0_0,MT100EOCG_0_0,&hw_version_str,&mts_hw_version)) { attr_group = &mt100eocg_platform_attribute_group; gpio_pins = gpio_pins_mt100eocg_0_0; mts_hw_version = MT100EOCG_0_0; @@ -1364,6 +1383,11 @@ static int __init mts_io_init(void) /* request_firmware() requires a device, so call after device allocated */ ret = mts_id_eeprom_load(); + if (ret != 0) { + cleanup(); + return ret; + } + if (DEVICE_CAPA(id_eeprom.capa, CAPA_DOUT)) { ret = spi_register_driver(&mts_spi_dout_driver); diff --git a/io-module/version.h b/io-module/version.h index b72c4b0..e61e6ed 100644 --- a/io-module/version.h +++ b/io-module/version.h @@ -1,7 +1,7 @@ #ifndef __VERSION_H #define __VERSION_H -#define DRIVER_VERSION "v4.9.1" +#define DRIVER_VERSION "v4.9.2" #define DRIVER_AUTHOR "Multitech Systems" #define DRIVER_DESC "MTS-IO Controller" #define DRIVER_NAME "mts-io" |