From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 6E407940694 for ; Thu, 11 Jan 2024 00:04:32 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=1UeWDU/F6sulCZT02sMpUWOsOTSurZI4BCVkdTrzDCk=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1704931471; v=1; b=QD+Mw44h1WDgvfrph8+DuuPm/KZelAUIaWwyXBlnJ69iWyoP4VGZ1jqkkhd7V6fTLssIdMIJ hALPKj7G+LZ1DObNNu7+4wI4XHSGpPLfr+hFbKk9qkXrjD79kGUszYJPCugdfhIR0lKm3FyGzro ICEslQXMZHfbW/f4PLOTS5Zo= X-Received: by 127.0.0.2 with SMTP id lQHpYY7687511xBHtwOTIpFm; Wed, 10 Jan 2024 16:04:31 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.9368.1704931469364233539 for ; Wed, 10 Jan 2024 16:04:29 -0800 X-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 0A4DD12FC; Wed, 10 Jan 2024 16:05:15 -0800 (PST) X-Received: from u200865.usa.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E0C063F5A1; Wed, 10 Jan 2024 16:04:28 -0800 (PST) From: "Jeremy Linton" To: devel@edk2.groups.io Cc: ardb+tianocore@kernel.org, quic_llindhol@quicinc.com, Jeremy Linton Subject: [edk2-devel] [RFC 3/6] Platform/RasberryPi: Create I2C driver bound to RTC Date: Wed, 10 Jan 2024 18:04:23 -0600 Message-ID: <20240111000426.2735007-4-jeremy.linton@arm.com> In-Reply-To: <20240111000426.2735007-1-jeremy.linton@arm.com> References: <20240111000426.2735007-1-jeremy.linton@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,jeremy.linton@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: cjM2udtBi2oNKRHVkpLzZI7Hx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=QD+Mw44h; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=arm.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Now that we have a generic Bcm I2C driver lets instantiate one against a possible RTC hat on the pi4. Signed-off-by: Jeremy Linton --- .../Drivers/BcmI2CPlatform/BcmI2CPlatform.c | 127 ++++++++++++++++++ .../Drivers/BcmI2CPlatform/BcmI2CPlatform.inf | 54 ++++++++ 2 files changed, 181 insertions(+) create mode 100644 Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPla= tform.c create mode 100644 Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPla= tform.inf diff --git a/Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPlatform.c= b/Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPlatform.c new file mode 100644 index 0000000000..11f927b848 --- /dev/null +++ b/Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPlatform.c @@ -0,0 +1,127 @@ +/** @file + Brcm/Rpi I2C DXE platform driver. + + Copyright 2018-2020 NXP + Sourced and reworked from edk2/NXP I2C stack + Copyright 2022 Arm, Jeremy Linton + + SPDX-License-Identifier: BSD-2-Clause-Patent + + This thing binds a I2C driver to a RTC.. + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +typedef struct { + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR StartDesc; + UINT8 EndDesc; +} ADDRESS_SPACE_DESCRIPTOR; + +#define BCM_I2C_NUM_CONTROLLERS 1 //actually 6 on the bcm2711, hack for = now + +STATIC ADDRESS_SPACE_DESCRIPTOR mI2cDesc[BCM_I2C_NUM_CONTROLLERS]; + +STATIC +EFI_STATUS +RegisterDevice ( + IN EFI_GUID *TypeGuid, + IN ADDRESS_SPACE_DESCRIPTOR *Desc, + OUT EFI_HANDLE *Handle + ) +{ + NON_DISCOVERABLE_DEVICE *Device; + EFI_STATUS Status; + + Device =3D (NON_DISCOVERABLE_DEVICE *)AllocateZeroPool (sizeof (*Devic= e)); + if (Device =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Device->Type =3D TypeGuid; + Device->DmaType =3D NonDiscoverableDeviceDmaTypeNonCoherent; + Device->Resources =3D (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Desc; + + Status =3D gBS->InstallMultipleProtocolInterfaces (Handle, + &gEdkiiNonDiscoverableDeviceProtocolGuid, Device, + NULL); + if (EFI_ERROR (Status)) { + goto FreeDevice; + } + return EFI_SUCCESS; + +FreeDevice: + FreePool (Device); + + return Status; +} + +VOID +PopulateI2cInformation ( + IN VOID + ) +{ + UINT32 Index; + + for (Index =3D 0; Index < ARRAY_SIZE (mI2cDesc); Index++) { + mI2cDesc[Index].StartDesc.Desc =3D ACPI_ADDRESS_SPACE_DESCRIPTOR; + mI2cDesc[Index].StartDesc.Len =3D sizeof (EFI_ACPI_ADDRESS_SPACE_DES= CRIPTOR) - 3; + mI2cDesc[Index].StartDesc.ResType =3D ACPI_ADDRESS_SPACE_TYPE_MEM; + mI2cDesc[Index].StartDesc.GenFlag =3D 0; + mI2cDesc[Index].StartDesc.SpecificFlag =3D 0; + mI2cDesc[Index].StartDesc.AddrSpaceGranularity =3D 32; + mI2cDesc[Index].StartDesc.AddrRangeMin =3D BCM2836_I2C1_BASE_ADDRESS= ; + mI2cDesc[Index].StartDesc.AddrRangeMax =3D mI2cDesc[Index].StartDesc= .AddrRangeMin + BCM2836_I2C1_LENGTH; + mI2cDesc[Index].StartDesc.AddrTranslationOffset =3D 0; + mI2cDesc[Index].StartDesc.AddrLen =3D BCM2836_I2C1_LENGTH; + + mI2cDesc[Index].EndDesc =3D ACPI_END_TAG_DESCRIPTOR; + } +} + +EFI_STATUS +EFIAPI +BcmI2CPlatformDxeEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + + Handle =3D NULL; + + PopulateI2cInformation (); + + if (PcdGet32 (PcdHwRtc)) + { + DEBUG ((DEBUG_ERROR, "RTC I2C enable\n")); + // If we don't register this, the second rtc won't get enabled + // leaving the emulator in place. + Status =3D RegisterDevice (&gBcmNonDiscoverableI2cMasterGuid, + &mI2cDesc[0], &Handle); + ASSERT_EFI_ERROR (Status); + + // + // Install the DS1307 I2C Master protocol on this handle so the RTC = driver + // can identify it as the I2C master it can invoke directly. + // + Status =3D gBS->InstallProtocolInterface (&Handle, + &gDs1307RealTimeClockLibI2cMasterProtocolGuid, + EFI_NATIVE_INTERFACE, NULL); + ASSERT_EFI_ERROR (Status); + } else { + DEBUG ((DEBUG_ERROR, "RTC I2C disabled\n")); + } + + return EFI_SUCCESS; +} diff --git a/Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPlatform.i= nf b/Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPlatform.inf new file mode 100644 index 0000000000..aa5c1b51b2 --- /dev/null +++ b/Platform/RaspberryPi/Drivers/BcmI2CPlatform/BcmI2CPlatform.inf @@ -0,0 +1,54 @@ +## @file +# +# Component description file for Bcm/Rpi I2C driver. +# +# Copyright 2018-2020 NXP +# Sourced and reworked from edk2/NXP I2C stack +# Copyright 2022 Arm, Jeremy Linton +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001A + BASE_NAME =3D BcmI2CPlatformDxe + FILE_GUID =3D 1a23fe23-39bc-4bee-859d-ecb5bbb6048= 4 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D BcmI2CPlatformDxeEntryPoint + +[Sources] + BcmI2CPlatform.c + +[Packages] + ArmPkg/ArmPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + Silicon/Maxim/Library/Ds1307RtcLib/Ds1307RtcLib.dec + Silicon/Broadcom/Bcm283x/Bcm283x.dec + Platform/RaspberryPi/RaspberryPi.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + PcdLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiLib + +[Guids] + gBcmNonDiscoverableI2cMasterGuid + +[Protocols] + gEdkiiNonDiscoverableDeviceProtocolGuid ## PRODUCES + gDs1307RealTimeClockLibI2cMasterProtocolGuid ## PRODUCES + +[Pcd] + gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress + gRaspberryPiTokenSpaceGuid.PcdHwRtc + +[Depex] + gRaspberryPiConfigAppliedProtocolGuid --=20 2.43.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113560): https://edk2.groups.io/g/devel/message/113560 Mute This Topic: https://groups.io/mt/103653099/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-