Publish LumaOps source
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| super_io.cpp |
|
||||
| |
|
||||
| Functions for interfacing with Super-IO |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 11 Feb 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "super_io.h"
|
||||
|
||||
#if defined(_MACOSX_X86_X64)
|
||||
#include "macUSPCIOAccess.h"
|
||||
#elif defined(_WIN32)
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
int dev_port_fd;
|
||||
#endif
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* superio_enter *
|
||||
* *
|
||||
* Put the Super IO chip into Extended Function Mode *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void superio_enter(int ioreg)
|
||||
{
|
||||
#if defined(_MACOSX_X86_X64)
|
||||
WriteIoPortByte(ioreg, 0x87);
|
||||
WriteIoPortByte(ioreg, 0x87);
|
||||
#elif defined(_WIN32)
|
||||
/*-----------------------------------------------------*\
|
||||
| This function is not defined for Windows |
|
||||
| For 64-bit Windows, super_io_pawnio.cpp is used |
|
||||
| instead. For 32-bit Windows, this function provides|
|
||||
| a nonfunctional stub implementation. |
|
||||
\*-----------------------------------------------------*/
|
||||
#else
|
||||
unsigned char temp = 0x87;
|
||||
dev_port_fd = open("/dev/port", O_RDWR, "rw");
|
||||
|
||||
if (dev_port_fd >= 0)
|
||||
{
|
||||
lseek(dev_port_fd, ioreg, SEEK_SET);
|
||||
if(write(dev_port_fd, &temp, 1) == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lseek(dev_port_fd, ioreg, SEEK_SET);
|
||||
if(write(dev_port_fd, &temp, 1) == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
close(dev_port_fd);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* superio_outb *
|
||||
* *
|
||||
* Write a byte to the Super IO configuration register *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void superio_outb(int ioreg, int reg, int val)
|
||||
{
|
||||
#if defined(_MACOSX_X86_X64)
|
||||
WriteIoPortByte(ioreg, reg);
|
||||
WriteIoPortByte(ioreg + 1, val);
|
||||
#elif defined(_WIN32)
|
||||
/*-----------------------------------------------------*\
|
||||
| This function is not defined for Windows |
|
||||
| For 64-bit Windows, super_io_pawnio.cpp is used |
|
||||
| instead. For 32-bit Windows, this function provides|
|
||||
| a nonfunctional stub implementation. |
|
||||
\*-----------------------------------------------------*/
|
||||
#else
|
||||
dev_port_fd = open("/dev/port", O_RDWR, "rw");
|
||||
|
||||
if (dev_port_fd >= 0)
|
||||
{
|
||||
lseek(dev_port_fd, ioreg, SEEK_SET);
|
||||
if(write(dev_port_fd, ®, 1) == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(write(dev_port_fd, &val, 1) == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
close(dev_port_fd);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* superio_inb *
|
||||
* *
|
||||
* Read a byte to the Super IO configuration register *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
int superio_inb(int ioreg, int reg)
|
||||
{
|
||||
#if defined(_MACOSX_X86_X64)
|
||||
WriteIoPortByte(ioreg, reg);
|
||||
return ReadIoPortByte(ioreg + 1);
|
||||
#elif defined(_WIN32)
|
||||
/*-----------------------------------------------------*\
|
||||
| This function is not defined for Windows |
|
||||
| For 64-bit Windows, super_io_pawnio.cpp is used |
|
||||
| instead. For 32-bit Windows, this function provides|
|
||||
| a nonfunctional stub implementation. |
|
||||
\*-----------------------------------------------------*/
|
||||
return -1;
|
||||
#else
|
||||
unsigned char temp = 0;
|
||||
dev_port_fd = open("/dev/port", O_RDWR, "rw");
|
||||
|
||||
if (dev_port_fd >= 0)
|
||||
{
|
||||
lseek(dev_port_fd, ioreg, SEEK_SET);
|
||||
if(write(dev_port_fd, ®, 1) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(read(dev_port_fd, &temp, 1) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(dev_port_fd);
|
||||
|
||||
return((int)temp);
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| super_io.cpp |
|
||||
| |
|
||||
| Functions for interfacing with Super-IO |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 11 Feb 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* Nuvoton Super IO constants *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
#define SIO_NCT5577_ID 0xC330 /* Device ID for NCT5577D (C333) */
|
||||
#define SIO_NCT6102_ID 0x1060 /* Device ID for NCT6102D/6106D (1061) */
|
||||
#define SIO_NCT6793_ID 0xd120 /* Device ID for NCT6793D (D121) */
|
||||
#define SIO_NCT6795_ID 0xd350 /* Device ID for NCT6795D (D350) */
|
||||
#define SIO_NCT6796_ID 0xd420 /* Device ID for NCT6796D (D421) */
|
||||
#define SIO_NCT6797_ID 0xd450 /* Device ID for NCT6797D (D450) */
|
||||
#define SIO_NCT6798_ID 0xd428 /* Device ID for NCT6798D (D428) */
|
||||
#define SIO_ITE8688_ID 0x8688 /* Device ID for ITE8688 (8688) */
|
||||
#define SIO_REG_LOGDEV 0x07 /* Logical Device Register */
|
||||
#define SIO_REG_DEVID 0x20 /* Device ID Register */
|
||||
#define SIO_REG_SMBA 0x62 /* SMBus Base Address Register */
|
||||
#define SIO_LOGDEV_SMBUS 0x0B /* Logical Device for SMBus */
|
||||
#define SIO_ID_MASK 0xFFF8 /* Device ID mask */
|
||||
|
||||
void superio_enter(int ioreg);
|
||||
|
||||
void superio_outb(int ioreg, int reg, int val);
|
||||
|
||||
int superio_inb(int ioreg, int reg);
|
||||
@@ -0,0 +1,119 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| super_io_pawnio.cpp |
|
||||
| |
|
||||
| Functions for interfacing with Super-IO using PawnIO |
|
||||
| |
|
||||
| Stephen Horvath (Steve-Tech) 05 May 2025 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "super_io.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include "PawnIOLib.h"
|
||||
#include "i2c_smbus_pawnio.h"
|
||||
|
||||
static HANDLE pawnio_handle = NULL;
|
||||
|
||||
static int pawnio_chip_type = 0;
|
||||
|
||||
static int addr_to_pawnio(int addr)
|
||||
{
|
||||
switch (addr)
|
||||
{
|
||||
case 0x2E:
|
||||
return 0;
|
||||
case 0x4E:
|
||||
return 1;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* pawnio_superio_enter *
|
||||
* *
|
||||
* Put the Super IO chip into Extended Function Mode *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void superio_enter(int ioreg)
|
||||
{
|
||||
HRESULT status;
|
||||
SIZE_T return_size;
|
||||
|
||||
if (pawnio_handle == NULL)
|
||||
{
|
||||
status = i2c_smbus_pawnio::start_pawnio("superio", &pawnio_handle);
|
||||
if (status != S_OK)
|
||||
{
|
||||
// TODO: Figure out how to handle errors
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (pawnio_chip_type == 0)
|
||||
{
|
||||
int in_reg = addr_to_pawnio(ioreg);
|
||||
if (in_reg == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
const SIZE_T in_size = 1;
|
||||
ULONG64 in[in_size] = {(ULONG64)in_reg};
|
||||
const SIZE_T out_size = 1;
|
||||
ULONG64 out[out_size];
|
||||
status = pawnio_execute(pawnio_handle, "ioctl_detect", in, in_size, out, out_size, &return_size);
|
||||
if (status != S_OK || out[0] == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pawnio_chip_type = (int)out[0];
|
||||
}
|
||||
|
||||
pawnio_execute(pawnio_handle, "ioctl_enter", NULL, 0, NULL, 0, &return_size);
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* pawnio_superio_outb *
|
||||
* *
|
||||
* Write a byte to the Super IO configuration register *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void superio_outb([[maybe_unused]] int ioreg, int reg, int val)
|
||||
{
|
||||
const SIZE_T in_size = 2;
|
||||
ULONG64 in[in_size] = {(ULONG64)reg, (ULONG64)val};
|
||||
SIZE_T return_size;
|
||||
pawnio_execute(pawnio_handle, "ioctl_write", in, in_size, NULL, 0, &return_size);
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* pawnio_superio_inb *
|
||||
* *
|
||||
* Read a byte from the Super IO configuration register *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
int superio_inb([[maybe_unused]] int ioreg, int reg)
|
||||
{
|
||||
const SIZE_T in_size = 1;
|
||||
ULONG64 in[in_size] = {(ULONG64)reg};
|
||||
const SIZE_T out_size = 1;
|
||||
ULONG64 out[out_size];
|
||||
SIZE_T return_size;
|
||||
HRESULT status = pawnio_execute(pawnio_handle, "ioctl_read", in, in_size, out, out_size, &return_size);
|
||||
if (status != S_OK)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return (int)out[0];
|
||||
}
|
||||
Reference in New Issue
Block a user