Skip to content

Commit c32663b

Browse files
Rework EVGAGP102GPUController to use I2C PCI detector and store name in controller to avoid setting it in detector
1 parent c94eed4 commit c32663b

File tree

6 files changed

+81
-97
lines changed

6 files changed

+81
-97
lines changed

Controllers/EVGAAmpereGPUController/EVGAGPUv3Controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ void EVGAGPUv3Controller::SetZone(uint8_t zone, uint8_t mode, EVGAv3_config zone
516516
break;
517517
default:
518518
{
519-
LOG_TRACE("[%s] Mode %02d not found", name->c_str(), mode);
519+
LOG_TRACE("[%s] Mode %02d not found", name.c_str(), mode);
520520
}
521521
break;
522522
}

Controllers/EVGAGP102GPUController/EVGAGP102Controller.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
#include "EVGAGP102Controller.h"
1313
#include "LogManager.h"
1414

15-
EVGAGP102Controller::EVGAGP102Controller(i2c_smbus_interface* bus_ptr, zoneinfo info)
15+
EVGAGP102Controller::EVGAGP102Controller(i2c_smbus_interface* bus_ptr, zoneinfo info, std::string dev_name)
1616
{
17-
bus = bus_ptr;
18-
zi = info;
17+
bus = bus_ptr;
18+
zi = info;
19+
name = dev_name;
1920
}
2021

2122
EVGAGP102Controller::~EVGAGP102Controller()
@@ -32,6 +33,16 @@ std::string EVGAGP102Controller::GetDeviceLocation()
3233
return("I2C: " + return_string);
3334
}
3435

36+
std::string EVGAGP102Controller::GetDeviceName()
37+
{
38+
return(name);
39+
}
40+
41+
std::string EVGAGP102Controller::GetZoneName()
42+
{
43+
return(zi.zone_name);
44+
}
45+
3546
void EVGAGP102Controller::SetColor(unsigned char red, unsigned char green, unsigned char blue)
3647
{
3748
SendCommand(EVGA_GP102_CMD_BEGIN);
@@ -125,8 +136,3 @@ void EVGAGP102Controller::SaveSettings()
125136
//bus->i2c_smbus_write_byte_data(zi.dev_addr, 0x21, 0xE5);
126137
//bus->i2c_smbus_write_byte_data(zi.dev_addr, 0x22, 0xE7);
127138
}
128-
129-
std::string EVGAGP102Controller::GetName()
130-
{
131-
return zi.zone_name;
132-
}

Controllers/EVGAGP102GPUController/EVGAGP102Controller.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ const static zoneinfo gpuzoneinfos[]
8282
class EVGAGP102Controller
8383
{
8484
public:
85-
EVGAGP102Controller(i2c_smbus_interface* bus, zoneinfo info);
85+
EVGAGP102Controller(i2c_smbus_interface* bus, zoneinfo info, std::string dev_name);
8686
~EVGAGP102Controller();
8787

8888
bool IsValid();
8989
std::string GetDeviceLocation();
90-
std::string GetName();
90+
std::string GetDeviceName();
91+
std::string GetZoneName();
9192
unsigned char GetMode();
9293

9394
void SetColor(unsigned char red, unsigned char green, unsigned char blue);
@@ -96,15 +97,15 @@ class EVGAGP102Controller
9697
void SaveSettings();
9798

9899
private:
100+
i2c_smbus_interface* bus;
101+
zoneinfo zi;
102+
std::string name;
103+
99104
bool CommandAcknowledged();
100105
bool CommandCompleted();
101106
s32 QueryCommand(s32 command);
102107
void SendCommand(s32 command);
103108
unsigned char GetRed();
104109
unsigned char GetGreen();
105110
unsigned char GetBlue();
106-
107-
i2c_smbus_interface* bus;
108-
zoneinfo zi;
109-
110111
};

Controllers/EVGAGP102GPUController/EVGAGP102GPUControllerDetect.cpp

