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