Skip to content

Instantly share code, notes, and snippets.

@N1kroks
Last active November 4, 2024 15:14
Show Gist options
  • Save N1kroks/ea0aedd6d9b9e1c802da9f554f08cf0c to your computer and use it in GitHub Desktop.
Save N1kroks/ea0aedd6d9b9e1c802da9f554f08cf0c to your computer and use it in GitHub Desktop.
#include <Library/DebugLib.h>
#include <Library/IoLib.h>
#include <Library/UefiBootServicesTableLib.h>
#define CORE 0x0c440000
#define OBSRVR 0x0e600000
#define PMIC_USID 4 // PM6150L GPIO USID
#define PMIC_GPIO_BASE 0xC000 // PM6150L GPIO address
#define VOL_UP_GPIO 2
UINT32 channel_map[16][256];
EFI_STATUS
EFIAPI
Entry (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable)
{
EFI_STATUS Status = EFI_SUCCESS;
UINT32 Version = MmioRead32(CORE);
DEBUG((EFI_D_ERROR, "PMIC ARB Version: 0x%X\n", Version));
gBS->SetMem(channel_map, 16 * 256, 0);
for(UINT16 i = 0; i < 512; i++) {
UINT32 periph = MmioRead32(CORE + 0x900 + (0x4 * i));
UINT8 slave_id = (periph & 0xf0000) >> 16;
UINT8 pid = (periph & 0xff00) >> 8;
channel_map[slave_id][pid] = i;
}
UINT32 pid = GPIO_BASE + (VOL_UP_GPIO - 1) * 0x100 + 0x8;
UINT32 channel = channel_map[PMIC_USID][(pid & (0xFF << 8)) >> 8] & 0xffff;
DEBUG((EFI_D_ERROR, "Channel: 0x%X\n", OBSRVR + channel * 0x80));
DEBUG((EFI_D_ERROR, "Command: 0x%X\n", (0x8000001 | ((pid & 0xFF) << 4))));
while(1) {}
return Status;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment