From 4e0c09efd410038d0e40dbb6d4d4a9fdd4719e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mal=C3=BD?= Date: Wed, 6 Aug 2025 23:16:20 +0200 Subject: [PATCH] Move correct i2c bus detection for AMD GPUs to separate header file --- .../SapphireGPUControllerDetect.cpp | 26 +------------ i2c_smbus/i2c_amd_gpu.h | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 24 deletions(-) create mode 100644 i2c_smbus/i2c_amd_gpu.h diff --git a/Controllers/SapphireGPUController/SapphireGPUControllerDetect.cpp b/Controllers/SapphireGPUController/SapphireGPUControllerDetect.cpp index a3f738e1..40c4773a 100644 --- a/Controllers/SapphireGPUController/SapphireGPUControllerDetect.cpp +++ b/Controllers/SapphireGPUController/SapphireGPUControllerDetect.cpp @@ -7,12 +7,12 @@ | SPDX-License-Identifier: GPL-2.0-or-later | \*---------------------------------------------------------*/ -#include #include "Detector.h" #include "SapphireNitroGlowV1Controller.h" #include "SapphireNitroGlowV3Controller.h" #include "RGBController_SapphireNitroGlowV1.h" #include "RGBController_SapphireNitroGlowV3.h" +#include "i2c_amd_gpu.h" #include "i2c_smbus.h" #include "pci_ids.h" @@ -34,31 +34,9 @@ enum * * \******************************************************************************************/ -static const char * RECOGNIZED_I2C_BUS_NAMES[] = { - "AMD ADL", - "AMDGPU DM i2c OEM bus", - nullptr -}; - -bool IsRecognizedI2CBus(i2c_smbus_interface* bus) -{ - size_t idx = 0; - - const char *name; - while((name = RECOGNIZED_I2C_BUS_NAMES[idx++]) != nullptr) - { - if(std::strcmp(name, bus->device_name) == 0) - { - return true; - } - } - - return false; -} - bool TestForSapphireGPUController(i2c_smbus_interface* bus, unsigned char address) { - if (!IsRecognizedI2CBus(bus)) + if(bus->pci_vendor == AMD_GPU_VEN && !is_amd_gpu_i2c_bus(bus)) { return false; } diff --git a/i2c_smbus/i2c_amd_gpu.h b/i2c_smbus/i2c_amd_gpu.h new file mode 100644 index 00000000..213d840d --- /dev/null +++ b/i2c_smbus/i2c_amd_gpu.h @@ -0,0 +1,38 @@ +/*---------------------------------------------------------*\ +| i2c_amd_gpu.h | +| | +| Bits specific to AMD GPUs to reliably detect | +| the I2C bus that has RGB control | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-or-later | +\*---------------------------------------------------------*/ + +#pragma once + +#include +#include "i2c_smbus.h" + +inline constexpr const char * RECOGNIZED_I2C_BUS_NAMES[] = +{ + // Windows i2c bus + "AMD ADL", + // Linux i2c bus name since kernel 6.15 + "AMDGPU DM i2c OEM bus", + nullptr +}; + +inline bool is_amd_gpu_i2c_bus(const i2c_smbus_interface *bus) +{ + const char *name; + size_t idx = 0; + while((name = RECOGNIZED_I2C_BUS_NAMES[idx++]) != nullptr) + { + if(std::strcmp(name, bus->device_name) == 0) + { + return true; + } + } + + return false; +}