|
|
|
|
@ -23,11 +23,52 @@ std::unordered_map<std::string, int> i2c_smbus_pawnio::using_handle;
|
|
|
|
|
i2c_smbus_pawnio::i2c_smbus_pawnio(HANDLE handle, std::string name)
|
|
|
|
|
{
|
|
|
|
|
/*-----------------------------------------------------*\
|
|
|
|
|
| Store bus information |
|
|
|
|
|
| TODO: Remove name field once all drivers use the same |
|
|
|
|
|
| ioctl names |
|
|
|
|
|
\*-----------------------------------------------------*/
|
|
|
|
|
this->handle = handle;
|
|
|
|
|
this->name = name;
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------*\
|
|
|
|
|
| Get driver settings |
|
|
|
|
|
\*-----------------------------------------------------*/
|
|
|
|
|
json drivers_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Drivers");
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------*\
|
|
|
|
|
| Get bus information |
|
|
|
|
|
\*-----------------------------------------------------*/
|
|
|
|
|
const SIZE_T in_size = 1;
|
|
|
|
|
ULONG64 in[in_size] = {0};
|
|
|
|
|
const SIZE_T out_size = 3;
|
|
|
|
|
ULONG64 out[out_size];
|
|
|
|
|
SIZE_T return_size;
|
|
|
|
|
HRESULT status;
|
|
|
|
|
|
|
|
|
|
status = pawnio_execute(handle, "ioctl_identity", in, in_size, out, out_size, &return_size);
|
|
|
|
|
|
|
|
|
|
if(!status)
|
|
|
|
|
{
|
|
|
|
|
this->pci_vendor = (out[2] & 0x000000000000FFFF);
|
|
|
|
|
this->pci_device = (out[2] & 0x00000000FFFF0000) >> 16;
|
|
|
|
|
this->pci_subsystem_vendor = (out[2] & 0x0000FFFF0000FFFF) >> 32;
|
|
|
|
|
this->pci_subsystem_device = (out[2] & 0xFFFF000000000000) >> 48;
|
|
|
|
|
|
|
|
|
|
char name_str[9];
|
|
|
|
|
name_str[0] = (out[0] & 0x00000000000000FF);
|
|
|
|
|
name_str[1] = (out[0] & 0x000000000000FF00) >> 8;
|
|
|
|
|
name_str[2] = (out[0] & 0x0000000000FF0000) >> 16;
|
|
|
|
|
name_str[3] = (out[0] & 0x00000000FF000000) >> 24;
|
|
|
|
|
name_str[4] = (out[0] & 0x000000FF00000000) >> 32;
|
|
|
|
|
name_str[5] = (out[0] & 0x0000FF0000000000) >> 40;
|
|
|
|
|
name_str[6] = (out[0] & 0x00FF000000000000) >> 48;
|
|
|
|
|
name_str[7] = (out[0] & 0xFF00000000000000) >> 56;
|
|
|
|
|
name_str[8] = 0;
|
|
|
|
|
|
|
|
|
|
strncpy( this->device_name, name_str, 512 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------*\
|
|
|
|
|
| Get shared SMBus access setting |
|
|
|
|
|
\*-----------------------------------------------------*/
|
|
|
|
|
bool shared_smbus_access = true;
|
|
|
|
|
@ -45,14 +86,6 @@ i2c_smbus_pawnio::i2c_smbus_pawnio(HANDLE handle, std::string name)
|
|
|
|
|
global_smbus_access_handle = CreateMutexA(NULL, FALSE, GLOBAL_SMBUS_MUTEX_NAME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------*\
|
|
|
|
|
| Store bus information |
|
|
|
|
|
| TODO: Remove name field once all drivers use the same |
|
|
|
|
|
| ioctl names |
|
|
|
|
|
\*-----------------------------------------------------*/
|
|
|
|
|
this->handle = handle;
|
|
|
|
|
this->name = name;
|
|
|
|
|
|
|
|
|
|
using_handle[name]++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -75,207 +108,52 @@ i2c_smbus_pawnio::~i2c_smbus_pawnio()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 i2c_smbus_pawnio::pawnio_read(u8 addr, char /*read_write*/, u8 command, int size, i2c_smbus_data* data)
|
|
|
|
|
s32 i2c_smbus_pawnio::i2c_smbus_xfer(u8 addr, char read_write, u8 command, int size, i2c_smbus_data* data)
|
|
|
|
|
{
|
|
|
|
|
SIZE_T return_size;
|
|
|
|
|
|
|
|
|
|
switch(size)
|
|
|
|
|
/*-----------------------------------------------------*\
|
|
|
|
|
| Lock SMBus mutex |
|
|
|
|
|
\*-----------------------------------------------------*/
|
|
|
|
|
if(global_smbus_access_handle != NULL)
|
|
|
|
|
{
|
|
|
|
|
case I2C_SMBUS_BYTE:
|
|
|
|
|
{
|
|
|
|
|
const SIZE_T in_size = 1;
|
|
|
|
|
ULONG64 in[in_size] = {addr};
|
|
|
|
|
const SIZE_T out_size = 1;
|
|
|
|
|
ULONG64 out[out_size];
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------*\
|
|
|
|
|
| Execute PawnIO read_byte ioctl |
|
|
|
|
|
\*---------------------------------------------*/
|
|
|
|
|
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_read_byte").c_str(), in, in_size, out, out_size, &return_size);
|
|
|
|
|
data->byte = (u8)out[0];
|
|
|
|
|
|
|
|
|
|
return(status ? -EIO : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case I2C_SMBUS_BYTE_DATA:
|
|
|
|
|
{
|
|
|
|
|
const SIZE_T in_size = 2;
|
|
|
|
|
ULONG64 in[in_size] = {addr, command};
|
|
|
|
|
const SIZE_T out_size = 1;
|
|
|
|
|
ULONG64 out[out_size];
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------*\
|
|
|
|
|
| Execute PawnIO read_byte_data ioctl |
|
|
|
|
|
\*---------------------------------------------*/
|
|
|
|
|
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_read_byte_data").c_str(), in, in_size, out, out_size, &return_size);
|
|
|
|
|
data->byte = (u8)out[0];
|
|
|
|
|
|
|
|
|
|
return(status ? -EIO : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case I2C_SMBUS_WORD_DATA:
|
|
|
|
|
{
|
|
|
|
|
const SIZE_T in_size = 2;
|
|
|
|
|
ULONG64 in[in_size] = {addr, command};
|
|
|
|
|
const SIZE_T out_size = 1;
|
|
|
|
|
ULONG64 out[out_size];
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------*\
|
|
|
|
|
| Execute PawnIO read_word_data ioctl |
|
|
|
|
|
\*---------------------------------------------*/
|
|
|
|
|
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_read_word_data").c_str(), in, in_size, out, out_size, &return_size);
|
|
|
|
|
data->word = (u16)out[0];
|
|
|
|
|
|
|
|
|
|
return(status ? -EIO : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case I2C_SMBUS_BLOCK_DATA:
|
|
|
|
|
{
|
|
|
|
|
const SIZE_T in_size = 2;
|
|
|
|
|
ULONG64 in[in_size] = {addr, command};
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------*\
|
|
|
|
|
| Calculate output data buffer size |
|
|
|
|
|
| Pawn only deals with 64-bit cells, divide by |
|
|
|
|
|
| 8 to convert bytes to qwords. |
|
|
|
|
|
| The first cell is also the length. |
|
|
|
|
|
\*---------------------------------------------*/
|
|
|
|
|
const SIZE_T out_size = 1 + (I2C_SMBUS_BLOCK_MAX / 8);
|
|
|
|
|
ULONG64 out[out_size];
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------*\
|
|
|
|
|
| Execute PawnIO read_block_data ioctl |
|
|
|
|
|
\*---------------------------------------------*/
|
|
|
|
|
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_read_block_data").c_str(), in, in_size, out, out_size, &return_size);
|
|
|
|
|
|
|
|
|
|
if(status)
|
|
|
|
|
{
|
|
|
|
|
return(-EIO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(out[0] == 0 || out[0] > I2C_SMBUS_BLOCK_MAX)
|
|
|
|
|
{
|
|
|
|
|
return(-EPROTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------*\
|
|
|
|
|
| Unpack bytes from 64bit Pawn cells |
|
|
|
|
|
\*---------------------------------------------*/
|
|
|
|
|
u8 *out_bytes = (u8*)(&out[1]);
|
|
|
|
|
memcpy(&data->block[1], out_bytes, out[0]);
|
|
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return(-EOPNOTSUPP);
|
|
|
|
|
WaitForSingleObject(global_smbus_access_handle, INFINITE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 i2c_smbus_pawnio::pawnio_write(u8 addr, char read_write, u8 command, int size, i2c_smbus_data* data)
|
|
|
|
|
{
|
|
|
|
|
SIZE_T return_size;
|
|
|
|
|
|
|
|
|
|
switch(size)
|
|
|
|
|
{
|
|
|
|
|
case I2C_SMBUS_QUICK:
|
|
|
|
|
{
|
|
|
|
|
const SIZE_T in_size = 2;
|
|
|
|
|
ULONG64 in[in_size] = {addr, (u8)read_write};
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------*\
|
|
|
|
|
| Execute PawnIO write_quick ioctl |
|
|
|
|
|
\*---------------------------------------------*/
|
|
|
|
|
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_write_quick").c_str(), in, in_size, NULL, 0, &return_size);
|
|
|
|
|
|
|
|
|
|
return(status ? -EIO : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case I2C_SMBUS_BYTE:
|
|
|
|
|
{
|
|
|
|
|
const SIZE_T in_size = 2;
|
|
|
|
|
ULONG64 in[in_size] = {addr, data->byte};
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------*\
|
|
|
|
|
| Execute PawnIO write_byte ioctl |
|
|
|
|
|
\*---------------------------------------------*/
|
|
|
|
|
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_write_byte").c_str(), in, in_size, NULL, 0, &return_size);
|
|
|
|
|
|
|
|
|
|
return(status ? -EIO : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case I2C_SMBUS_BYTE_DATA:
|
|
|
|
|
{
|
|
|
|
|
const SIZE_T in_size = 3;
|
|
|
|
|
ULONG64 in[in_size] = {addr, command, data->byte};
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------*\
|
|
|
|
|
| Execute PawnIO write_byte_data ioctl |
|
|
|
|
|
\*---------------------------------------------*/
|
|
|
|
|
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_write_byte_data").c_str(), in, in_size, NULL, 0, &return_size);
|
|
|
|
|
|
|
|
|
|
return(status ? -EIO : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case I2C_SMBUS_WORD_DATA:
|
|
|
|
|
{
|
|
|
|
|
const SIZE_T in_size = 3;
|
|
|
|
|
ULONG64 in[in_size] = {addr, command, data->word};
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------*\
|
|
|
|
|
| Execute PawnIO write_word_data ioctl |
|
|
|
|
|
\*---------------------------------------------*/
|
|
|
|
|
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_write_word_data").c_str(), in, in_size, NULL, 0, &return_size);
|
|
|
|
|
|
|
|
|
|
return(status ? -EIO : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case I2C_SMBUS_BLOCK_DATA:
|
|
|
|
|
{
|
|
|
|
|
SIZE_T len = data->block[0];
|
|
|
|
|
if(len == 0 || len > I2C_SMBUS_BLOCK_MAX)
|
|
|
|
|
{
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
const SIZE_T in_size = 3 + (I2C_SMBUS_BLOCK_MAX/8);
|
|
|
|
|
ULONG64 in[3 + (I2C_SMBUS_BLOCK_MAX/8)] = {addr, command, len};
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------*\
|
|
|
|
|
| Pack bytes into 64bit Pawn cells |
|
|
|
|
|
\*---------------------------------------------*/
|
|
|
|
|
u8 *in_bytes = (u8*)&in[3];
|
|
|
|
|
memcpy(in_bytes, &data->block[1], len);
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------*\
|
|
|
|
|
| Execute PawnIO write_block_data ioctl |
|
|
|
|
|
\*---------------------------------------------*/
|
|
|
|
|
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_write_block_data").c_str(), in, in_size, NULL, 0, &return_size);
|
|
|
|
|
|
|
|
|
|
return(status ? -EIO : 0);
|
|
|
|
|
}
|
|
|
|
|
/*-----------------------------------------------------*\
|
|
|
|
|
| Pack input data |
|
|
|
|
|
\*-----------------------------------------------------*/
|
|
|
|
|
const SIZE_T in_size = 9;
|
|
|
|
|
ULONG64 in[in_size];
|
|
|
|
|
const SIZE_T out_size = 5;
|
|
|
|
|
ULONG64 out[out_size];
|
|
|
|
|
SIZE_T return_size;
|
|
|
|
|
HRESULT status;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return(-EOPNOTSUPP);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
in[0] = addr;
|
|
|
|
|
in[1] = read_write;
|
|
|
|
|
in[2] = command;
|
|
|
|
|
in[3] = size;
|
|
|
|
|
|
|
|
|
|
s32 i2c_smbus_pawnio::i2c_smbus_xfer(u8 addr, char read_write, u8 command, int size, i2c_smbus_data* data)
|
|
|
|
|
{
|
|
|
|
|
if(global_smbus_access_handle != NULL)
|
|
|
|
|
if(data != NULL)
|
|
|
|
|
{
|
|
|
|
|
WaitForSingleObject(global_smbus_access_handle, INFINITE);
|
|
|
|
|
memcpy( &in[4], data, sizeof(i2c_smbus_data));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int status = -ENXIO;
|
|
|
|
|
/*-----------------------------------------------------*\
|
|
|
|
|
| Perform SMBus transfer |
|
|
|
|
|
\*-----------------------------------------------------*/
|
|
|
|
|
status = pawnio_execute(handle, "ioctl_smbus_xfer", in, in_size, out, out_size, &return_size);
|
|
|
|
|
|
|
|
|
|
if(read_write && size != I2C_SMBUS_QUICK) {
|
|
|
|
|
status = pawnio_read(addr, read_write, command, size, data);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
/*-----------------------------------------------------*\
|
|
|
|
|
| Unpack output data |
|
|
|
|
|
\*-----------------------------------------------------*/
|
|
|
|
|
if(data != NULL)
|
|
|
|
|
{
|
|
|
|
|
status = pawnio_write(addr, read_write, command, size, data);
|
|
|
|
|
memcpy( data, &out[0], sizeof(i2c_smbus_data));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------*\
|
|
|
|
|
| Unlock SMBus mutex |
|
|
|
|
|
\*-----------------------------------------------------*/
|
|
|
|
|
if(global_smbus_access_handle != NULL)
|
|
|
|
|
{
|
|
|
|
|
ReleaseMutex(global_smbus_access_handle);
|
|
|
|
|
@ -289,7 +167,6 @@ s32 i2c_smbus_pawnio::i2c_xfer(u8 /*addr*/, char /*read_write*/, int* /*size*/,
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Find a better place for this function
|
|
|
|
|
HRESULT i2c_smbus_pawnio::start_pawnio(std::string filename, PHANDLE phandle)
|
|
|
|
|
{
|
|
|
|
|
char exePath[MAX_PATH];
|
|
|
|
|
@ -415,141 +292,52 @@ bool i2c_smbus_pawnio_detect()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i2c_smbus_interface * bus;
|
|
|
|
|
HRESULT hres;
|
|
|
|
|
Wmi wmi;
|
|
|
|
|
HANDLE pawnio_handle;
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------*\
|
|
|
|
|
| Query WMI for Win32_PnPSignedDriver entries with |
|
|
|
|
|
| names matching "SMBUS" or "SM BUS". These devices |
|
|
|
|
|
| may be browsed under Device Manager -> System Devices |
|
|
|
|
|
| Try to load Intel (i801) SMBus driver |
|
|
|
|
|
\*-----------------------------------------------------*/
|
|
|
|
|
std::vector<QueryObj> q_res_PnPSignedDriver;
|
|
|
|
|
hres = wmi.query("SELECT * FROM Win32_PnPSignedDriver WHERE Description LIKE '%SMBUS%' OR Description LIKE '%SM BUS%'", q_res_PnPSignedDriver);
|
|
|
|
|
|
|
|
|
|
if(hres)
|
|
|
|
|
if(i2c_smbus_pawnio::start_pawnio("SmbusI801.bin", &pawnio_handle) == S_OK)
|
|
|
|
|
{
|
|
|
|
|
LOG_INFO("WMI query failed, I2C bus detection aborted");
|
|
|
|
|
return(false);
|
|
|
|
|
bus = new i2c_smbus_pawnio(pawnio_handle, "i801");
|
|
|
|
|
ResourceManager::get()->RegisterI2CBus(bus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------*\
|
|
|
|
|
| For each detected SMBus adapter, try enumerating it |
|
|
|
|
|
| as either AMD (piix4) or Intel (i801) |
|
|
|
|
|
| Try to load AMD (PIIX4) SMBus driver - primary bus |
|
|
|
|
|
\*-----------------------------------------------------*/
|
|
|
|
|
for(QueryObj &i : q_res_PnPSignedDriver)
|
|
|
|
|
if(i2c_smbus_pawnio::start_pawnio("SmbusPIIX4.bin", &pawnio_handle) == S_OK)
|
|
|
|
|
{
|
|
|
|
|
/*-------------------------------------------------*\
|
|
|
|
|
| Intel SMBus controllers do show I/O resources in |
|
|
|
|
|
| Device Manager. Analysis of many Intel boards |
|
|
|
|
|
| has shown that Intel SMBus adapter I/O space |
|
|
|
|
|
| varies between boards. We can query |
|
|
|
|
|
| Win32_PnPAllocatedResource entries and look up |
|
|
|
|
|
| the PCI device ID to find the allocated I/O space.|
|
|
|
|
|
| |
|
|
|
|
|
| Intel SMBus adapters use the i801 driver |
|
|
|
|
|
| Select port 0 |
|
|
|
|
|
\*-------------------------------------------------*/
|
|
|
|
|
if((i["Manufacturer"].find("Intel") != std::string::npos)
|
|
|
|
|
|| (i["Manufacturer"].find("INTEL") != std::string::npos))
|
|
|
|
|
{
|
|
|
|
|
std::string pnp_str = i["DeviceID"];
|
|
|
|
|
|
|
|
|
|
std::size_t ven_loc = pnp_str.find("VEN_");
|
|
|
|
|
std::size_t dev_loc = pnp_str.find("DEV_");
|
|
|
|
|
std::size_t sub_loc = pnp_str.find("SUBSYS_");
|
|
|
|
|
|
|
|
|
|
std::string ven_str = pnp_str.substr(ven_loc + 4, 4);
|
|
|
|
|
std::string dev_str = pnp_str.substr(dev_loc + 4, 4);
|
|
|
|
|
std::string sbv_str = pnp_str.substr(sub_loc + 11, 4);
|
|
|
|
|
std::string sbd_str = pnp_str.substr(sub_loc + 7, 4);
|
|
|
|
|
|
|
|
|
|
int ven_id = (int)std::stoul(ven_str, nullptr, 16);
|
|
|
|
|
int dev_id = (int)std::stoul(dev_str, nullptr, 16);
|
|
|
|
|
int sbv_id = (int)std::stoul(sbv_str, nullptr, 16);
|
|
|
|
|
int sbd_id = (int)std::stoul(sbd_str, nullptr, 16);
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------*\
|
|
|
|
|
| Create bus |
|
|
|
|
|
\*---------------------------------------------*/
|
|
|
|
|
if(i2c_smbus_pawnio::start_pawnio("SmbusI801.bin", &pawnio_handle) != S_OK)
|
|
|
|
|
{
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bus = new i2c_smbus_pawnio(pawnio_handle, "i801");
|
|
|
|
|
bus->pci_vendor = ven_id;
|
|
|
|
|
bus->pci_device = dev_id;
|
|
|
|
|
bus->pci_subsystem_vendor = sbv_id;
|
|
|
|
|
bus->pci_subsystem_device = sbd_id;
|
|
|
|
|
strncpy(bus->device_name, i["Description"].c_str(), sizeof bus->device_name);
|
|
|
|
|
ResourceManager::get()->RegisterI2CBus(bus);
|
|
|
|
|
}
|
|
|
|
|
piix4_port_sel(pawnio_handle, 0);
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------*\
|
|
|
|
|
| AMD SMBus adapters use the PIIX4 driver |
|
|
|
|
|
bus = new i2c_smbus_pawnio(pawnio_handle, "piix4");
|
|
|
|
|
ResourceManager::get()->RegisterI2CBus(bus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------*\
|
|
|
|
|
| Try to load AMD (PIIX4 SMBus driver - secondary bus |
|
|
|
|
|
\*-----------------------------------------------------*/
|
|
|
|
|
if(i2c_smbus_pawnio::start_pawnio("SmbusPIIX4.bin", &pawnio_handle) == S_OK)
|
|
|
|
|
{
|
|
|
|
|
/*--------------------------------------------------*\
|
|
|
|
|
| Select port 1 |
|
|
|
|
|
\*-------------------------------------------------*/
|
|
|
|
|
else if(i["Manufacturer"].find("Advanced Micro Devices, Inc") != std::string::npos)
|
|
|
|
|
{
|
|
|
|
|
std::string pnp_str = i["DeviceID"];
|
|
|
|
|
|
|
|
|
|
std::size_t ven_loc = pnp_str.find("VEN_");
|
|
|
|
|
std::size_t dev_loc = pnp_str.find("DEV_");
|
|
|
|
|
std::size_t sub_loc = pnp_str.find("SUBSYS_");
|
|
|
|
|
|
|
|
|
|
std::string ven_str = pnp_str.substr(ven_loc + 4, 4);
|
|
|
|
|
std::string dev_str = pnp_str.substr(dev_loc + 4, 4);
|
|
|
|
|
std::string sbv_str = pnp_str.substr(sub_loc + 11, 4);
|
|
|
|
|
std::string sbd_str = pnp_str.substr(sub_loc + 7, 4);
|
|
|
|
|
|
|
|
|
|
int ven_id = (int)std::stoul(ven_str, nullptr, 16);
|
|
|
|
|
int dev_id = (int)std::stoul(dev_str, nullptr, 16);
|
|
|
|
|
int sbv_id = (int)std::stoul(sbv_str, nullptr, 16);
|
|
|
|
|
int sbd_id = (int)std::stoul(sbd_str, nullptr, 16);
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------*\
|
|
|
|
|
| Create primary bus |
|
|
|
|
|
\*---------------------------------------------*/
|
|
|
|
|
if(i2c_smbus_pawnio::start_pawnio("SmbusPIIX4.bin", &pawnio_handle) != S_OK)
|
|
|
|
|
{
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------*\
|
|
|
|
|
| Select port 0 |
|
|
|
|
|
\*---------------------------------------------*/
|
|
|
|
|
piix4_port_sel(pawnio_handle, 0);
|
|
|
|
|
|
|
|
|
|
bus = new i2c_smbus_pawnio(pawnio_handle, "piix4");
|
|
|
|
|
bus->pci_vendor = ven_id;
|
|
|
|
|
bus->pci_device = dev_id;
|
|
|
|
|
bus->pci_subsystem_vendor = sbv_id;
|
|
|
|
|
bus->pci_subsystem_device = sbd_id;
|
|
|
|
|
strncpy(bus->device_name, i["Description"].c_str(), sizeof bus->device_name);
|
|
|
|
|
strncat(bus->device_name, " port 0", sizeof bus->device_name);
|
|
|
|
|
ResourceManager::get()->RegisterI2CBus(bus);
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------*\
|
|
|
|
|
| Create secondary bus |
|
|
|
|
|
\*---------------------------------------------*/
|
|
|
|
|
if(i2c_smbus_pawnio::start_pawnio("SmbusPIIX4.bin", &pawnio_handle) != S_OK)
|
|
|
|
|
{
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------*\
|
|
|
|
|
| Select port 1 |
|
|
|
|
|
\*---------------------------------------------*/
|
|
|
|
|
piix4_port_sel(pawnio_handle, 1);
|
|
|
|
|
|
|
|
|
|
bus = new i2c_smbus_pawnio(pawnio_handle, "piix4");
|
|
|
|
|
bus->pci_vendor = ven_id;
|
|
|
|
|
bus->pci_device = dev_id;
|
|
|
|
|
bus->pci_subsystem_vendor = sbv_id;
|
|
|
|
|
bus->pci_subsystem_device = sbd_id;
|
|
|
|
|
strncpy(bus->device_name, i["Description"].c_str(), sizeof bus->device_name);
|
|
|
|
|
strncat(bus->device_name, " port 1", sizeof bus->device_name);
|
|
|
|
|
ResourceManager::get()->RegisterI2CBus(bus);
|
|
|
|
|
}
|
|
|
|
|
piix4_port_sel(pawnio_handle, 1);
|
|
|
|
|
|
|
|
|
|
bus = new i2c_smbus_pawnio(pawnio_handle, "piix4");
|
|
|
|
|
ResourceManager::get()->RegisterI2CBus(bus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------*\
|
|
|
|
|
| Try to load Nuvoton (NCT6793) SMBus driver |
|
|
|
|
|
\*-----------------------------------------------------*/
|
|
|
|
|
if(i2c_smbus_pawnio::start_pawnio("SmbusNCT6793.bin", &pawnio_handle) == S_OK)
|
|
|
|
|
{
|
|
|
|
|
bus = new i2c_smbus_pawnio(pawnio_handle, "NCT6793");
|
|
|
|
|
ResourceManager::get()->RegisterI2CBus(bus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
|