Lines changed: 33 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,80 +17,57 @@
1717
#include "i2c_smbus.h"
1818
#include "pci_ids.h"
1919

20-
typedef struct
21-
{
22-
int pci_vendor;
23-
int pci_device;
24-
int pci_subsystem_vendor;
25-
int pci_subsystem_device;
26-
const char * name;
27-
} gpu_pci_device;
28-
29-
#define GPU_NUM_DEVICES (sizeof(device_list) / sizeof(device_list[ 0 ]))
30-
31-
static const gpu_pci_device device_list[] =
32-
{
33-
{ NVIDIA_VEN, NVIDIA_GTX1070_DEV, EVGA_SUB_VEN, EVGA_GTX1070_FTW2_SUB_DEV, "EVGA GeForce GTX 1070 FTW2 Gaming" },
34-
{ NVIDIA_VEN, NVIDIA_GTX1080_DEV, EVGA_SUB_VEN, EVGA_GTX1080_FTW2_SUB_DEV, "EVGA GeForce GTX 1080 FTW2 Gaming" },
35-
{ NVIDIA_VEN, NVIDIA_GTX1080_DEV, EVGA_SUB_VEN, EVGA_GTX1080_FTW2_11G_SUB_DEV, "EVGA GeForce GTX 1080 FTW2 11G" },
36-
{ NVIDIA_VEN, NVIDIA_GTX1080_DEV, EVGA_SUB_VEN, EVGA_GTX1080_FTW2_DT_SUB_DEV, "EVGA GeForce GTX 1080 FTW2 DT" },
37-
{ NVIDIA_VEN, NVIDIA_GTX1080TI_DEV, EVGA_SUB_VEN, EVGA_GTX1080TI_SC2_GAMING_SUB_DEV, "EVGA GeForce GTX 1080 Ti SC2 Gaming" },
38-
{ NVIDIA_VEN, NVIDIA_GTX1080TI_DEV, EVGA_SUB_VEN, EVGA_GTX1080TI_FTW3_SUB_DEV, "EVGA GeForce GTX 1080 Ti FTW3" },
39-
{ NVIDIA_VEN, NVIDIA_GTX1080TI_DEV, EVGA_SUB_VEN, EVGA_GTX1080TI_FTW3_HYBRID_SUB_DEV, "EVGA GeForce GTX 1080 Ti FTW3 Hybrid" },
40-
{ NVIDIA_VEN, NVIDIA_GTX1080TI_DEV, EVGA_SUB_VEN, EVGA_GTX1080TI_KINGPIN_SUB_DEV, "EVGA GeForce GTX 1080 Ti K|NGP|N" },
41-
};
4220
/******************************************************************************************\
4321
* *
4422
* DetectEVGAGP102GPUControllers *
4523
* *
4624
* Detect EVGA GP102 GPU controllers on the enumerated I2C busses at address 0x49. *
4725
* *
4826
* bus - pointer to i2c_smbus_interface where EVGA GPU device is connected *
49-
* dev - I2C address of EVGA GPU device *
27+
* address - unused, the address comes from the GPU zone info table *
28+
* name - name string of detected PCI device *
5029
* *
5130
\******************************************************************************************/
5231

