From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.9372.1641102583711667127 for ; Sat, 01 Jan 2022 21:49:43 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: jeremy.linton@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 599191396; Sat, 1 Jan 2022 21:49:43 -0800 (PST) Received: from u200856.usa.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ECFC73F5A1; Sat, 1 Jan 2022 21:49:42 -0800 (PST) From: "Jeremy Linton" To: devel@edk2.groups.io Cc: pete@akeo.ie, ardb+tianocore@kernel.org, leif@nuviainc.com, awarkentin@vmware.com, Sunny.Wang@arm.com, samer.el-haj-mahmoud@arm.com, mariobalanica02@gmail.com, Jeremy Linton , Ard Biesheuvel Subject: [PATCH V2 06/10] Platform/RaspberryPi: Add mailbox cmd to control audio amp Date: Sat, 1 Jan 2022 23:49:20 -0600 Message-Id: <20220102054924.1195762-7-jeremy.linton@arm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220102054924.1195762-1-jeremy.linton@arm.com> References: <20220102054924.1195762-1-jeremy.linton@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable The lower level firmware can enable/disable a LDO audio amp, which allows us to mute/unmute audio output while the firmware is running. Tested-by: Ard Biesheuvel Signed-off-by: Jeremy Linton --- .../Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c | 60 ++++++++++++++++= +++++- .../RaspberryPi/Include/IndustryStandard/RpiMbox.h | 1 + .../RaspberryPi/Include/Protocol/RpiFirmware.h | 7 +++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c= b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c index 4edec0ad04..dca43d78a6 100644 --- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c +++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c @@ -1532,6 +1532,63 @@ RpiFirmwareNotifyGpioSetCfg ( return Status; } =20 +#pragma pack() +typedef struct { + UINT32 State; +} RPI_FW_SET_LDO_REG_TAG; + +typedef struct { + RPI_FW_BUFFER_HEAD BufferHead; + RPI_FW_TAG_HEAD TagHead; + RPI_FW_SET_LDO_REG_TAG TagBody; + UINT32 EndTag; +} RPI_FW_SET_LDO_REG_CMD; +#pragma pack() + + +STATIC +EFI_STATUS +EFIAPI +RpiFirmwareSetLdoRegState ( + IN UINTN State + ) +{ + RPI_FW_SET_LDO_REG_CMD *Cmd; + EFI_STATUS Status; + UINT32 Result; + + if (!AcquireSpinLockOrFail (&mMailboxLock)) { + DEBUG ((DEBUG_ERROR, "%a: failed to acquire spinlock\n", __FUNCTION_= _)); + return EFI_DEVICE_ERROR; + } + + Cmd =3D mDmaBuffer; + ZeroMem (Cmd, sizeof (*Cmd)); + + Cmd->BufferHead.BufferSize =3D sizeof (*Cmd); + Cmd->BufferHead.Response =3D 0; + Cmd->TagHead.TagId =3D RPI_MBOX_SET_LDO_REGULATOR; + Cmd->TagHead.TagSize =3D sizeof (Cmd->TagBody); + Cmd->TagBody.State =3D State; + + Cmd->TagHead.TagValueSize =3D 0; + Cmd->EndTag =3D 0; + + Status =3D MailboxTransaction (Cmd->BufferHead.BufferSize, RPI_MBOX_VC= _CHANNEL, &Result); + + if (EFI_ERROR (Status) || + Cmd->BufferHead.Response !=3D RPI_MBOX_RESP_SUCCESS) { + DEBUG ((DEBUG_ERROR, + "%a: mailbox transaction error: Status =3D=3D %r, Response =3D=3D= 0x%x\n", + __FUNCTION__, Status, Cmd->BufferHead.Response)); + } + + ReleaseSpinLock (&mMailboxLock); + + return Status; +} + + STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL mRpiFirmwareProtocol =3D { RpiFirmwareSetPowerState, RpiFirmwareGetMacAddress, @@ -1557,7 +1614,8 @@ STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL mRpiFirmwareP= rotocol =3D { RpiFirmwareNotifyXhciReset, RpiFirmwareGetCurrentClockState, RpiFirmwareSetClockState, - RpiFirmwareNotifyGpioSetCfg + RpiFirmwareNotifyGpioSetCfg, + RpiFirmwareSetLdoRegState }; =20 /** diff --git a/Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h b/Pl= atform/RaspberryPi/Include/IndustryStandard/RpiMbox.h index 551c2b82e5..f36aaafaf8 100644 --- a/Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h +++ b/Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h @@ -92,6 +92,7 @@ #define RPI_MBOX_NOTIFY_REBOOT 0x00030048 #define RPI_MBOX_GET_POE_HAT_VAL 0x00030049 #define RPI_MBOX_SET_POE_HAT_VAL 0x00030050 +#define RPI_MBOX_SET_LDO_REGULATOR 0x00030056 #define RPI_MBOX_NOTIFY_XHCI_RESET 0x00030058 =20 #define RPI_MBOX_SET_CLOCK_STATE 0x00038001 diff --git a/Platform/RaspberryPi/Include/Protocol/RpiFirmware.h b/Platfo= rm/RaspberryPi/Include/Protocol/RpiFirmware.h index c48bb6e434..175894e37a 100644 --- a/Platform/RaspberryPi/Include/Protocol/RpiFirmware.h +++ b/Platform/RaspberryPi/Include/Protocol/RpiFirmware.h @@ -171,6 +171,12 @@ EFI_STATUS UINTN State ); =20 +typedef +EFI_STATUS +(EFIAPI *SET_LDO_REGULATOR) ( + UINTN State + ); + typedef struct { SET_POWER_STATE SetPowerState; GET_MAC_ADDRESS GetMacAddress; @@ -197,6 +203,7 @@ typedef struct { GET_CLOCK_STATE GetClockState; SET_CLOCK_STATE SetClockState; GPIO_SET_CFG SetGpioConfig; + SET_LDO_REGULATOR SetLdoRegState; } RASPBERRY_PI_FIRMWARE_PROTOCOL; =20 extern EFI_GUID gRaspberryPiFirmwareProtocolGuid; --=20 2.13.7