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