diff options
Diffstat (limited to 'io-module/mts-io.c')
-rw-r--r-- | io-module/mts-io.c | 109 |
1 files changed, 82 insertions, 27 deletions
diff --git a/io-module/mts-io.c b/io-module/mts-io.c index 954da63..73d6376 100644 --- a/io-module/mts-io.c +++ b/io-module/mts-io.c @@ -125,9 +125,6 @@ static volatile int radio_reset_timer_is_start = 0; static struct timer_list radio_reset_available_timer; static volatile int radio_reset_available_timer_is_start = 0; static time_t time_now_secs(void); -static void radio_reset_available_timer_callback(unsigned long data); -static void radio_reset_timer_callback(unsigned long data); - /* generic GPIO support */ #include "gpio.c" @@ -159,8 +156,8 @@ bool sent_extra_long = false; * 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) +int +mts_has_radio(const char *product_id, size_t len) { char *p; if (!product_id || ! *product_id) @@ -197,6 +194,7 @@ has_radio(const char *product_id, size_t len) log_debug("Undefined product-id - has modem"); return 1; /* Product id invalid or empty, so instantiate a radio anyway */ } +EXPORT_SYMBOL(mts_has_radio); /* active-low socket modem reset */ static ssize_t mts_attr_store_radio_reset(struct device *dev, @@ -271,7 +269,11 @@ static time_t time_now_secs(void) return ts.tv_sec; } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0) +static void radio_reset_available_timer_callback( struct timer_list *data ) +#else static void radio_reset_available_timer_callback( unsigned long data ) +#endif { /* do your timer stuff here */ //log_info("radio_reset_available_timer_callback\n"); @@ -283,7 +285,11 @@ static void radio_reset_available_timer_callback( unsigned long data ) radio_reset_available_timer_is_start = 0; } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0) +static void radio_reset_timer_callback( struct timer_list *data ) +#else static void radio_reset_timer_callback( unsigned long data ) +#endif { /* do your timer stuff here */ //log_info("radio_reset_timer_callback\n"); @@ -514,7 +520,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) { value = sprintf(buf, "%1d\n", - has_radio(id_eeprom.product_id,sizeof id_eeprom.product_id)); + mts_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) { @@ -544,7 +550,15 @@ static ssize_t mts_attr_show_product_info(struct device *dev, id_eeprom.mac_wifi[3], id_eeprom.mac_wifi[4], id_eeprom.mac_wifi[5]); - } else if (strcmp(attr->attr.name, "mac-eth") == 0) { + } else if (strcmp(attr->attr.name, "mac-bluetooth") == 0) { + value = sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X\n", + id_eeprom.mac_bluetooth[0], + id_eeprom.mac_bluetooth[1], + id_eeprom.mac_bluetooth[2], + id_eeprom.mac_bluetooth[3], + id_eeprom.mac_bluetooth[4], + id_eeprom.mac_bluetooth[5]); + } else if (strcmp(attr->attr.name, "mac-eth") == 0) { value = sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X\n", id_eeprom.mac_addr[0], id_eeprom.mac_addr[1], @@ -603,10 +617,11 @@ static int get_radio_model_from_product_id(void) { #include "mts_lora.c" /* include per-device pins and attributes */ -#include "mtcdt.c" -#include "mtcap.c" -#include "mtr.c" -#include "mths.c" +#include "machine/mtcdt.c" +#include "machine/mtcap.c" +#include "machine/mtr.c" +#include "machine/mths.c" +#include "machine/mtcpm.c" /* include capabilities sub-directory support */ #include "mts_capab.c" @@ -635,15 +650,20 @@ mts_id_eeprom_load(void) log_info("Platform EEPROM contents loaded"); } else { log_error("Invalid platform EEPROM length (%d)", fw->size); + return -EINVAL; } release_firmware(fw); } else { log_error("Unable to load EEPROM contents (%d)", ret); + return -ENODEV; } - noradio = ! has_radio(id_eeprom.product_id,sizeof id_eeprom.product_id); - log_debug("mts_id_eeprom: noradio=%d",noradio); + // If we are an MTCPM, the base board sets the radio existance. + if (strncmp(id_eeprom.hw_version,HW_VERSION_MTCPM_DASH,sizeof HW_VERSION_MTCPM_DASH) != 0) { + noradio = ! mts_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) || @@ -769,7 +789,7 @@ mts_id_eeprom_load(void) attr_group = &mtcdt_0_1_platform_attribute_group; gpio_pins = gpio_pins_mtcdt_0_1; - set_buttons(default_buttons); + 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) { current_blength = attr_blength = sizeof mtcdt_0_1_platform_attributes; @@ -815,9 +835,9 @@ mts_id_eeprom_load(void) if (DEVICE_CAPA(id_eeprom.capa, CAPA_LORA)) { attr_group_lora = &mtcdtiphp_0_0_lora_attribute_group; } - set_buttons(default_buttons); + set_buttons(default_buttons); log_info("detected board %s", tmp); - } else { + } else if ((tmp=HW_VERSION_MTCDT_0_0),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) { if(noradio) { struct attribute **ap = mtcdt_platform_attribute_group.attrs; while(1) { @@ -837,9 +857,35 @@ mts_id_eeprom_load(void) attr_group = &mtcdt_platform_attribute_group; 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 (strncmp(id_eeprom.hw_version, HW_VERSION_MTCPM_0_0, strlen(HW_VERSION_MTCPM_0_0)) == 0) { + attr_group = &mtcpm_platform_attribute_group; + gpio_pins = gpio_pins_mtcpm; set_buttons(default_buttons); - log_info("detected board %s", HW_VERSION_MTCDT_0_0); - } + mts_hw_version = MTCPM_0_0; + log_info("detected board %s", HW_VERSION_MTCPM_0_0); + } else { + int i; + + for(i=0;i<sizeof id_eeprom.hw_version;i++) { + if(! id_eeprom.hw_version[i]) + /* Found NULL so done */ + break; + if(! isprint(id_eeprom.hw_version[i])) + break; + } + log_alert("Unsupported EEPROM settings or device"); + + if(i) + log_alert("Found unsupported EEPROM HW_VERSION: %.*s",i,id_eeprom.hw_version); + log_alert("Check log for HW_VERSION dump"); + + print_hex_dump_bytes("HW_VERSION: ", DUMP_PREFIX_OFFSET, id_eeprom.hw_version, sizeof id_eeprom.hw_version); + + return -ENODEV; + } log_info("sizeof: %lu", (unsigned long) sizeof(struct mts_id_eeprom_layout)); log_info("vendor-id: %.32s", id_eeprom.vendor_id); @@ -861,8 +907,10 @@ 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"); - 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 != 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 (DEVICE_CAPA(id_eeprom.capa, CAPA_BLUETOOTH)) { log_info("mac-bluetooth: %02X:%02X:%02X:%02X:%02X:%02X", @@ -919,6 +967,7 @@ static void cleanup(void) } mts_capab_dir_delete(); + mts_cpu_dir_delete(); } static int __init mts_io_init(void) @@ -942,21 +991,19 @@ static int __init mts_io_init(void) platform_driver_unregister(&mts_io_driver); mts_io_platform_device = platform_device_alloc(PLATFORM_NAME, -1); - if (!mts_io_platform_device) { - cleanup(); + if (!mts_io_platform_device) return -ENOMEM; - } /* request_firmware() requires a device, so call after device allocated */ ret = mts_id_eeprom_load(); if (ret) { - cleanup(); + kfree(mts_io_platform_device); return ret; } ret = platform_device_add(mts_io_platform_device); if (ret) { - cleanup(); + kfree(mts_io_platform_device); return ret; } @@ -964,7 +1011,7 @@ static int __init mts_io_init(void) mts_load_lora_port(); } - ret = mts_capab_dir_create(); + ret = mts_capab_dir_create(mts_hw_version); if (ret) { cleanup(); return ret; @@ -983,13 +1030,21 @@ static int __init mts_io_init(void) log_debug("could not request pin %s (%d) but it could have already been requested under a different pin name", pin->name, ret); } } + + // Create CPU directory if approprate (only MTCDT3 for now) + ret = mts_cpu_dir_create(mts_hw_version); + // start general buttons processing init_buttons(); /* init timers */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0) + timer_setup(&radio_reset_timer, radio_reset_timer_callback, 0); + timer_setup(&radio_reset_available_timer, radio_reset_available_timer_callback, 0); +#else setup_timer(&radio_reset_timer, radio_reset_timer_callback, 0); setup_timer(&radio_reset_available_timer, radio_reset_available_timer_callback, 0); - +#endif return 0; } |