53-
void DetectEVGAGP102GPUControllers(std::vector<i2c_smbus_interface*>& busses)
32+
void DetectEVGAGP102GPUControllers(i2c_smbus_interface* bus, uint8_t /*address*/, const std::string& name)
5433
{
55-
for (unsigned int bus = 0; bus < busses.size(); bus++)
34+
if(bus->port_id == 1)
5635
{
57-
for(unsigned int dev_idx = 0; dev_idx < GPU_NUM_DEVICES; dev_idx++)
36+
RGBController_EVGAGP102* new_rgbcontroller;
37+
std::vector<EVGAGP102Controller*> controllers;
38+
39+
for(unsigned int i = 0; i < sizeof(gpuzoneinfos) / sizeof(zoneinfo); i++)
5840
{
59-
if (busses[bus]->port_id != 1)
41+
EVGAGP102Controller* controller = new EVGAGP102Controller(bus, gpuzoneinfos[i], name);
42+
43+
if(controller->IsValid())
6044
{
61-
break;
45+
controllers.push_back(controller);
6246
}
63-
64-
if(busses[bus]->pci_vendor == device_list[dev_idx].pci_vendor &&
65-
busses[bus]->pci_device == device_list[dev_idx].pci_device &&
66-
busses[bus]->pci_subsystem_vendor == device_list[dev_idx].pci_subsystem_vendor &&
67-
busses[bus]->pci_subsystem_device == device_list[dev_idx].pci_subsystem_device)
47+
else
6848
{
69-
LOG_DEBUG(GPU_DETECT_MESSAGE, EVGA_GP102_CONTROLLER_NAME, bus, device_list[dev_idx].pci_device, device_list[dev_idx].pci_subsystem_device, device_list[dev_idx].name );
70-
RGBController_EVGAGP102* new_rgbcontroller;
71-
std::vector<EVGAGP102Controller*> controllers;
72-
73-
for(unsigned int i = 0; i < sizeof(gpuzoneinfos) / sizeof(zoneinfo); i++)
74-
{
75-
EVGAGP102Controller* contr = new EVGAGP102Controller(busses[bus], gpuzoneinfos[i]);
76-
if (contr->IsValid())
77-
{
78-
controllers.push_back(contr);
79-
}
80-
else
81-
{
82-
delete contr;
83-
}
84-
}
85-
if(controllers.size() != 0)
86-
{
87-
new_rgbcontroller = new RGBController_EVGAGP102(controllers);
88-
new_rgbcontroller->name = device_list[dev_idx].name;
89-
ResourceManager::get()->RegisterRGBController(new_rgbcontroller);
90-
}
49+
delete controller;
9150
}
9251
}
52+
53+
if(controllers.size() != 0)
54+
{
55+
new_rgbcontroller = new RGBController_EVGAGP102(controllers);
56+
57+
ResourceManager::get()->RegisterRGBController(new_rgbcontroller);
58+
}
9359
}
9460
} /* DetectEVGAGP102GPUControllers() */
9561

