Skip to content

Commit 23ec687

Browse files
committed
Check for bus name when looking for Sapphire GPU RGB controls
1 parent 5c30da6 commit 23ec687

4 files changed

Lines changed: 32 additions & 13 deletions

File tree

Controllers/SapphireGPUController/SapphireGPUControllerDetect.cpp

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

10+
#include <cstring>
1011
#include "Detector.h"
1112
#include "SapphireNitroGlowV1Controller.h"
1213
#include "SapphireNitroGlowV3Controller.h"
@@ -33,21 +34,34 @@ enum
3334
* *
3435
\******************************************************************************************/
3536

36-
bool TestForSapphireGPUController(i2c_smbus_interface* bus, unsigned char address)
37-
{
38-
bool pass = false;
39-
int res;
37+
static const char * RECOGNIZED_I2C_BUS_NAMES[] = {
38+
"AMD ADL",
39+
"AMDGPU DM i2c OEM bus",
40+
nullptr
41+
};
4042

41-
//Read a byte to test for presence
42-
res = bus->i2c_smbus_read_byte(address);
43+
bool IsRecognizedI2CBus(i2c_smbus_interface* bus)
44+
{
45+
size_t idx = 0;
4346

44-
if (res >= 0)
47+
const char *name;
48+
while((name = RECOGNIZED_I2C_BUS_NAMES[idx++]) != nullptr)
4549
{
46-
pass = true;
50+
if (std::strcmp(name, bus->bus_name) == 0) return true;
4751
}
4852

49-
return(pass);
53+
return false;
54+
}
5055

56+
bool TestForSapphireGPUController(i2c_smbus_interface* bus, unsigned char address)
57+
{
58+
if (!IsRecognizedI2CBus(bus))
59+
{
60+
return false;
61+
}
62+
63+
//Read a byte to test for presence
64+
return bus->i2c_smbus_read_byte(address) >= 0;
5165
} /* TestForSapphireGPUController() */
5266

5367
/******************************************************************************************\

i2c_smbus/Linux/i2c_smbus_linux.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ bool i2c_smbus_linux_detect()
7474
{
7575
i2c_smbus_linux * bus;
7676
char device_string[1024];
77+
char device_path[1024];
7778
DIR * dir;
7879
char driver_path[512];
7980
struct dirent * ent;
@@ -109,6 +110,7 @@ bool i2c_smbus_linux_detect()
109110
if(test_fd)
110111
{
111112
memset(device_string, 0x00, sizeof(device_string));
113+
memset(device_path, 0x00, sizeof(device_string));
112114

113115
if(read(test_fd, device_string, sizeof(device_string)) < 0)
114116
{
@@ -220,17 +222,18 @@ bool i2c_smbus_linux_detect()
220222
close(test_fd);
221223
}
222224

223-
strcpy(device_string, "/dev/");
224-
strcat(device_string, ent->d_name);
225-
test_fd = open(device_string, O_RDWR);
225+
strcpy(device_path, "/dev/");
226+
strcat(device_path, ent->d_name);
227+
test_fd = open(device_path, O_RDWR);
226228

227229
if (test_fd < 0)
228230
{
229231
ret = false;
230232
}
231233

232234
bus = new i2c_smbus_linux();
233-
strcpy(bus->device_name, device_string);
235+
strcpy(bus->device_name, device_path);
236+
strcpy(bus->bus_name, device_string);
234237
bus->handle = test_fd;
235238
bus->pci_device = pci_device;
236239
bus->pci_vendor = pci_vendor;

i2c_smbus/Windows/i2c_smbus_amdadl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ i2c_smbus_amdadl::i2c_smbus_amdadl(ADL_CONTEXT_HANDLE context, int adapter_index
130130
this->pci_subsystem_device = sbd_id;
131131
this->port_id = 1;
132132
strcpy(this->device_name, "AMD ADL");
133+
strcpy(this->bus_name, "AMD ADL");
133134
}
134135
}
135136
}

i2c_smbus/i2c_smbus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class i2c_smbus_interface
7777
{
7878
public:
7979
char device_name[512];
80+
char bus_name[512];
8081

8182
int port_id;
8283
int pci_device;

0 commit comments

Comments
 (0)