2 Common Library for PEI USB
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved. <BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "PeiUsbLib.h"
14 Get a given usb descriptor.
16 @param PeiServices General-purpose services that are available to every PEIM.
17 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
18 @param Value Request Value.
19 @param Index Request Index.
20 @param DescriptorLength Request descriptor Length.
21 @param Descriptor Request descriptor.
24 @retval EFI_SUCCESS Usb descriptor is obtained successfully.
25 @retval EFI_DEVICE_ERROR Cannot get the usb descriptor due to a hardware error.
26 @retval Others Other failure occurs.
31 IN EFI_PEI_SERVICES
**PeiServices
,
32 IN PEI_USB_IO_PPI
*UsbIoPpi
,
35 IN UINT16 DescriptorLength
,
39 EFI_USB_DEVICE_REQUEST DevReq
;
41 ASSERT (UsbIoPpi
!= NULL
);
43 DevReq
.RequestType
= USB_DEV_GET_DESCRIPTOR_REQ_TYPE
;
44 DevReq
.Request
= USB_DEV_GET_DESCRIPTOR
;
47 DevReq
.Length
= DescriptorLength
;
49 return UsbIoPpi
->UsbControlTransfer (
54 PcdGet32 (PcdUsbTransferTimeoutValue
),
61 Set a usb device with a specified address.
63 @param PeiServices General-purpose services that are available to every PEIM.
64 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
65 @param AddressValue The address to assign.
67 @retval EFI_SUCCESS Usb device address is set successfully.
68 @retval EFI_DEVICE_ERROR Cannot set the usb address due to a hardware error.
69 @retval Others Other failure occurs.
73 PeiUsbSetDeviceAddress (
74 IN EFI_PEI_SERVICES
**PeiServices
,
75 IN PEI_USB_IO_PPI
*UsbIoPpi
,
76 IN UINT16 AddressValue
79 EFI_USB_DEVICE_REQUEST DevReq
;
81 ASSERT (UsbIoPpi
!= NULL
);
83 DevReq
.RequestType
= USB_DEV_SET_ADDRESS_REQ_TYPE
;
84 DevReq
.Request
= USB_DEV_SET_ADDRESS
;
85 DevReq
.Value
= AddressValue
;
89 return UsbIoPpi
->UsbControlTransfer (
94 PcdGet32 (PcdUsbTransferTimeoutValue
),
101 Configure a usb device to Configuration 1.
103 @param PeiServices General-purpose services that are available to every PEIM.
104 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
106 @retval EFI_SUCCESS Usb device is set to use Configuration 1 successfully.
107 @retval EFI_DEVICE_ERROR Cannot set the usb device due to a hardware error.
108 @retval Others Other failure occurs.
112 PeiUsbSetConfiguration (
113 IN EFI_PEI_SERVICES
**PeiServices
,
114 IN PEI_USB_IO_PPI
*UsbIoPpi
117 EFI_USB_DEVICE_REQUEST DevReq
;
119 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
121 DevReq
.RequestType
= USB_DEV_SET_CONFIGURATION_REQ_TYPE
;
122 DevReq
.Request
= USB_DEV_SET_CONFIGURATION
;
125 return UsbIoPpi
->UsbControlTransfer (
130 PcdGet32 (PcdUsbTransferTimeoutValue
),
137 Judge if the port is connected with a usb device or not.
139 @param PortStatus The usb port status gotten.
141 @retval TRUE A usb device is connected with the port.
142 @retval FALSE No usb device is connected with the port.
151 // return the bit 0 value of PortStatus
153 if ((PortStatus
& USB_PORT_STAT_CONNECTION
) != 0) {
161 Get device speed according to port status.
163 @param PortStatus The usb port status gotten.
165 @return Device speed value.
169 PeiUsbGetDeviceSpeed (
173 if ((PortStatus
& USB_PORT_STAT_LOW_SPEED
) != 0) {
174 return EFI_USB_SPEED_LOW
;
175 } else if ((PortStatus
& USB_PORT_STAT_HIGH_SPEED
) != 0) {
176 return EFI_USB_SPEED_HIGH
;
177 } else if ((PortStatus
& USB_PORT_STAT_SUPER_SPEED
) != 0) {
178 return EFI_USB_SPEED_SUPER
;
180 return EFI_USB_SPEED_FULL
;