Rework EVGAPascalGPUController to use I2C PCI detector and store name in controller to avoid setting it in detector

This commit is contained in:
Adam Honse 2025-08-07 22:39:49 -05:00
parent c32663bb32
commit df75659778
5 changed files with 55 additions and 82 deletions

View file

@ -11,10 +11,11 @@
#include "EVGAGPUv1Controller.h" #include "EVGAGPUv1Controller.h"
EVGAGPUv1Controller::EVGAGPUv1Controller(i2c_smbus_interface* bus, evga_dev_id dev) EVGAGPUv1Controller::EVGAGPUv1Controller(i2c_smbus_interface* bus, evga_dev_id dev, std::string dev_name)
{ {
this->bus = bus; this->bus = bus;
this->dev = dev; this->dev = dev;
this->name = dev_name;
} }
EVGAGPUv1Controller::~EVGAGPUv1Controller() EVGAGPUv1Controller::~EVGAGPUv1Controller()
@ -32,6 +33,11 @@ std::string EVGAGPUv1Controller::GetDeviceLocation()
return("I2C: " + return_string); return("I2C: " + return_string);
} }
std::string EVGAGPUv1Controller::GetDeviceName()
{
return(name);
}
unsigned char EVGAGPUv1Controller::GetMode() unsigned char EVGAGPUv1Controller::GetMode()
{ {
return(bus->i2c_smbus_read_byte_data(dev, EVGA_GPU_V1_REG_MODE)); return(bus->i2c_smbus_read_byte_data(dev, EVGA_GPU_V1_REG_MODE));

View file

@ -37,10 +37,11 @@ enum
class EVGAGPUv1Controller class EVGAGPUv1Controller
{ {
public: public:
EVGAGPUv1Controller(i2c_smbus_interface* bus, evga_dev_id dev); EVGAGPUv1Controller(i2c_smbus_interface* bus, evga_dev_id dev, std::string dev_name);
~EVGAGPUv1Controller(); ~EVGAGPUv1Controller();
std::string GetDeviceLocation(); std::string GetDeviceLocation();
std::string GetDeviceName();
unsigned char GetMode(); unsigned char GetMode();
unsigned char GetRed(); unsigned char GetRed();
@ -54,4 +55,5 @@ public:
private: private:
i2c_smbus_interface* bus; i2c_smbus_interface* bus;
evga_dev_id dev; evga_dev_id dev;
std::string name;
}; };

View file

@ -9,7 +9,6 @@
| SPDX-License-Identifier: GPL-2.0-only | | SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
#include <vector>
#include "Detector.h" #include "Detector.h"
#include "EVGAGPUv1Controller.h" #include "EVGAGPUv1Controller.h"
#include "LogManager.h" #include "LogManager.h"
@ -17,25 +16,6 @@
#include "i2c_smbus.h" #include "i2c_smbus.h"
#include "pci_ids.h" #include "pci_ids.h"
typedef struct
{
int pci_vendor;
int pci_device;
int pci_subsystem_vendor;
int pci_subsystem_device;
const char * name;
} gpu_pci_device;
#define GPU_NUM_DEVICES (sizeof(device_list) / sizeof(device_list[ 0 ]))
static const gpu_pci_device device_list[] =
{
{ NVIDIA_VEN, NVIDIA_GTX1070_DEV, EVGA_SUB_VEN, EVGA_GTX1070_FTW_DT_GAMING_SUB_DEV, "EVGA GeForce GTX 1070 FTW DT Gaming" },
{ NVIDIA_VEN, NVIDIA_GTX1070_DEV, EVGA_SUB_VEN, EVGA_GTX1070_FTW_SUB_DEV, "EVGA GeForce GTX 1070 FTW" },
{ NVIDIA_VEN, NVIDIA_GTX1070_DEV, EVGA_SUB_VEN, EVGA_GTX1070_FTW_HYBRID_SUB_DEV, "EVGA GeForce GTX 1070 FTW HYBRID" },
{ NVIDIA_VEN, NVIDIA_GTX1070TI_DEV, EVGA_SUB_VEN, EVGA_GTX1070TI_FTW2_SUB_DEV, "EVGA GeForce GTX 1070 Ti FTW2" },
{ NVIDIA_VEN, NVIDIA_GTX1080_DEV, EVGA_SUB_VEN, EVGA_GTX1080_FTW_SUB_DEV, "EVGA GeForce GTX 1080 FTW" },
};
/******************************************************************************************\ /******************************************************************************************\
* * * *
* DetectEVGAGPUControllers * * DetectEVGAGPUControllers *
@ -47,33 +27,19 @@ static const gpu_pci_device device_list[] =
* * * *
\******************************************************************************************/ \******************************************************************************************/
void DetectEVGAPascalGPUControllers(std::vector<i2c_smbus_interface*>& busses) void DetectEVGAPascalGPUControllers(i2c_smbus_interface* bus, uint8_t address, const std::string& name)
{ {
for (unsigned int bus = 0; bus < busses.size(); bus++) if(bus->port_id == 1)
{ {
for(unsigned int dev_idx = 0; dev_idx < GPU_NUM_DEVICES; dev_idx++) EVGAGPUv1Controller* controller = new EVGAGPUv1Controller(bus, address, name);
{ RGBController_EVGAGPUv1* rgb_controller = new RGBController_EVGAGPUv1(controller);
if (busses[bus]->port_id != 1)
{
break;
}
if(busses[bus]->pci_vendor == device_list[dev_idx].pci_vendor && ResourceManager::get()->RegisterRGBController(rgb_controller);
busses[bus]->pci_device == device_list[dev_idx].pci_device &&
busses[bus]->pci_subsystem_vendor == device_list[dev_idx].pci_subsystem_vendor &&
busses[bus]->pci_subsystem_device == device_list[dev_idx].pci_subsystem_device)
{
LOG_DEBUG(GPU_DETECT_MESSAGE, EVGAGPUV1_CONTROLLER_NAME, bus, device_list[dev_idx].pci_device, device_list[dev_idx].pci_subsystem_device, device_list[dev_idx].name );
EVGAGPUv1Controller* new_controller;
RGBController_EVGAGPUv1* new_rgbcontroller;
new_controller = new EVGAGPUv1Controller(busses[bus], 0x49);
new_rgbcontroller = new RGBController_EVGAGPUv1(new_controller);
new_rgbcontroller->name = device_list[dev_idx].name;
ResourceManager::get()->RegisterRGBController(new_rgbcontroller);
}
}
} }
} /* DetectEVGAPascalGPUControllers() */ } /* DetectEVGAPascalGPUControllers() */
REGISTER_I2C_DETECTOR("EVGA Pascal GPU", DetectEVGAPascalGPUControllers); REGISTER_I2C_PCI_DETECTOR("EVGA GeForce GTX 1070 FTW DT Gaming", DetectEVGAPascalGPUControllers, NVIDIA_VEN, NVIDIA_GTX1070_DEV, EVGA_SUB_VEN, EVGA_GTX1070_FTW_DT_GAMING_SUB_DEV, 0x49);
REGISTER_I2C_PCI_DETECTOR("EVGA GeForce GTX 1070 FTW", DetectEVGAPascalGPUControllers, NVIDIA_VEN, NVIDIA_GTX1070_DEV, EVGA_SUB_VEN, EVGA_GTX1070_FTW_SUB_DEV, 0x49);
REGISTER_I2C_PCI_DETECTOR("EVGA GeForce GTX 1070 FTW HYBRID", DetectEVGAPascalGPUControllers, NVIDIA_VEN, NVIDIA_GTX1070_DEV, EVGA_SUB_VEN, EVGA_GTX1070_FTW_HYBRID_SUB_DEV, 0x49);
REGISTER_I2C_PCI_DETECTOR("EVGA GeForce GTX 1070 Ti FTW2", DetectEVGAPascalGPUControllers, NVIDIA_VEN, NVIDIA_GTX1070TI_DEV, EVGA_SUB_VEN, EVGA_GTX1070TI_FTW2_SUB_DEV, 0x49);
REGISTER_I2C_PCI_DETECTOR("EVGA GeForce GTX 1080 FTW", DetectEVGAPascalGPUControllers, NVIDIA_VEN, NVIDIA_GTX1080_DEV, EVGA_SUB_VEN, EVGA_GTX1080_FTW_SUB_DEV, 0x49);

View file

@ -22,50 +22,49 @@
@comment @comment
\*-------------------------------------------------------------------*/ \*-------------------------------------------------------------------*/
RGBController_EVGAGPUv1::RGBController_EVGAGPUv1(EVGAGPUv1Controller* evga_ptr) RGBController_EVGAGPUv1::RGBController_EVGAGPUv1(EVGAGPUv1Controller* controller_ptr)
{ {
evga = evga_ptr; controller = controller_ptr;
name = "EVGA GPU"; name = controller->GetDeviceName();
vendor = "EVGA"; vendor = "EVGA";
description = "EVGA RGB v1 GPU Device"; description = "EVGA RGB v1 GPU Device";
location = evga->GetDeviceLocation(); location = controller->GetDeviceLocation();
type = DEVICE_TYPE_GPU;
type = DEVICE_TYPE_GPU;
mode Off; mode Off;
Off.name = "Off"; Off.name = "Off";
Off.value = EVGA_GPU_V1_MODE_OFF; Off.value = EVGA_GPU_V1_MODE_OFF;
Off.flags = MODE_FLAG_MANUAL_SAVE; Off.flags = MODE_FLAG_MANUAL_SAVE;
Off.color_mode = MODE_COLORS_NONE; Off.color_mode = MODE_COLORS_NONE;
modes.push_back(Off); modes.push_back(Off);
mode Direct; mode Direct;
Direct.name = "Direct"; Direct.name = "Direct";
Direct.value = EVGA_GPU_V1_MODE_CUSTOM; Direct.value = EVGA_GPU_V1_MODE_CUSTOM;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_MANUAL_SAVE; Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_MANUAL_SAVE;
Direct.color_mode = MODE_COLORS_PER_LED; Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct); modes.push_back(Direct);
mode Rainbow; mode Rainbow;
Rainbow.name = "Rainbow"; Rainbow.name = "Rainbow";
Rainbow.value = EVGA_GPU_V1_MODE_RAINBOW; Rainbow.value = EVGA_GPU_V1_MODE_RAINBOW;
Rainbow.flags = MODE_FLAG_MANUAL_SAVE; Rainbow.flags = MODE_FLAG_MANUAL_SAVE;
Rainbow.color_mode = MODE_COLORS_NONE; Rainbow.color_mode = MODE_COLORS_NONE;
modes.push_back(Rainbow); modes.push_back(Rainbow);
mode Breathing; mode Breathing;
Breathing.name = "Breathing"; Breathing.name = "Breathing";
Breathing.value = EVGA_GPU_V1_MODE_BREATHING; Breathing.value = EVGA_GPU_V1_MODE_BREATHING;
Breathing.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_MANUAL_SAVE; Breathing.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_MANUAL_SAVE;
Breathing.color_mode = MODE_COLORS_PER_LED; Breathing.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Breathing); modes.push_back(Breathing);
SetupZones(); SetupZones();
// Initialize active mode and stored color // Initialize active mode and stored color
unsigned char raw_active_mode = evga->GetMode(); unsigned char raw_active_mode = controller->GetMode();
active_mode = 0; active_mode = 0;
for(unsigned int i = 0; i < modes.size(); i++) for(unsigned int i = 0; i < modes.size(); i++)
@ -77,9 +76,9 @@ RGBController_EVGAGPUv1::RGBController_EVGAGPUv1(EVGAGPUv1Controller* evga_ptr)
} }
} }
unsigned char r = evga->GetRed(); unsigned char r = controller->GetRed();
unsigned char g = evga->GetGreen(); unsigned char g = controller->GetGreen();
unsigned char b = evga->GetBlue(); unsigned char b = controller->GetBlue();
RGBColor color = ToRGBColor(r, g, b); RGBColor color = ToRGBColor(r, g, b);
colors[0] = color; colors[0] = color;
@ -87,7 +86,7 @@ RGBController_EVGAGPUv1::RGBController_EVGAGPUv1(EVGAGPUv1Controller* evga_ptr)
RGBController_EVGAGPUv1::~RGBController_EVGAGPUv1() RGBController_EVGAGPUv1::~RGBController_EVGAGPUv1()
{ {
delete evga; delete controller;
} }
void RGBController_EVGAGPUv1::SetupZones() void RGBController_EVGAGPUv1::SetupZones()
@ -131,7 +130,7 @@ void RGBController_EVGAGPUv1::DeviceUpdateLEDs()
unsigned char grn = RGBGetGValue(color); unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color); unsigned char blu = RGBGetBValue(color);
evga->SetColor(red, grn, blu); controller->SetColor(red, grn, blu);
} }
void RGBController_EVGAGPUv1::UpdateZoneLEDs(int /*zone*/) void RGBController_EVGAGPUv1::UpdateZoneLEDs(int /*zone*/)
@ -146,10 +145,10 @@ void RGBController_EVGAGPUv1::UpdateSingleLED(int /*led*/)
void RGBController_EVGAGPUv1::DeviceUpdateMode() void RGBController_EVGAGPUv1::DeviceUpdateMode()
{ {
evga->SetMode((unsigned char)modes[(unsigned int)active_mode].value); controller->SetMode((unsigned char)modes[(unsigned int)active_mode].value);
} }
void RGBController_EVGAGPUv1::DeviceSaveMode() void RGBController_EVGAGPUv1::DeviceSaveMode()
{ {
evga->SaveSettings(); controller->SaveSettings();
} }

View file

@ -17,7 +17,7 @@
class RGBController_EVGAGPUv1 : public RGBController class RGBController_EVGAGPUv1 : public RGBController
{ {
public: public:
RGBController_EVGAGPUv1(EVGAGPUv1Controller* evga_ptr); RGBController_EVGAGPUv1(EVGAGPUv1Controller* controller_ptr);
~RGBController_EVGAGPUv1(); ~RGBController_EVGAGPUv1();
void SetupZones(); void SetupZones();
@ -32,5 +32,5 @@ public:
void DeviceSaveMode(); void DeviceSaveMode();
private: private:
EVGAGPUv1Controller* evga; EVGAGPUv1Controller* controller;
}; };