]> git.proxmox.com Git - mirror_edk2.git/blob - Omap35xxPkg/PciEmulation/PciEmulation.c
OvmfPkg/PlatformBootManagerLib: hoist PciAcpiInitialization()
[mirror_edk2.git] / Omap35xxPkg / PciEmulation / PciEmulation.c
1 /** @file
2
3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4 Copyright (c) 2016, Linaro, Ltd. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include <PiDxe.h>
17
18 #include <Library/BaseLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/IoLib.h>
21 #include <Library/NonDiscoverableDeviceRegistrationLib.h>
22 #include <Library/UefiBootServicesTableLib.h>
23
24 #include <Protocol/EmbeddedExternalDevice.h>
25
26 #include <TPS65950.h>
27 #include <Omap3530/Omap3530.h>
28
29 EMBEDDED_EXTERNAL_DEVICE *gTPS65950;
30
31 #define HOST_CONTROLLER_OPERATION_REG_SIZE 0x44
32
33 STATIC
34 EFI_STATUS
35 ConfigureUSBHost (
36 NON_DISCOVERABLE_DEVICE *Device
37 )
38 {
39 EFI_STATUS Status;
40 UINT8 Data = 0;
41
42 // Take USB host out of force-standby mode
43 MmioWrite32 (UHH_SYSCONFIG, UHH_SYSCONFIG_MIDLEMODE_NO_STANDBY
44 | UHH_SYSCONFIG_CLOCKACTIVITY_ON
45 | UHH_SYSCONFIG_SIDLEMODE_NO_STANDBY
46 | UHH_SYSCONFIG_ENAWAKEUP_ENABLE
47 | UHH_SYSCONFIG_AUTOIDLE_ALWAYS_RUN);
48 MmioWrite32 (UHH_HOSTCONFIG, UHH_HOSTCONFIG_P3_CONNECT_STATUS_DISCONNECT
49 | UHH_HOSTCONFIG_P2_CONNECT_STATUS_DISCONNECT
50 | UHH_HOSTCONFIG_P1_CONNECT_STATUS_DISCONNECT
51 | UHH_HOSTCONFIG_ENA_INCR_ALIGN_DISABLE
52 | UHH_HOSTCONFIG_ENA_INCR16_ENABLE
53 | UHH_HOSTCONFIG_ENA_INCR8_ENABLE
54 | UHH_HOSTCONFIG_ENA_INCR4_ENABLE
55 | UHH_HOSTCONFIG_AUTOPPD_ON_OVERCUR_EN_ON
56 | UHH_HOSTCONFIG_P1_ULPI_BYPASS_ULPI_MODE);
57
58 // USB reset (GPIO 147 - Port 5 pin 19) output high
59 MmioAnd32 (GPIO5_BASE + GPIO_OE, ~BIT19);
60 MmioWrite32 (GPIO5_BASE + GPIO_SETDATAOUT, BIT19);
61
62 // Get the Power IC protocol
63 Status = gBS->LocateProtocol (&gEmbeddedExternalDeviceProtocolGuid, NULL, (VOID **)&gTPS65950);
64 ASSERT_EFI_ERROR (Status);
65
66 // Power the USB PHY
67 Data = VAUX_DEV_GRP_P1;
68 Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VAUX2_DEV_GRP), 1, &Data);
69 ASSERT_EFI_ERROR(Status);
70
71 Data = VAUX_DEDICATED_18V;
72 Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID4, VAUX2_DEDICATED), 1, &Data);
73 ASSERT_EFI_ERROR (Status);
74
75 // Enable power to the USB hub
76 Status = gTPS65950->Read (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID3, LEDEN), 1, &Data);
77 ASSERT_EFI_ERROR (Status);
78
79 // LEDAON controls the power to the USB host, PWM is disabled
80 Data &= ~LEDAPWM;
81 Data |= LEDAON;
82
83 Status = gTPS65950->Write (gTPS65950, EXTERNAL_DEVICE_REGISTER(I2C_ADDR_GRP_ID3, LEDEN), 1, &Data);
84 ASSERT_EFI_ERROR (Status);
85
86 return EFI_SUCCESS;
87 }
88
89 EFI_STATUS
90 EFIAPI
91 PciEmulationEntryPoint (
92 IN EFI_HANDLE ImageHandle,
93 IN EFI_SYSTEM_TABLE *SystemTable
94 )
95 {
96 UINT8 CapabilityLength;
97 UINT8 PhysicalPorts;
98 UINTN MemorySize;
99
100 CapabilityLength = MmioRead8 (USB_EHCI_HCCAPBASE);
101 PhysicalPorts = MmioRead32 (USB_EHCI_HCCAPBASE + 0x4) & 0x0000000F;
102 MemorySize = CapabilityLength + HOST_CONTROLLER_OPERATION_REG_SIZE +
103 4 * PhysicalPorts - 1;
104
105 return RegisterNonDiscoverableMmioDevice (
106 NonDiscoverableDeviceTypeEhci,
107 NonDiscoverableDeviceDmaTypeNonCoherent,
108 ConfigureUSBHost,
109 NULL,
110 1,
111 USB_EHCI_HCCAPBASE, MemorySize
112 );
113 }