From f37b39e45eba85d8735f4411bc67cd68303ea354 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Tue, 12 Oct 2021 21:42:01 -0500 Subject: [PATCH] Check for Micron string when detecting Aura and Crucial DRAM to ensure right controller gets used --- .../AsusAuraSMBusController.h | 1 + .../AsusAuraSMBusControllerDetect.cpp | 37 +++++++++++++- .../CrucialController/CrucialController.h | 5 ++ .../CrucialControllerDetect.cpp | 50 +++++++++++++++++-- 4 files changed, 87 insertions(+), 6 deletions(-) diff --git a/Controllers/AsusAuraSMBusController/AsusAuraSMBusController.h b/Controllers/AsusAuraSMBusController/AsusAuraSMBusController.h index 36961887..fb0d1ffd 100644 --- a/Controllers/AsusAuraSMBusController/AsusAuraSMBusController.h +++ b/Controllers/AsusAuraSMBusController/AsusAuraSMBusController.h @@ -20,6 +20,7 @@ typedef unsigned short aura_register; enum { AURA_REG_DEVICE_NAME = 0x1000, /* Device String 16 bytes */ + AURA_REG_MICRON_CHECK = 0x1030, /* If "Micron" appears here, skip */ AURA_REG_CONFIG_TABLE = 0x1C00, /* Start of LED configuration bytes */ AURA_REG_COLORS_DIRECT = 0x8000, /* Colors for Direct Mode 15 bytes */ AURA_REG_COLORS_EFFECT = 0x8010, /* Colors for Internal Effects 15 bytes */ diff --git a/Controllers/AsusAuraSMBusController/AsusAuraSMBusControllerDetect.cpp b/Controllers/AsusAuraSMBusController/AsusAuraSMBusControllerDetect.cpp index 9b8fd129..3ac0b975 100644 --- a/Controllers/AsusAuraSMBusController/AsusAuraSMBusControllerDetect.cpp +++ b/Controllers/AsusAuraSMBusController/AsusAuraSMBusControllerDetect.cpp @@ -59,6 +59,25 @@ static const unsigned char aura_mobo_addresses[] = 0x4F }; +/******************************************************************************************\ +* * +* AuraRegisterRead * +* * +* A standalone version of the AuraSMBusController::AuraRegisterRead function for * +* access to Aura devices without instancing the AuraSMBusController class or reading * +* the config table from the device. * +* * +\******************************************************************************************/ + +unsigned char AuraRegisterRead(i2c_smbus_interface* bus, aura_dev_id dev, aura_register reg) +{ + //Write Aura register + bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF)); + + //Read Aura value + return(bus->i2c_smbus_read_byte_data(dev, 0x81)); +} + /******************************************************************************************\ * * * AuraRegisterWrite * @@ -116,7 +135,23 @@ bool TestForAsusAuraSMBusController(i2c_smbus_interface* bus, unsigned char addr if(pass) { - LOG_VERBOSE("[Aura SMBus] Detection successful, address %02X", address); + LOG_DEBUG("[Aura SMBus] Checking for Micron string"); + + char buf[16]; + for(int i = 0; i < 16; i++) + { + buf[i] = AuraRegisterRead(bus, address, AURA_REG_MICRON_CHECK + i); + } + + if(strcmp(buf, "Micron") == 0) + { + LOG_DEBUG("[Aura SMBus] Device %02X is a Micron device, skipping", address); + pass = false; + } + else + { + LOG_VERBOSE("[Aura SMBus] Detection successful, address %02X", address); + } } } diff --git a/Controllers/CrucialController/CrucialController.h b/Controllers/CrucialController/CrucialController.h index 25795188..f3fc6c4c 100644 --- a/Controllers/CrucialController/CrucialController.h +++ b/Controllers/CrucialController/CrucialController.h @@ -16,6 +16,11 @@ typedef unsigned char crucial_dev_id; typedef unsigned short crucial_register; +enum +{ + CRUCIAL_REG_MICRON_CHECK = 0x1030 /* "Micron" string should be here */ +}; + enum { CRUCIAL_MODE_UNKNOWN = 0x00, /* We don't know what the mode is */ diff --git a/Controllers/CrucialController/CrucialControllerDetect.cpp b/Controllers/CrucialController/CrucialControllerDetect.cpp index f2f62c56..86567fb4 100644 --- a/Controllers/CrucialController/CrucialControllerDetect.cpp +++ b/Controllers/CrucialController/CrucialControllerDetect.cpp @@ -14,7 +14,7 @@ using namespace std::chrono_literals; /*----------------------------------------------------------------------*\ | This list contains the available SMBus addresses for Crucial RAM | \*----------------------------------------------------------------------*/ -#define CRUCIAL_ADDRESS_COUNT 4 +#define CRUCIAL_ADDRESS_COUNT 8 static const unsigned char crucial_addresses[] = { @@ -24,10 +24,10 @@ static const unsigned char crucial_addresses[] = | the same, Aura RAM will be detected as Crucial. | | We need to improve the Crucial detection scheme. | \*-----------------------------------------------------*/ -// 0x39, -// 0x3A, -// 0x3B, -// 0x3C, + 0x39, + 0x3A, + 0x3B, + 0x3C, 0x20, 0x21, 0x22, @@ -46,6 +46,25 @@ std::string concatHexArray(const unsigned char array[], int count, const char sp } #define TESTING_ADDRESSES concatHexArray(crucial_addresses, CRUCIAL_ADDRESS_COUNT, "|").c_str() +/******************************************************************************************\ +* * +* CrucialRegisterRead * +* * +* A standalone version of the AuraSMBusController::AuraRegisterRead function for * +* access to Aura devices without instancing the AuraSMBusController class or reading * +* the config table from the device. * +* * +\******************************************************************************************/ + +unsigned char CrucialRegisterRead(i2c_smbus_interface* bus, crucial_dev_id dev, crucial_register reg) +{ + //Write Aura register + bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF)); + + //Read Aura value + return(bus->i2c_smbus_read_byte_data(dev, 0x81)); +} + /******************************************************************************************\ * * * TestForCrucialController * @@ -79,6 +98,27 @@ bool TestForCrucialController(i2c_smbus_interface* bus, unsigned char address) pass = false; } } + + if(pass) + { + LOG_DEBUG("[%s] Checking for Micron string", CRUCIAL_CONTROLLER_NAME); + + char buf[16]; + for(int i = 0; i < 16; i++) + { + buf[i] = CrucialRegisterRead(bus, address, CRUCIAL_REG_MICRON_CHECK + i); + } + + if(strcmp(buf, "Micron") == 0) + { + LOG_DEBUG("[%s] Device %02X is a Micron device, continuing", CRUCIAL_CONTROLLER_NAME, address); + } + else + { + LOG_DEBUG("[%s] Device %02X is not a Micron device, skipping", CRUCIAL_CONTROLLER_NAME, address); + pass = false; + } + } } return(pass);