Add support for Intel i801 SMBus on MacOS
This commit is contained in:
parent
524675108d
commit
e9c382d2e6
6 changed files with 204 additions and 2 deletions
|
|
@ -9,8 +9,13 @@
|
|||
\*-----------------------------------------*/
|
||||
|
||||
#include "i2c_smbus_i801.h"
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#include "OlsApi.h"
|
||||
#elif _MACOSX_X86_X64
|
||||
#include "macUSPCIOAccess.h"
|
||||
#endif
|
||||
|
||||
#include "LogManager.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
|
@ -490,6 +495,7 @@ s32 i2c_smbus_i801::i2c_xfer(u8 addr, char read_write, int* size, u8* data)
|
|||
}
|
||||
|
||||
#include "Detector.h"
|
||||
#ifdef _WIN32
|
||||
#include "wmi.h"
|
||||
|
||||
bool i2c_smbus_i801_detect()
|
||||
|
|
@ -558,6 +564,18 @@ bool i2c_smbus_i801_detect()
|
|||
int sbv_id = (int)std::stoul(sbv_str, nullptr, 16);
|
||||
int sbd_id = (int)std::stoul(sbd_str, nullptr, 16);
|
||||
|
||||
DWORD pciAddress = FindPciDeviceById(ven_id, dev_id, 0);
|
||||
if(pciAddress == 0xFFFFFFFF)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t host_config = ReadPciConfigWord(pciAddress, SMBHSTCFG);
|
||||
if ((host_config & SMBHSTCFG_HST_EN) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bus = new i2c_smbus_i801();
|
||||
bus->pci_vendor = ven_id;
|
||||
bus->pci_device = dev_id;
|
||||
|
|
@ -572,5 +590,41 @@ bool i2c_smbus_i801_detect()
|
|||
|
||||
return(true);
|
||||
}
|
||||
#elif _MACOSX_X86_X64
|
||||
bool i2c_smbus_i801_detect()
|
||||
{
|
||||
if(!GetMacUSPCIODriverStatus())
|
||||
{
|
||||
LOG_INFO("macUSPCIO is not loaded, i801 I2C bus detection aborted");
|
||||
return(false);
|
||||
}
|
||||
|
||||
uint8_t host_config = ReadConfigPortByte(SMBHSTCFG);
|
||||
if ((host_config & SMBHSTCFG_HST_EN) == 0)
|
||||
{
|
||||
LOG_INFO("i801 SMBus Disabled");
|
||||
return(false);
|
||||
}
|
||||
|
||||
i2c_smbus_interface * bus;
|
||||
bus = new i2c_smbus_i801();
|
||||
// addresses are referenced from: https://opensource.apple.com/source/IOPCIFamily/IOPCIFamily-146/IOKit/pci/IOPCIDevice.h.auto.html
|
||||
bus->pci_vendor = ReadConfigPortWord(0x00);
|
||||
bus->pci_device = ReadConfigPortWord(0x02);
|
||||
bus->pci_subsystem_vendor = ReadConfigPortWord(0x2c);
|
||||
bus->pci_subsystem_device = ReadConfigPortWord(0x2e);
|
||||
|
||||
if(!bus->pci_vendor || !bus->pci_device || !bus->pci_subsystem_vendor || !bus->pci_subsystem_device)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
sprintf(bus->device_name, "Intel(R) SMBus - %X", bus->pci_device);
|
||||
((i2c_smbus_i801 *)bus)->i801_smba = ReadConfigPortWord(0x20) & 0xFFFE;
|
||||
ResourceManager::get()->RegisterI2CBus(bus);
|
||||
|
||||
return(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
REGISTER_I2C_BUS_DETECTOR(i2c_smbus_i801_detect);
|
||||
|
|
|
|||
|
|
@ -77,6 +77,10 @@
|
|||
#define STATUS_ERROR_FLAGS (SMBHSTSTS_FAILED | SMBHSTSTS_BUS_ERR | SMBHSTSTS_DEV_ERR)
|
||||
#define STATUS_FLAGS (SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR | STATUS_ERROR_FLAGS)
|
||||
|
||||
/* I801 Host Config */
|
||||
#define SMBHSTCFG 0x040
|
||||
#define SMBHSTCFG_HST_EN BIT(0)
|
||||
|
||||
class i2c_smbus_i801 : public i2c_smbus_interface
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue