From 6369968a3167860c89e31ff7ebd8342c9dd81b1e Mon Sep 17 00:00:00 2001 From: gxcreator Date: Mon, 15 Nov 2021 05:42:08 +0300 Subject: [PATCH] Added initial Palit GPU 30xx support --- .../PNYGPUController/PNYGPUController.cpp | 54 ++++++++++++-- .../PNYGPUController/PNYGPUController.h | 22 ++++-- .../PNYGPUControllerDetect.cpp | 40 +++++++++- .../PNYGPUController/RGBController_PNYGPU.cpp | 73 ++++++++++++++++--- pci_ids/pci_ids.h | 20 +++++ 5 files changed, 177 insertions(+), 32 deletions(-) diff --git a/Controllers/PNYGPUController/PNYGPUController.cpp b/Controllers/PNYGPUController/PNYGPUController.cpp index cc67e5d22..296deb36b 100644 --- a/Controllers/PNYGPUController/PNYGPUController.cpp +++ b/Controllers/PNYGPUController/PNYGPUController.cpp @@ -30,6 +30,15 @@ std::string PNYGPUController::GetDeviceLocation() return("I2C: " + return_string); } +void PNYGPUController::WriteI2CData(u8 command, u8 length, u8* data) +{ + //Simulating i2c_smbus_write_i2c_block_data(command, length, data); + for (u8 i = 0; i < length; i++) + { + bus->i2c_smbus_write_byte_data(dev, command+i, data[i]); + } +} + unsigned char PNYGPUController::GetMode() { return(bus->i2c_smbus_read_byte_data(dev, PNY_GPU_MODE_OFF)); @@ -50,17 +59,46 @@ unsigned char PNYGPUController::GetBlue() return(bus->i2c_smbus_read_byte_data(dev, PNY_GPU_REG_COLOR_BLUE)); } -void PNYGPUController::SetColor(unsigned char red, unsigned char green, unsigned char blue) +void PNYGPUController::SetOff() { - bus->i2c_smbus_write_byte_data(dev, 0xE0, 0x00); + bus->i2c_smbus_write_byte_data(dev, PNY_GPU_REG_CONTROL, 0); + bus->i2c_smbus_write_byte_data(dev, PNY_GPU_REG_MODE, 0x00); +} + +void PNYGPUController::SetCycle(unsigned char speed) +{ + u8 loop[] = { + 0x01, // Direction + 0x00, // ?? + speed, // Speed + 0x1F // Somehow related to speed + }; + loop[2] = speed; + WriteI2CData(PNY_GPU_REG_CONTROL, sizeof(loop), loop); +} + +void PNYGPUController::SetStrobe(unsigned char r, unsigned char g, unsigned char b, unsigned char speed, unsigned char brightness) +{ + u8 strobe[] = { + 0x02, // Strobe + 0x00, // Rise speed + speed, // Cycle length/2 + 0x00, // Off delay + r, // R + g, // G + b, // B + brightness, // Peak brightness + 0x05 // Fade speed + }; + WriteI2CData(PNY_GPU_REG_CONTROL, sizeof(strobe), strobe); +} + +void PNYGPUController::SetDirect(unsigned char red, unsigned char green, unsigned char blue, unsigned char brightness) +{ + bus->i2c_smbus_write_byte_data(dev, PNY_GPU_REG_CONTROL, 0); bus->i2c_smbus_write_byte_data(dev, PNY_GPU_REG_MODE, 0x01); bus->i2c_smbus_write_byte_data(dev, PNY_GPU_REG_COLOR_RED, red); bus->i2c_smbus_write_byte_data(dev, PNY_GPU_REG_COLOR_BLUE, blue); bus->i2c_smbus_write_byte_data(dev, PNY_GPU_REG_COLOR_GREEN, green); - bus->i2c_smbus_write_byte_data(dev, PNY_GPU_REG_COLOR_BRIGHTNESS, 0x64); -} - -void PNYGPUController::SetMode(unsigned char mode) -{ - bus->i2c_smbus_write_byte_data(dev, PNY_GPU_REG_MODE, mode); + bus->i2c_smbus_write_byte_data(dev, PNY_GPU_REG_COLOR_BRIGHTNESS, brightness); } diff --git a/Controllers/PNYGPUController/PNYGPUController.h b/Controllers/PNYGPUController/PNYGPUController.h index d92fe996e..b1b3a0244 100644 --- a/Controllers/PNYGPUController/PNYGPUController.h +++ b/Controllers/PNYGPUController/PNYGPUController.h @@ -16,6 +16,7 @@ typedef unsigned char pny_dev_id; enum { + PNY_GPU_REG_CONTROL = 0xE0, PNY_GPU_REG_MODE = 0x60, PNY_GPU_REG_COLOR_RED = 0x6C, PNY_GPU_REG_COLOR_GREEN = 0x6D, @@ -26,7 +27,9 @@ enum enum { PNY_GPU_MODE_OFF = 0x00, - PNY_GPU_MODE_CUSTOM = 0x01, + PNY_GPU_MODE_DIRECT = 0x01, + PNY_GPU_MODE_CYCLE = 0x02, + PNY_GPU_MODE_STROBE = 0x03, }; class PNYGPUController @@ -37,16 +40,19 @@ public: std::string GetDeviceLocation(); - unsigned char GetMode(); - unsigned char GetRed(); - unsigned char GetGreen(); - unsigned char GetBlue(); - - void SetColor(unsigned char red, unsigned char green, unsigned char blue); - void SetMode(unsigned char mode); + void SetOff(); + void SetCycle(unsigned char speed); + void SetStrobe(unsigned char r, unsigned char g, unsigned char b, unsigned char speed, unsigned char brightness); + void SetDirect(unsigned char red, unsigned char green, unsigned char blue, unsigned char brightness); private: i2c_smbus_interface* bus; pny_dev_id dev; + void WriteI2CData(u8 command, u8 length, u8* data); + unsigned char GetMode(); + unsigned char GetRed(); + unsigned char GetGreen(); + unsigned char GetBlue(); + }; diff --git a/Controllers/PNYGPUController/PNYGPUControllerDetect.cpp b/Controllers/PNYGPUController/PNYGPUControllerDetect.cpp index 918d813d8..cd9b4f77d 100644 --- a/Controllers/PNYGPUController/PNYGPUControllerDetect.cpp +++ b/Controllers/PNYGPUController/PNYGPUControllerDetect.cpp @@ -25,9 +25,28 @@ typedef struct #define GPU_NUM_DEVICES (sizeof(device_list) / sizeof(device_list[ 0 ])) +#define PNY_SUB_VEN_STR "PNY" +#define PALIT_SUB_VEN_STR "Palit" +#define GENERIC_SUB_VEN_STR "Generic" + static const gpu_pci_device device_list[] = { - { NVIDIA_VEN, NVIDIA_RTX3090_DEV, PNY_SUB_VEN, PNY_RTX_3090_XLR8_REVEL_EPIC_X_SUB_DEV, PNY_RGB, "PNY XLR8 Revel EPIC-X RTX 3090" }, + { NVIDIA_VEN, NVIDIA_RTX3090_DEV, PNY_SUB_VEN, PNY_RTX_3090_XLR8_REVEL_EPIC_X_SUB_DEV, PNY_RGB, "PNY XLR8 Revel EPIC-X RTX 3090" }, + { NVIDIA_VEN, NVIDIA_RTX3060_DEV, PALIT_SUB_VEN, PALIT_RTX3060_SUB_DEV, PNY_RGB, "Palit 3060" }, + { NVIDIA_VEN, NVIDIA_RTX3060_LHR_DEV, PALIT_SUB_VEN, PALIT_RTX3060_LHR_SUB_DEV, PNY_RGB, "Palit 3060 LHR" }, + + { NVIDIA_VEN, NVIDIA_RTX3060TI_DEV, PALIT_SUB_VEN, PALIT_RTX3060TI_SUB_DEV, PNY_RGB, "Palit 3060Ti" }, + { NVIDIA_VEN, NVIDIA_RTX3060TI_LHR_DEV, PALIT_SUB_VEN, PALIT_RTX3060TI_LHR_SUB_DEV, PNY_RGB, "Palit 3060Ti" }, + + { NVIDIA_VEN, NVIDIA_RTX3070_DEV, PALIT_SUB_VEN, PALIT_RTX3070_SUB_DEV, PNY_RGB, "Palit 3070" }, + { NVIDIA_VEN, NVIDIA_RTX3070_LHR_DEV, PALIT_SUB_VEN, PALIT_RTX3070_LHR_SUB_DEV, PNY_RGB, "Palit 3070 LHR" }, + { NVIDIA_VEN, NVIDIA_RTX3070TI_DEV, PALIT_SUB_VEN, PALIT_RTX3070TI_SUB_DEV, PNY_RGB, "Palit 3070Ti" }, + + { NVIDIA_VEN, NVIDIA_RTX3080_DEV, PALIT_SUB_VEN, PALIT_RTX3080_SUB_DEV, PNY_RGB, "Palit 3080" }, + { NVIDIA_VEN, NVIDIA_RTX3080_LHR_DEV, PALIT_SUB_VEN, PALIT_RTX3080_LHR_SUB_DEV, PNY_RGB, "Palit 3080 LHR" }, + { NVIDIA_VEN, NVIDIA_RTX3080TI_DEV, PALIT_SUB_VEN, PALIT_RTX3080TI_SUB_DEV, PNY_RGB, "Palit 3080Ti" }, + + { NVIDIA_VEN, NVIDIA_RTX3090_DEV, PALIT_SUB_VEN, PALIT_RTX3090_SUB_DEV, PNY_RGB, "Palit 3090" } }; /******************************************************************************************\ @@ -64,9 +83,22 @@ void DetectPNYGPUControllers(std::vector& busses) PNYGPUController* new_controller; RGBController_PNYGPU* new_rgbcontroller; - new_controller = new PNYGPUController(busses[bus], 0x49); - new_rgbcontroller = new RGBController_PNYGPU(new_controller); - new_rgbcontroller->name = device_list[dev_idx].name; + new_controller = new PNYGPUController(busses[bus], 0x49); + new_rgbcontroller = new RGBController_PNYGPU(new_controller); + new_rgbcontroller->name = device_list[dev_idx].name; + switch(device_list[dev_idx].pci_subsystem_vendor) + { + case PNY_SUB_VEN: + new_rgbcontroller->vendor = PNY_SUB_VEN_STR; + break; + + case PALIT_SUB_VEN: + new_rgbcontroller->vendor = PALIT_SUB_VEN_STR; + break; + default: + new_rgbcontroller->vendor = GENERIC_SUB_VEN_STR; + break; + } ResourceManager::get()->RegisterRGBController(new_rgbcontroller); } break; diff --git a/Controllers/PNYGPUController/RGBController_PNYGPU.cpp b/Controllers/PNYGPUController/RGBController_PNYGPU.cpp index e8cac47ec..26aebc617 100644 --- a/Controllers/PNYGPUController/RGBController_PNYGPU.cpp +++ b/Controllers/PNYGPUController/RGBController_PNYGPU.cpp @@ -13,9 +13,9 @@ RGBController_PNYGPU::RGBController_PNYGPU(PNYGPUController* pny_ptr) { pny = pny_ptr; - name = "PNY GPU"; - vendor = "PNY"; - description = "PNY RGB GPU Device"; + name = "PNY/Palit GPU"; + vendor = "PNY/Palit"; + description = "PNY/Palit RGB GPU Device"; location = pny->GetDeviceLocation(); type = DEVICE_TYPE_GPU; @@ -29,11 +29,37 @@ RGBController_PNYGPU::RGBController_PNYGPU(PNYGPUController* pny_ptr) mode Direct; Direct.name = "Direct"; - Direct.value = PNY_GPU_MODE_CUSTOM; - Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Direct.value = PNY_GPU_MODE_DIRECT; + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR| MODE_FLAG_HAS_BRIGHTNESS; + Direct.brightness = 255; + Direct.brightness_min = 0; + Direct.brightness_max = 100; Direct.color_mode = MODE_COLORS_PER_LED; modes.push_back(Direct); + mode Cycle; + Cycle.name = "Cycle"; + Cycle.value = PNY_GPU_MODE_CYCLE; + Cycle.flags = MODE_FLAG_HAS_SPEED; + Cycle.speed = 3; + Cycle.speed_max = 0; + Cycle.speed_max = 100; + Cycle.color_mode = MODE_COLORS_PER_LED; + modes.push_back(Cycle); + + mode Strobe; + Strobe.name = "Strobe"; + Strobe.value = PNY_GPU_MODE_STROBE; + Strobe.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS; + Strobe.speed = 2; + Strobe.speed_max = 0; + Strobe.speed_max = 255; + Strobe.brightness = 255; + Strobe.brightness_min = 0; + Strobe.brightness_max = 100; + Strobe.color_mode = MODE_COLORS_PER_LED; + modes.push_back(Strobe); + SetupZones(); @@ -76,12 +102,7 @@ void RGBController_PNYGPU::ResizeZone(int /*zone*/, int /*new_size*/) void RGBController_PNYGPU::DeviceUpdateLEDs() { - RGBColor color = colors[0]; - unsigned char red = RGBGetRValue(color); - unsigned char grn = RGBGetGValue(color); - unsigned char blu = RGBGetBValue(color); - - pny->SetColor(red, grn, blu); + DeviceUpdateMode(); } void RGBController_PNYGPU::UpdateZoneLEDs(int /*zone*/) @@ -101,5 +122,33 @@ void RGBController_PNYGPU::SetCustomMode() void RGBController_PNYGPU::DeviceUpdateMode() { - pny->SetMode((unsigned char)modes[(unsigned int)active_mode].value); + RGBColor color = colors[0]; + unsigned char r = RGBGetRValue(color); + unsigned char g = RGBGetGValue(color); + unsigned char b = RGBGetBValue(color); + unsigned char speed, brightness; + switch(modes[active_mode].value) + { + case PNY_GPU_MODE_OFF: + pny->SetOff(); + break; + + case PNY_GPU_MODE_DIRECT: + brightness = modes[active_mode].brightness; + pny->SetDirect(r, g, b, brightness); + break; + + case PNY_GPU_MODE_CYCLE: + speed = modes[active_mode].speed; + pny->SetCycle(speed); + break; + + case PNY_GPU_MODE_STROBE: + speed = modes[active_mode].speed; + brightness = modes[active_mode].brightness; + pny->SetStrobe(r, g, b, speed, brightness); + break; + default: + break; + } } diff --git a/pci_ids/pci_ids.h b/pci_ids/pci_ids.h index e8b4bd53a..919da1b67 100644 --- a/pci_ids/pci_ids.h +++ b/pci_ids/pci_ids.h @@ -90,6 +90,7 @@ #define MSI_SUB_VEN 0x1462 #define NVIDIA_SUB_VEN 0x10DE #define PNY_SUB_VEN 0x196E +#define PALIT_SUB_VEN 0x1569 #define SAPPHIRE_SUB_VEN 0x1DA2 #define SAPPHIRE_LEGACY_SUB_VEN 0x174B #define ZOTAC_SUB_VEN 0x19DA @@ -298,6 +299,25 @@ \*-----------------------------------------------------*/ #define PNY_RTX_3090_XLR8_REVEL_EPIC_X_SUB_DEV 0x136A +/*-----------------------------------------------------*\ +| Palit Sub-Device IDs | +\*-----------------------------------------------------*/ +#define PALIT_RTX3060_SUB_DEV 0x2503 +#define PALIT_RTX3060_LHR_SUB_DEV 0x2504 + +#define PALIT_RTX3060TI_SUB_DEV 0x2486 +#define PALIT_RTX3060TI_LHR_SUB_DEV 0x2489 + +#define PALIT_RTX3070_SUB_DEV 0x2484 +#define PALIT_RTX3070_LHR_SUB_DEV 0x2488 +#define PALIT_RTX3070TI_SUB_DEV 0xF278 + +#define PALIT_RTX3080_SUB_DEV 0x2206 +#define PALIT_RTX3080_LHR_SUB_DEV 0x2216 +#define PALIT_RTX3080TI_SUB_DEV 0x2208 + +#define PALIT_RTX3090_SUB_DEV 0x2204 + /*-----------------------------------------------------*\ | Sapphire Sub-Device IDs | \*-----------------------------------------------------*/