From 0ed1e3654d7f468e7b546aaf9e45ab2e3bf2bfd3 Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 12 Dec 2018 16:39:01 -0600 Subject: Load EEPROM via request_firmware --- mtac.c | 27 ++++++++++++++++++++++++++- mtac.h | 1 - 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/mtac.c b/mtac.c index 2f31bbe..532545d 100644 --- a/mtac.c +++ b/mtac.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -16,7 +17,8 @@ #include "mtac.h" /* accessory card EEPROMs, read outside of driver */ -extern uint8_t mts_ap_eeprom[NUM_AP][512]; +uint8_t mts_ap_eeprom[NUM_AP][512]; +EXPORT_SYMBOL(mts_ap_eeprom); /* info for accessory port (contains function pointers for setup and teardown, * gpio pin list for the device inserted into the port. */ @@ -467,10 +469,33 @@ EXPORT_SYMBOL(mtac_free); static int __init mtac_init(void) { int port_index; +#define MTS_IO_FWNAME_LEN (32) + char fwname[MTS_IO_FWNAME_LEN]; + const struct firmware* fw = NULL; + int ret; log_debug("init: " DRIVER_VERSION); mutex_lock(&mtac_mutex); + for (port_index = 0; port_index < NUM_AP; port_index++) { + snprintf(fwname, MTS_IO_FWNAME_LEN, "mtac%d_eeprom.bin", port_index+1); + fwname[MTS_IO_FWNAME_LEN-1] = '\0'; + + mts_ap_eeprom[port_index][0] = 0x00; /* initialize to not present */ + if((ret = request_firmware(&fw, fwname, &mts_io_platform_device->dev)) == 0) { + if(fw->size == sizeof(mts_ap_eeprom[0])) { + memcpy(mts_ap_eeprom[port_index], fw->data, sizeof(mts_ap_eeprom[0])); + log_info("EEPROM contents loaded (%s)", fwname); + } + else + { + log_error("EEPROM invalid size (%s:%d)", fwname, fw->size); + } + release_firmware(fw); + } else { + log_error("EEPROM unable to read (%s:%d)", fwname, ret); + } + if (mts_ap_eeprom[port_index][0] == 0xFF) log_alert("uninitialized eeprom on accessory card %d", port_index); else if (mts_ap_eeprom[port_index][0] == 0x0) diff --git a/mtac.h b/mtac.h index 03e6cd0..477dea4 100644 --- a/mtac.h +++ b/mtac.h @@ -69,7 +69,6 @@ struct ap_info { extern struct platform_device *mts_io_platform_device; -extern uint8_t mts_ap_eeprom[NUM_AP][512]; extern struct mutex mtac_mutex; extern void mtac_clear_port_pins(int port_index); -- cgit v1.2.3