From 31a9399d192a58b592c5c983fe4150ba2ff971f1 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Tue, 27 Oct 2020 00:46:53 -0500 Subject: [PATCH] Add I2C read check to Sapphire GPU controller, so it only creates a controller for the correct GPU bus --- .../SapphireGPUControllerDetect.cpp | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/Controllers/SapphireGPUController/SapphireGPUControllerDetect.cpp b/Controllers/SapphireGPUController/SapphireGPUControllerDetect.cpp index af0a17d3..4dd03980 100644 --- a/Controllers/SapphireGPUController/SapphireGPUControllerDetect.cpp +++ b/Controllers/SapphireGPUController/SapphireGPUControllerDetect.cpp @@ -24,6 +24,32 @@ static const gpu_pci_device device_list[] = { AMD_GPU_VEN, AMD_RX580_DEV, SAPPHIRE_SUB_VEN, SAPPHIRE_RX580_NITRO_PLUS_SUB_DEV, "Sapphire RX580 Nitro+" }, }; +/******************************************************************************************\ +* * +* TestForSapphireGPUController * +* * +* Tests the given address to see if an Sapphire controller exists there. First * +* does a quick write to test for a response * +* * +\******************************************************************************************/ + +bool TestForSapphireGPUController(i2c_smbus_interface* bus, unsigned char address) +{ + bool pass = false; + int res; + + //Read a byte to test for presence + res = bus->i2c_smbus_read_byte(address); + + if (res >= 0) + { + pass = true; + } + + return(pass); + +} /* TestForSapphireGPUController() */ + /******************************************************************************************\ * * * DetectSapphireGPUControllers * @@ -49,10 +75,13 @@ void DetectSapphireGPUControllers(std::vector& busses, std busses[bus]->pci_subsystem_vendor == device_list[dev_idx].pci_subsystem_vendor && busses[bus]->pci_subsystem_device == device_list[dev_idx].pci_subsystem_device) { - new_sapphire_gpu = new SapphireGPUController(busses[bus], 0x55); - new_controller = new RGBController_SapphireGPU(new_sapphire_gpu); - new_controller->name = device_list[dev_idx].name; - rgb_controllers.push_back(new_controller); + if(TestForSapphireGPUController(busses[bus], 0x55)) + { + new_sapphire_gpu = new SapphireGPUController(busses[bus], 0x55); + new_controller = new RGBController_SapphireGPU(new_sapphire_gpu); + new_controller->name = device_list[dev_idx].name; + rgb_controllers.push_back(new_controller); + } } } }