Skip to content

Commit 4e0c09e

Browse files
committed
Move correct i2c bus detection for AMD GPUs to separate header file
1 parent f5fc3ff commit 4e0c09e

2 files changed

Lines changed: 40 additions & 24 deletions

File tree

Controllers/SapphireGPUController/SapphireGPUControllerDetect.cpp

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
| SPDX-License-Identifier: GPL-2.0-or-later |
88
\*---------------------------------------------------------*/
99

10-
#include <cstring>
1110
#include "Detector.h"
1211
#include "SapphireNitroGlowV1Controller.h"
1312
#include "SapphireNitroGlowV3Controller.h"
1413
#include "RGBController_SapphireNitroGlowV1.h"
1514
#include "RGBController_SapphireNitroGlowV3.h"
15+
#include "i2c_amd_gpu.h"
1616
#include "i2c_smbus.h"
1717
#include "pci_ids.h"
1818

@@ -34,31 +34,9 @@ enum
3434
* *
3535
\******************************************************************************************/
3636

37-
static const char * RECOGNIZED_I2C_BUS_NAMES[] = {
38-
"AMD ADL",
39-
"AMDGPU DM i2c OEM bus",
40-
nullptr
41-
};
42-
43-
bool IsRecognizedI2CBus(i2c_smbus_interface* bus)
44-
{
45-
size_t idx = 0;
46-
47-
const char *name;
48-
while((name = RECOGNIZED_I2C_BUS_NAMES[idx++]) != nullptr)
49-
{
50-
if(std::strcmp(name, bus->device_name) == 0)
51-
{
52-
return true;
53-
}
54-
}
55-
56-
return false;
57-
}
58-
5937
bool TestForSapphireGPUController(i2c_smbus_interface* bus, unsigned char address)
6038
{
61-
if (!IsRecognizedI2CBus(bus))
39+
if(bus->pci_vendor == AMD_GPU_VEN && !is_amd_gpu_i2c_bus(bus))
6240
{
6341
return false;
6442
}

i2c_smbus/i2c_amd_gpu.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*---------------------------------------------------------*\
2+
| i2c_amd_gpu.h |
3+
| |
4+
| Bits specific to AMD GPUs to reliably detect |
5+
| the I2C bus that has RGB control |
6+
| |
7+
| This file is part of the OpenRGB project |
8+
| SPDX-License-Identifier: GPL-2.0-or-later |
9+
\*---------------------------------------------------------*/
10+
11+
#pragma once
12+
13+
#include <cstring>
14+
#include "i2c_smbus.h"
15+
16+
inline constexpr const char * RECOGNIZED_I2C_BUS_NAMES[] =
17+
{
18+
// Windows i2c bus
19+
"AMD ADL",
20+
// Linux i2c bus name since kernel 6.15
21+
"AMDGPU DM i2c OEM bus",
22+
nullptr
23+
};
24+
25+
inline bool is_amd_gpu_i2c_bus(const i2c_smbus_interface *bus)
26+
{
27+
const char *name;
28+
size_t idx = 0;
29+
while((name = RECOGNIZED_I2C_BUS_NAMES[idx++]) != nullptr)
30+
{
31+
if(std::strcmp(name, bus->device_name) == 0)
32+
{
33+
return true;
34+
}
35+
}
36+
37+
return false;
38+
}

0 commit comments

Comments
 (0)