From 3ac592211f34365e1788ff2ec01cdbc03e48b660 Mon Sep 17 00:00:00 2001 From: Mike Nicholson Date: Wed, 12 Dec 2018 16:46:36 -0600 Subject: Load EEPROM via request_firmware --- io-module/mts-io.c | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'io-module') diff --git a/io-module/mts-io.c b/io-module/mts-io.c index 7726b34..64886a0 100644 --- a/io-module/mts-io.c +++ b/io-module/mts-io.c @@ -44,7 +44,7 @@ #include #include #include - +#include #include "mts_io_module.h" #include "mts_io.h" #include "buttons.h" @@ -54,9 +54,7 @@ #define LED_LS_CONTROLLABLE 0 /* on-board EEPROM */ -extern uint8_t mts_id_eeprom[512]; 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); @@ -574,18 +572,27 @@ mts_id_eeprom_load(void) int current_blength; // Current length in bytes of attribute array 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; - } + char *tmp; + int noradio; + int ret; + const struct firmware* fw = NULL; + + /* Attempt to load the mts-io driver */ + if((ret = request_firmware(&fw, "mts_eeprom.bin", &mts_io_platform_device->dev)) == 0) { + if(fw->size == sizeof(id_eeprom)) + { + memcpy(&id_eeprom, fw->data, sizeof(id_eeprom)); + log_info("Platform EEPROM contents loaded"); + } + else + { + log_error("Invalid platform EEPROM length (%d)", fw->size); + } + + release_firmware(fw); + } else { + log_error("Unable to load EEPROM contents (%d)", ret); + } noradio = ! has_radio(id_eeprom.product_id,sizeof id_eeprom.product_id); log_debug("mts_id_eeprom: noradio=%d",noradio); @@ -860,18 +867,19 @@ static int __init mts_io_init(void) log_info("init: " DRIVER_VERSION); - ret = mts_id_eeprom_load(); - if (ret) { - cleanup(); - return ret; - } - mts_io_platform_device = platform_device_alloc(PLATFORM_NAME, -1); if (!mts_io_platform_device) { cleanup(); return -ENOMEM; } + /* request_firmware() requires a device, so call after device allocated */ + ret = mts_id_eeprom_load(); + if (ret) { + cleanup(); + return ret; + } + ret = platform_device_add(mts_io_platform_device); if (ret) { cleanup(); -- cgit v1.2.3