96-
REGISTER_I2C_DETECTOR("EVGA GP102 GPU", DetectEVGAGP102GPUControllers);
62+
/*---------------------------------------------------------*\
63+
| The I2C address is provided by the GPU Zone Info table, |
64+
| as these GPUs have multiple I2C devices per card. |
65+
\*---------------------------------------------------------*/
66+
REGISTER_I2C_PCI_DETECTOR( "EVGA GeForce GTX 1070 FTW2 Gaming", DetectEVGAGP102GPUControllers, NVIDIA_VEN, NVIDIA_GTX1070_DEV, EVGA_SUB_VEN, EVGA_GTX1070_FTW2_SUB_DEV, 0x00 );
67+
REGISTER_I2C_PCI_DETECTOR( "EVGA GeForce GTX 1080 FTW2 Gaming", DetectEVGAGP102GPUControllers, NVIDIA_VEN, NVIDIA_GTX1080_DEV, EVGA_SUB_VEN, EVGA_GTX1080_FTW2_SUB_DEV, 0x00 );
68+
REGISTER_I2C_PCI_DETECTOR( "EVGA GeForce GTX 1080 FTW2 11G", DetectEVGAGP102GPUControllers, NVIDIA_VEN, NVIDIA_GTX1080_DEV, EVGA_SUB_VEN, EVGA_GTX1080_FTW2_11G_SUB_DEV, 0x00 );
69+
REGISTER_I2C_PCI_DETECTOR( "EVGA GeForce GTX 1080 FTW2 DT", DetectEVGAGP102GPUControllers, NVIDIA_VEN, NVIDIA_GTX1080_DEV, EVGA_SUB_VEN, EVGA_GTX1080_FTW2_DT_SUB_DEV, 0x00 );
70+
REGISTER_I2C_PCI_DETECTOR( "EVGA GeForce GTX 1080 Ti SC2 Gaming", DetectEVGAGP102GPUControllers, NVIDIA_VEN, NVIDIA_GTX1080TI_DEV, EVGA_SUB_VEN, EVGA_GTX1080TI_SC2_GAMING_SUB_DEV, 0x00 );
71+
REGISTER_I2C_PCI_DETECTOR( "EVGA GeForce GTX 1080 Ti FTW3", DetectEVGAGP102GPUControllers, NVIDIA_VEN, NVIDIA_GTX1080TI_DEV, EVGA_SUB_VEN, EVGA_GTX1080TI_FTW3_SUB_DEV, 0x00 );
72+
REGISTER_I2C_PCI_DETECTOR( "EVGA GeForce GTX 1080 Ti FTW3 Hybrid", DetectEVGAGP102GPUControllers, NVIDIA_VEN, NVIDIA_GTX1080TI_DEV, EVGA_SUB_VEN, EVGA_GTX1080TI_FTW3_HYBRID_SUB_DEV, 0x00 );
73+
REGISTER_I2C_PCI_DETECTOR( "EVGA GeForce GTX 1080 Ti K|NGP|N", DetectEVGAGP102GPUControllers, NVIDIA_VEN, NVIDIA_GTX1080TI_DEV, EVGA_SUB_VEN, EVGA_GTX1080TI_KINGPIN_SUB_DEV, 0x00 );

Controllers/EVGAGP102GPUController/RGBController_EVGAGP102.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,40 @@
2323
@comment
2424
\*-------------------------------------------------------------------*/
2525

26-
RGBController_EVGAGP102::RGBController_EVGAGP102(std::vector<EVGAGP102Controller*> evga_ptr)
26+
RGBController_EVGAGP102::RGBController_EVGAGP102(std::vector<EVGAGP102Controller*> controller_list)
2727
{
28-
evga = evga_ptr;
28+
controllers = controller_list;
2929

30-
name = "EVGA GP102 GPU";
31-
vendor = "EVGA";
32-
description = "EVGA GP102-based RGB GPU Device";
30+
name = controllers[0]->GetDeviceName();
31+
vendor = "EVGA";
32+
description = "EVGA GP102-based RGB GPU Device";
3333

3434
for(unsigned int i = 0; i < zones.size(); i++)
3535
{
36-
location += evga[i]->GetDeviceLocation() + " ";
36+
location += controllers[i]->GetDeviceLocation() + " ";
3737
}
3838

3939
type = DEVICE_TYPE_GPU;
4040

4141
mode Off;
42-
Off.name = "Off";
43-
Off.value = EVGA_GP102_MODE_OFF;
44-
Off.flags = 0;
45-
Off.color_mode = MODE_COLORS_NONE;
42+
Off.name = "Off";
43+
Off.value = EVGA_GP102_MODE_OFF;
44+
Off.flags = 0;
45+
Off.color_mode = MODE_COLORS_NONE;
4646
modes.push_back(Off);
4747

4848
mode Direct;
49-
Direct.name = "Direct";
50-
Direct.value = EVGA_GP102_MODE_CUSTOM;
51-
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
52-
Direct.color_mode = MODE_COLORS_PER_LED;
49+
Direct.name = "Direct";
50+
Direct.value = EVGA_GP102_MODE_CUSTOM;
51+
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
52+
Direct.color_mode = MODE_COLORS_PER_LED;
5353
modes.push_back(Direct);
5454

5555
SetupZones();
5656

5757
// Initialize active mode and stored color
5858

59-
unsigned char raw_active_mode = evga[0]->GetMode();
59+
unsigned char raw_active_mode = controllers[0]->GetMode();
6060

6161
active_mode = 0;
6262
for(unsigned int i = 0; i < modes.size(); i++)
@@ -69,17 +69,17 @@ RGBController_EVGAGP102::RGBController_EVGAGP102(std::vector<EVGAGP102Controller
6969
}
7070
for(unsigned int i = 0; i < zones.size(); i++)
7171
{
72-
std::array<unsigned char, 3> rgb = evga[i]->GetColor();
72+
std::array<unsigned char, 3> rgb = controllers[i]->GetColor();
7373

7474
colors[i] = ToRGBColor(rgb[0], rgb[1], rgb[2]);
7575
}
7676
}
7777

