diff options
author | John Klug <john.klug@multitech.com> | 2020-02-25 17:55:49 -0600 |
---|---|---|
committer | John Klug <john.klug@multitech.com> | 2020-02-25 17:55:49 -0600 |
commit | 62f1d67abe1f4e79542c3cca683b40beb2eeda02 (patch) | |
tree | 554b675f8a972c73961dd615bd50093d8cd9a9f7 /io-module/mts-io.c | |
parent | 0a4a5f96dd649a5c5e18d43d7bd206f35845e1cb (diff) | |
download | mts-io-62f1d67abe1f4e79542c3cca683b40beb2eeda02.tar.gz mts-io-62f1d67abe1f4e79542c3cca683b40beb2eeda02.tar.bz2 mts-io-62f1d67abe1f4e79542c3cca683b40beb2eeda02.zip |
mts-io based on thud/4.19 kernel for mt100eocg4.3.1
Diffstat (limited to 'io-module/mts-io.c')
-rw-r--r-- | io-module/mts-io.c | 118 |
1 files changed, 82 insertions, 36 deletions
diff --git a/io-module/mts-io.c b/io-module/mts-io.c index 154d120..7c8a873 100644 --- a/io-module/mts-io.c +++ b/io-module/mts-io.c @@ -3,10 +3,8 @@ * * Copyright (C) 2014 by Multi-Tech Systems * Copyright (C) 2016 by Multi-Tech Systems - * - * Authors: James Maki <jmaki@multitech.com> - * Jesse Gilles <jgilles@multitech.com> - * Mike Fiore <mfiore@multitech.com> + * Copyright (C) 2019 by Multi-Tech Systems + * Copyright (C) 2020 by Multi-Tech Systems * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -38,7 +36,6 @@ #include <linux/platform_device.h> #include <linux/device.h> #include <linux/bitops.h> -#include <linux/spi/spi.h> #include <linux/kmod.h> #include <linux/ctype.h> #include <linux/io.h> @@ -168,8 +165,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) @@ -206,6 +203,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, @@ -531,7 +529,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) { @@ -561,7 +559,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], @@ -620,11 +626,13 @@ 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 "mt100eocg.c" +#include "machine/mtcdt.c" +#include "machine/mtcap.c" +#include "machine/mtr.c" +#include "machine/mths.c" +#include "machine/mtcpm.c" +#include "machine/mt100eocg.c" + /* include capabilities sub-directory support */ #include "mts_capab.c" @@ -652,18 +660,24 @@ 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)) { + ((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)) { /* 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; @@ -785,7 +799,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; @@ -831,15 +845,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 if (strncmp(id_eeprom.product_id, PRODUCT_ID_MT100EOCG, strlen(PRODUCT_ID_MT100EOCG)) == 0) { - attr_group = &mt100eocg_platform_attribute_group; - gpio_pins = gpio_pins_mt100eocg_0_0; - mts_hw_version = MT100EOCG_0_0; - set_buttons(default_buttons); - log_info("detected board %s", HW_VERSION_MT100EOCG_0_0); - } 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) { @@ -859,9 +867,41 @@ 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", 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); + mts_hw_version = MTCPM_0_0; + log_info("detected board %s", HW_VERSION_MTCPM_0_0); + } else if (strncmp(id_eeprom.product_id, PRODUCT_ID_MT100EOCG, strlen(PRODUCT_ID_MT100EOCG)) == 0) { + attr_group = &mt100eocg_platform_attribute_group; + gpio_pins = gpio_pins_mt100eocg_0_0; + mts_hw_version = MT100EOCG_0_0; + set_buttons(default_buttons); + log_info("detected board %s", HW_VERSION_MT100EOCG_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); @@ -883,7 +923,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"); + 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", @@ -940,6 +983,7 @@ static void cleanup(void) } mts_capab_dir_delete(); + mts_cpu_dir_delete(); } static int __init mts_io_init(void) @@ -963,21 +1007,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; } @@ -1002,7 +1044,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; @@ -1021,6 +1063,10 @@ 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(); |