diff options
Diffstat (limited to 'io-module/mts-io.c')
-rw-r--r-- | io-module/mts-io.c | 142 |
1 files changed, 74 insertions, 68 deletions
diff --git a/io-module/mts-io.c b/io-module/mts-io.c index d6bd4f2..f224777 100644 --- a/io-module/mts-io.c +++ b/io-module/mts-io.c @@ -20,7 +20,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ -#include <linux/clk.h> + #include <linux/delay.h> #include <linux/ioctl.h> #include <linux/input.h> @@ -71,11 +71,6 @@ static const struct of_device_id mts_io_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, mts_io_dt_ids); -/* on-board EEPROM */ -static struct mts_id_eeprom_layout id_eeprom; - -#include "adc.c" - /* * We must call platform_set_drvdata, or else the * devres_head for the driver has junk in it, and @@ -88,11 +83,7 @@ static struct mts_id_eeprom_layout id_eeprom; */ static int mts_io_probe(struct platform_device *pdev) { - int ret = 0; - if (!DEVICE_CAPA(id_eeprom.capa, CAPA_ADC)) { - ret = mts_io_board_adc_probe(pdev); - } - return ret; + return 0; } static int mts_io_remove(struct platform_device *pdev) @@ -113,6 +104,8 @@ static struct platform_driver mts_io_driver = { }; +/* on-board EEPROM */ +static struct mts_id_eeprom_layout id_eeprom; static uint8_t mts_hw_version; struct platform_device *mts_io_platform_device; EXPORT_SYMBOL(mts_io_platform_device); @@ -135,8 +128,6 @@ static time_t time_now_secs(void); /* generic GPIO support */ #include "gpio.c" -#include "spi.c" - /* generic Button support */ //#include "buttons.c" @@ -165,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) @@ -203,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, @@ -528,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) { @@ -558,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], @@ -617,11 +617,12 @@ 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 capabilities sub-directory support */ #include "mts_capab.c" @@ -649,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) || @@ -784,7 +790,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 +837,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 +859,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); @@ -883,8 +909,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", @@ -941,6 +969,7 @@ static void cleanup(void) } mts_capab_dir_delete(); + mts_cpu_dir_delete(); } static int __init mts_io_init(void) @@ -964,46 +993,27 @@ 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; } - if (DEVICE_CAPA(id_eeprom.capa, CAPA_DOUT)) { - ret = spi_register_driver(&mts_spi_dout_driver); - if (ret) { - printk(KERN_ERR "mts-io:mts-io-dout: probe failed: %d\n", ret); - } - } - if (DEVICE_CAPA(id_eeprom.capa, CAPA_DIN)) { - ret = spi_register_driver(&mts_spi_din_driver); - if (ret) { - printk(KERN_ERR "mts-io:mts-io-din: probe failed: %d\n", ret); - } - } - ret = spi_register_driver(&mts_spi_board_temp_driver); - if (ret) { - printk(KERN_ERR "mts-io:mts-io-board-temp: probe failed: %d\n", ret); - } - if (DEVICE_CAPA(id_eeprom.capa, CAPA_LORA) && attr_group_lora) { mts_load_lora_port(); } - ret = mts_capab_dir_create(); + ret = mts_capab_dir_create(mts_hw_version); if (ret) { cleanup(); return ret; @@ -1022,6 +1032,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(); @@ -1038,14 +1052,6 @@ static int __init mts_io_init(void) static void __exit mts_io_exit(void) { - if (DEVICE_CAPA(id_eeprom.capa, CAPA_DOUT)) { - spi_unregister_driver(&mts_spi_dout_driver); - } - if (DEVICE_CAPA(id_eeprom.capa, CAPA_DIN)) { - spi_unregister_driver(&mts_spi_din_driver); - } - spi_unregister_driver(&mts_spi_board_temp_driver); - struct gpio_pin *pin; /* delete radio_reset_timer */ del_timer(&radio_reset_timer); |