7878
RGBController_EVGAGP102::~RGBController_EVGAGP102()
7979
{
80-
for(unsigned int i = 0; i < evga.size(); i++)
80+
for(unsigned int i = 0; i < controllers.size(); i++)
8181
{
82-
delete evga[i];
82+
delete controllers[i];
8383
}
8484
}
8585

@@ -91,19 +91,19 @@ void RGBController_EVGAGP102::SetupZones()
9191
| the backplate logo (K|NGP|N logo, or EVGA GeForce 1080 Ti |
9292
| for the FTW3).
9393
\*---------------------------------------------------------*/
94-
for(unsigned int i = 0; i < evga.size(); i++)
94+
for(unsigned int i = 0; i < controllers.size(); i++)
9595
{
9696
zone new_zone;
9797
led new_led;
9898

99-
new_zone.name = evga[i]->GetName();
99+
new_zone.name = controllers[i]->GetZoneName();
100100
new_zone.type = ZONE_TYPE_SINGLE;
101101
new_zone.leds_min = 1;
102102
new_zone.leds_max = 1;
103103
new_zone.leds_count = 1;
104104
new_zone.matrix_map = NULL;
105105

106-
new_led.name = evga[i]->GetName();
106+
new_led.name = controllers[i]->GetZoneName();
107107

108108
leds.push_back(new_led);
109109
zones.push_back(new_zone);
@@ -133,7 +133,7 @@ void RGBController_EVGAGP102::UpdateZoneLEDs(int zone)
133133
unsigned char red = RGBGetRValue(color);
134134
unsigned char grn = RGBGetGValue(color);
135135
unsigned char blu = RGBGetBValue(color);
136-
evga[zone]->SetColor(red, grn, blu);
136+
controllers[zone]->SetColor(red, grn, blu);
137137
}
138138

139139
void RGBController_EVGAGP102::UpdateSingleLED(int /*led*/)
@@ -143,9 +143,9 @@ void RGBController_EVGAGP102::UpdateSingleLED(int /*led*/)
143143

144144
void RGBController_EVGAGP102::DeviceUpdateMode()
145145
{
146-
for(unsigned int i = 0; i < evga.size(); i++)
146+
for(unsigned int i = 0; i < controllers.size(); i++)
147147
{
148-
evga[i]->SetMode((unsigned char)modes[(unsigned int)active_mode].value);
148+
controllers[i]->SetMode((unsigned char)modes[(unsigned int)active_mode].value);
149149
}
150150
}
151151

Controllers/EVGAGP102GPUController/RGBController_EVGAGP102.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
class RGBController_EVGAGP102 : public RGBController
1818
{
1919
public:
20-
RGBController_EVGAGP102(std::vector<EVGAGP102Controller*> evga_ptr);
20+
RGBController_EVGAGP102(std::vector<EVGAGP102Controller*> controller_list);
2121
~RGBController_EVGAGP102();
2222

2323
void SetupZones();
@@ -32,5 +32,5 @@ class RGBController_EVGAGP102 : public RGBController
3232
void DeviceSaveMode();
3333

3434
private:
35-
std::vector<EVGAGP102Controller*> evga;
35+
std::vector<EVGAGP102Controller*> controllers;
3636
};

0 commit comments

Comments
 (0)