Skip to content

Commit

Permalink
Add 3 new features:
Browse files Browse the repository at this point in the history
* I2cSlaveDeviceTreePath protocol to be able to lookup the device tree path of any I2cIo device using its GUID and globally unique device index (+fixed bugs with non-unique device indices)
* Implement PCA9547 i2cmux support via the EFI_I2C_BUS_CONFIGURATION_MANAGEMENT_PROTOCOL
* Support for Framos EEPROMs (skip CRC check same as LPRD)
  • Loading branch information
Anonymous committed May 18, 2023
1 parent ea98295 commit f646940
Show file tree
Hide file tree
Showing 13 changed files with 400 additions and 77 deletions.
50 changes: 46 additions & 4 deletions Silicon/NVIDIA/Drivers/EepromDxe/Eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <Protocol/DriverBinding.h>
#include <Protocol/I2cIo.h>
#include <Protocol/TegraI2cSlaveDeviceTreePath.h>
#include <Protocol/Eeprom.h>
#include <Protocol/Rng.h>
#include <Protocol/KernelCmdLineUpdate.h>
Expand Down Expand Up @@ -306,6 +307,7 @@ EepromDxeDriverBindingStart (
{
EFI_STATUS Status;
EFI_I2C_IO_PROTOCOL *I2cIo = NULL;

EFI_RNG_PROTOCOL *RngProtocol = NULL;
EFI_I2C_REQUEST_PACKET *Request = NULL;
UINT8 Address = 0;
Expand All @@ -316,6 +318,9 @@ EepromDxeDriverBindingStart (
TEGRA_EEPROM_BOARD_INFO *IdBoardInfo;
BOOLEAN SkipEepromCRC;

NVIDIA_TEGRA_I2C_SLAVE_DEVICE_TREE_PATH_PROTOCOL *I2cSlaveDeviceTreePath = NULL;
CHAR8 *EepromDeviceTreePath;

RawData = NULL;
CvmBoardInfo = NULL;
IdBoardInfo = NULL;
Expand All @@ -338,6 +343,38 @@ EepromDxeDriverBindingStart (
goto ErrorExit;
}

EFI_HANDLE Handle[10]; // Usually only 8 Tegra I2C buses to choose from
UINTN HandleSize = sizeof(Handle);
Status = gBS->LocateHandle(ByProtocol, &gNVIDIAI2cSlaveDeviceTreePathProtocolGuid, NULL, &HandleSize, &Handle[0]);

if ((EFI_ERROR (Status))) {
DEBUG ((DEBUG_ERROR, "%a: Unable to LocateHandle for I2cSlaveDeviceTreePath Protocol (Status: %d)\n", __FUNCTION__, Status));
return Status;
}

EepromDeviceTreePath = NULL;
INT32 NumHandles = HandleSize/sizeof(Handle[0]);
for (INT32 i = 0; i < NumHandles; i++) {
Status = gBS->HandleProtocol (Handle[i], &gNVIDIAI2cSlaveDeviceTreePathProtocolGuid, (VOID **)&I2cSlaveDeviceTreePath);
if ((EFI_ERROR (Status))) {
DEBUG ((DEBUG_ERROR, "%a: Unable to HandleProtocol for index %d I2cSlaveDeviceTreePath Protocol (Status: %d)\n", __FUNCTION__, i, Status));
return Status;
}

Status = I2cSlaveDeviceTreePath->LookupPath(I2cSlaveDeviceTreePath, I2cIo->DeviceGuid, I2cIo->DeviceIndex, &EepromDeviceTreePath);
if (!(EFI_ERROR (Status))) {
// found
break;
}
}

if ((EFI_ERROR (Status))) {
DEBUG ((DEBUG_ERROR, "%a: Unable to LookupPath using any of the %d I2cSlaveDeviceTreePath Protocols (device index %x, Status: %d)\n", __FUNCTION__, NumHandles, I2cIo->DeviceIndex, Status));
return Status;
}

DEBUG ((DEBUG_INFO, "%a: Starting (TEGRA_PLATFORM_SILICON) Bus %x Device %x %a\r\n", __FUNCTION__, I2cIo->DeviceIndex >> 16, I2cIo->DeviceIndex & 0xFFFF, EepromDeviceTreePath));

// Allocate EEPROM Data
RawData = (UINT8 *)AllocateZeroPool (EEPROM_DATA_SIZE);
if (RawData == NULL) {
Expand Down Expand Up @@ -369,9 +406,14 @@ EepromDxeDriverBindingStart (

if (0 == AsciiStrnCmp (
(CHAR8 *)&RawData[CAMERA_EEPROM_PART_OFFSET],
CAMERA_EEPROM_PART_NAME,
AsciiStrLen (CAMERA_EEPROM_PART_NAME)
))
CAMERA_EEPROM_PART_NAME_0,
AsciiStrLen (CAMERA_EEPROM_PART_NAME_0)
) ||
0 == AsciiStrnCmp (
(CHAR8 *)&RawData[CAMERA_EEPROM_PART_OFFSET],
CAMERA_EEPROM_PART_NAME_1,
AsciiStrLen (CAMERA_EEPROM_PART_NAME_1)
))
{
SkipEepromCRC = TRUE;
}
Expand All @@ -393,7 +435,7 @@ EepromDxeDriverBindingStart (
DEBUG ((DEBUG_ERROR, "Eeprom data population failed(%r)\r\n", Status));
goto ErrorExit;
}

IdBoardInfo->EepromDeviceTreePath = EepromDeviceTreePath;
DEBUG ((DEBUG_ERROR, "Eeprom Product Id: %a\r\n", IdBoardInfo->ProductId));
} else {
CvmEeprom = TRUE;
Expand Down
1 change: 1 addition & 0 deletions Silicon/NVIDIA/Drivers/EepromDxe/Eeprom.inf
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
gNVIDIACvmEepromProtocolGuid ## SOMETIMES_PRODUCES
gNVIDIACvbEepromProtocolGuid ## SOMETIMES_PRODUCES
gNVIDIAEepromProtocolGuid ## SOMETIMES_PRODUCES
gNVIDIAI2cSlaveDeviceTreePathProtocolGuid ## CONSUMES

[Depex]
TRUE
11 changes: 8 additions & 3 deletions Silicon/NVIDIA/Drivers/TegraI2c/TegraI2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

// Currently only support enumerating 16 device per controller
#define MAX_I2C_DEVICES 16
#define MAX_I2C_DEVICE_DT_PATH 64
#define MAX_SLAVES_PER_DEVICE 1

typedef struct {
Expand All @@ -36,6 +37,8 @@ typedef struct {
EFI_I2C_ENUMERATE_PROTOCOL I2cEnumerate;
EFI_I2C_BUS_CONFIGURATION_MANAGEMENT_PROTOCOL I2CConfiguration;

NVIDIA_TEGRA_I2C_SLAVE_DEVICE_TREE_PATH_PROTOCOL I2cSlaveDeviceTreePath;

//
// Indicates if the protocols are installed
//
Expand All @@ -54,7 +57,6 @@ typedef struct {
UINT32 ControllerId;
UINTN BusClockHertz;

UINT32 BusId;
VOID *DeviceTreeBase;
INT32 DeviceTreeNodeOffset;

Expand All @@ -63,15 +65,18 @@ typedef struct {
//
EFI_I2C_DEVICE I2cDevices[MAX_I2C_DEVICES];
UINT32 SlaveAddressArray[MAX_I2C_DEVICES*MAX_SLAVES_PER_DEVICE];
CHAR8 DeviceTreePaths[MAX_I2C_DEVICES][MAX_I2C_DEVICE_DT_PATH];
UINTN NumberOfI2cDevices;

UINT32 PinControlId;
BOOLEAN PinControlConfigured;
BOOLEAN SkipOnExitDisabled;
} NVIDIA_TEGRA_I2C_PRIVATE_DATA;

#define TEGRA_I2C_PRIVATE_DATA_FROM_MASTER(a) CR(a, NVIDIA_TEGRA_I2C_PRIVATE_DATA, I2cMaster, TEGRA_I2C_SIGNATURE)
#define TEGRA_I2C_PRIVATE_DATA_FROM_ENUMERATE(a) CR(a, NVIDIA_TEGRA_I2C_PRIVATE_DATA, I2cEnumerate, TEGRA_I2C_SIGNATURE)
#define TEGRA_I2C_PRIVATE_DATA_FROM_MASTER(a) CR(a, NVIDIA_TEGRA_I2C_PRIVATE_DATA, I2cMaster, TEGRA_I2C_SIGNATURE)
#define TEGRA_I2C_PRIVATE_DATA_FROM_ENUMERATE(a) CR(a, NVIDIA_TEGRA_I2C_PRIVATE_DATA, I2cEnumerate, TEGRA_I2C_SIGNATURE)
#define TEGRA_I2C_PRIVATE_DATA_FROM_BUS_CONFIGURATION(a) CR(a, NVIDIA_TEGRA_I2C_PRIVATE_DATA, I2CConfiguration, TEGRA_I2C_SIGNATURE)
#define TEGRA_I2C_PRIVATE_DATA_FROM_SLAVE_DEVICE_TREE_PATH(a) CR(a, NVIDIA_TEGRA_I2C_PRIVATE_DATA, I2cSlaveDeviceTreePath, TEGRA_I2C_SIGNATURE)

/**
* @addtogroup SPEED_MODES I2C Mode frequencies
Expand Down
Loading

0 comments on commit f646940

Please sign in to comment.