]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Usb/UsbBusPei/PeiUsbLib.c
MdeModulePkg UsbBusPei: Remove redundant functions
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusPei / PeiUsbLib.c
1 /** @file
2 Common Libarary for PEI USB
3
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved. <BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions
8 of the BSD License which accompanies this distribution. The
9 full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #include "UsbPeim.h"
18 #include "PeiUsbLib.h"
19
20 /**
21 Get a given usb descriptor.
22
23 @param PeiServices General-purpose services that are available to every PEIM.
24 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
25 @param Value Request Value.
26 @param Index Request Index.
27 @param DescriptorLength Request descriptor Length.
28 @param Descriptor Request descriptor.
29
30
31 @retval EFI_SUCCESS Usb descriptor is obtained successfully.
32 @retval EFI_DEVICE_ERROR Cannot get the usb descriptor due to a hardware error.
33 @retval Others Other failure occurs.
34
35 **/
36 EFI_STATUS
37 PeiUsbGetDescriptor (
38 IN EFI_PEI_SERVICES **PeiServices,
39 IN PEI_USB_IO_PPI *UsbIoPpi,
40 IN UINT16 Value,
41 IN UINT16 Index,
42 IN UINT16 DescriptorLength,
43 OUT VOID *Descriptor
44 )
45 {
46 EFI_USB_DEVICE_REQUEST DevReq;
47
48 ASSERT (UsbIoPpi != NULL);
49
50 DevReq.RequestType = USB_DEV_GET_DESCRIPTOR_REQ_TYPE;
51 DevReq.Request = USB_DEV_GET_DESCRIPTOR;
52 DevReq.Value = Value;
53 DevReq.Index = Index;
54 DevReq.Length = DescriptorLength;
55
56 return UsbIoPpi->UsbControlTransfer (
57 PeiServices,
58 UsbIoPpi,
59 &DevReq,
60 EfiUsbDataIn,
61 PcdGet32 (PcdUsbTransferTimeoutValue),
62 Descriptor,
63 DescriptorLength
64 );
65 }
66
67 /**
68 Set a usb device with a specified address.
69
70 @param PeiServices General-purpose services that are available to every PEIM.
71 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
72 @param AddressValue The address to assign.
73
74 @retval EFI_SUCCESS Usb device address is set successfully.
75 @retval EFI_DEVICE_ERROR Cannot set the usb address due to a hardware error.
76 @retval Others Other failure occurs.
77
78 **/
79 EFI_STATUS
80 PeiUsbSetDeviceAddress (
81 IN EFI_PEI_SERVICES **PeiServices,
82 IN PEI_USB_IO_PPI *UsbIoPpi,
83 IN UINT16 AddressValue
84 )
85 {
86 EFI_USB_DEVICE_REQUEST DevReq;
87
88 ASSERT (UsbIoPpi != NULL);
89
90 DevReq.RequestType = USB_DEV_SET_ADDRESS_REQ_TYPE;
91 DevReq.Request = USB_DEV_SET_ADDRESS;
92 DevReq.Value = AddressValue;
93 DevReq.Index = 0;
94 DevReq.Length = 0;
95
96 return UsbIoPpi->UsbControlTransfer (
97 PeiServices,
98 UsbIoPpi,
99 &DevReq,
100 EfiUsbNoData,
101 PcdGet32 (PcdUsbTransferTimeoutValue),
102 NULL,
103 0
104 );
105 }
106
107
108
109 /**
110 Configure a usb device to Configuration 1.
111
112 @param PeiServices General-purpose services that are available to every PEIM.
113 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
114
115 @retval EFI_SUCCESS Usb device is set to use Configuration 1 successfully.
116 @retval EFI_DEVICE_ERROR Cannot set the usb device due to a hardware error.
117 @retval Others Other failure occurs.
118
119 **/
120 EFI_STATUS
121 PeiUsbSetConfiguration (
122 IN EFI_PEI_SERVICES **PeiServices,
123 IN PEI_USB_IO_PPI *UsbIoPpi
124 )
125 {
126 EFI_USB_DEVICE_REQUEST DevReq;
127 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
128
129 DevReq.RequestType = USB_DEV_SET_CONFIGURATION_REQ_TYPE;
130 DevReq.Request = USB_DEV_SET_CONFIGURATION;
131 DevReq.Value = 1;
132
133 return UsbIoPpi->UsbControlTransfer (
134 PeiServices,
135 UsbIoPpi,
136 &DevReq,
137 EfiUsbNoData,
138 PcdGet32 (PcdUsbTransferTimeoutValue),
139 NULL,
140 0
141 );
142 }
143
144 /**
145 Judge if the port is connected with a usb device or not.
146
147 @param PortStatus The usb port status gotten.
148
149 @retval TRUE A usb device is connected with the port.
150 @retval FALSE No usb device is connected with the port.
151
152 **/
153 BOOLEAN
154 IsPortConnect (
155 IN UINT16 PortStatus
156 )
157 {
158 //
159 // return the bit 0 value of PortStatus
160 //
161 if ((PortStatus & USB_PORT_STAT_CONNECTION) != 0) {
162 return TRUE;
163 } else {
164 return FALSE;
165 }
166 }
167
168 /**
169 Get device speed according to port status.
170
171 @param PortStatus The usb port status gotten.
172
173 @return Device speed value.
174
175 **/
176 UINTN
177 PeiUsbGetDeviceSpeed (
178 IN UINT16 PortStatus
179 )
180 {
181 if ((PortStatus & USB_PORT_STAT_LOW_SPEED) != 0) {
182 return EFI_USB_SPEED_LOW;
183 } else if ((PortStatus & USB_PORT_STAT_HIGH_SPEED) != 0){
184 return EFI_USB_SPEED_HIGH;
185 } else if ((PortStatus & USB_PORT_STAT_SUPER_SPEED) != 0) {
186 return EFI_USB_SPEED_SUPER;
187 } else {
188 return EFI_USB_SPEED_FULL;
189 }
190 }
191
192