]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Library/EdkUsbLib/hid.c
Rename PcdPlatformBusSpeed to PcdFSBClock and update help text.
[mirror_edk2.git] / EdkModulePkg / Library / EdkUsbLib / hid.c
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12 Module Name:\r
13\r
14 hid.c\r
15\r
16 Abstract:\r
17\r
18 HID class request\r
19\r
20 Revision History\r
21\r
22--*/\r
23\r
24//\r
25// Function to get HID descriptor\r
26//\r
27EFI_STATUS\r
28UsbGetHidDescriptor (\r
29 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
30 IN UINT8 InterfaceNum,\r
31 OUT EFI_USB_HID_DESCRIPTOR *HidDescriptor\r
32 )\r
33/*++\r
34\r
35 Routine Description:\r
36 Get Hid Descriptor\r
37\r
38 Arguments:\r
39 UsbIo - EFI_USB_IO_PROTOCOL\r
40 InterfaceNum - Hid interface number\r
41 HidDescriptor - Caller allocated buffer to store Usb hid descriptor\r
42 if successfully returned.\r
43\r
44 Returns:\r
45 EFI_SUCCESS\r
46 EFI_DEVICE_ERROR\r
47 EFI_TIMEOUT\r
48\r
49--*/\r
50{\r
51 UINT32 Status;\r
52 EFI_STATUS Result;\r
53 EFI_USB_DEVICE_REQUEST Request;\r
54\r
55 Request.RequestType = 0x81;\r
56 Request.Request = 0x06;\r
57 Request.Value = (UINT16) (0x21 << 8);\r
58 Request.Index = InterfaceNum;\r
59 Request.Length = sizeof (EFI_USB_HID_DESCRIPTOR);\r
60\r
61 Result = UsbIo->UsbControlTransfer (\r
62 UsbIo,\r
63 &Request,\r
64 EfiUsbDataIn,\r
65 TIMEOUT_VALUE,\r
66 HidDescriptor,\r
67 sizeof (EFI_USB_HID_DESCRIPTOR),\r
68 &Status\r
69 );\r
70\r
71 return Result;\r
72\r
73}\r
74//\r
75// Function to get Report Class descriptor\r
76//\r
77EFI_STATUS\r
78UsbGetReportDescriptor (\r
79 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
80 IN UINT8 InterfaceNum,\r
81 IN UINT16 DescriptorSize,\r
82 OUT UINT8 *DescriptorBuffer\r
83 )\r
84/*++\r
85\r
86 Routine Description:\r
87 get Report Class descriptor\r
88\r
89 Arguments:\r
90 UsbIo - EFI_USB_IO_PROTOCOL.\r
91 InterfaceNum - Report interface number.\r
92 DescriptorSize - Length of DescriptorBuffer.\r
93 DescriptorBuffer - Caller allocated buffer to store Usb report descriptor\r
94 if successfully returned.\r
95\r
96 Returns:\r
97 EFI_SUCCESS\r
98 EFI_DEVICE_ERROR\r
99 EFI_TIMEOUT\r
100\r
101--*/\r
102{\r
103 UINT32 Status;\r
104 EFI_STATUS Result;\r
105 EFI_USB_DEVICE_REQUEST Request;\r
106\r
107 //\r
108 // Fill Device request packet\r
109 //\r
110 Request.RequestType = 0x81;\r
111 Request.Request = 0x06;\r
112 Request.Value = (UINT16) (0x22 << 8);\r
113 Request.Index = InterfaceNum;\r
114 Request.Length = DescriptorSize;\r
115\r
116 Result = UsbIo->UsbControlTransfer (\r
117 UsbIo,\r
118 &Request,\r
119 EfiUsbDataIn,\r
120 TIMEOUT_VALUE,\r
121 DescriptorBuffer,\r
122 DescriptorSize,\r
123 &Status\r
124 );\r
125\r
126 return Result;\r
127\r
128}\r
129//\r
130// Following are HID class request\r
131//\r
132EFI_STATUS\r
133UsbGetProtocolRequest (\r
134 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
135 IN UINT8 Interface,\r
136 IN UINT8 *Protocol\r
137 )\r
138/*++\r
139\r
140 Routine Description:\r
141 Get Hid Protocol Request\r
142\r
143 Arguments:\r
144 UsbIo - EFI_USB_IO_PROTOCOL\r
145 Interface - Which interface the caller wants to get protocol\r
146 Protocol - Protocol value returned.\r
147\r
148 Returns:\r
149 EFI_SUCCESS\r
150 EFI_DEVICE_ERROR\r
151 EFI_TIMEOUT\r
152\r
153--*/\r
154{\r
155 UINT32 Status;\r
156 EFI_STATUS Result;\r
157 EFI_USB_DEVICE_REQUEST Request;\r
158\r
159 //\r
160 // Fill Device request packet\r
161 //\r
162 Request.RequestType = 0xa1;\r
163 //\r
164 // 10100001b;\r
165 //\r
166 Request.Request = EFI_USB_GET_PROTOCOL_REQUEST;\r
167 Request.Value = 0;\r
168 Request.Index = Interface;\r
169 Request.Length = 1;\r
170\r
171 Result = UsbIo->UsbControlTransfer (\r
172 UsbIo,\r
173 &Request,\r
174 EfiUsbDataIn,\r
175 TIMEOUT_VALUE,\r
176 Protocol,\r
177 sizeof (UINT8),\r
178 &Status\r
179 );\r
180\r
181 return Result;\r
182}\r
183\r
184\r
185EFI_STATUS\r
186UsbSetProtocolRequest (\r
187 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
188 IN UINT8 Interface,\r
189 IN UINT8 Protocol\r
190 )\r
191/*++\r
192\r
193 Routine Description:\r
194 Set Hid Protocol Request\r
195\r
196 Arguments:\r
197 UsbIo - EFI_USB_IO_PROTOCOL\r
198 Interface - Which interface the caller wants to set protocol\r
199 Protocol - Protocol value the caller wants to set.\r
200\r
201 Returns:\r
202 EFI_SUCCESS\r
203 EFI_DEVICE_ERROR\r
204 EFI_TIMEOUT\r
205\r
206--*/\r
207{\r
208 UINT32 Status;\r
209 EFI_STATUS Result;\r
210 EFI_USB_DEVICE_REQUEST Request;\r
211\r
212 //\r
213 // Fill Device request packet\r
214 //\r
215 Request.RequestType = 0x21;\r
216 //\r
217 // 00100001b;\r
218 //\r
219 Request.Request = EFI_USB_SET_PROTOCOL_REQUEST;\r
220 Request.Value = Protocol;\r
221 Request.Index = Interface;\r
222 Request.Length = 0;\r
223\r
224 Result = UsbIo->UsbControlTransfer (\r
225 UsbIo,\r
226 &Request,\r
227 EfiUsbNoData,\r
228 TIMEOUT_VALUE,\r
229 NULL,\r
230 0,\r
231 &Status\r
232 );\r
233 return Result;\r
234}\r
235\r
236\r
237EFI_STATUS\r
238UsbSetIdleRequest (\r
239 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
240 IN UINT8 Interface,\r
241 IN UINT8 ReportId,\r
242 IN UINT8 Duration\r
243 )\r
244/*++\r
245\r
246 Routine Description:\r
247 Set Idel request.\r
248\r
249 Arguments:\r
250 UsbIo - EFI_USB_IO_PROTOCOL\r
251 Interface - Which interface the caller wants to set.\r
252 ReportId - Which report the caller wants to set.\r
253 Duration - Idle rate the caller wants to set.\r
254\r
255 Returns:\r
256 EFI_SUCCESS\r
257 EFI_DEVICE_ERROR\r
258 EFI_TIMEOUT\r
259\r
260--*/\r
261{\r
262 UINT32 Status;\r
263 EFI_STATUS Result;\r
264 EFI_USB_DEVICE_REQUEST Request;\r
265\r
266 //\r
267 // Fill Device request packet\r
268 //\r
269 Request.RequestType = 0x21;\r
270 //\r
271 // 00100001b;\r
272 //\r
273 Request.Request = EFI_USB_SET_IDLE_REQUEST;\r
274 Request.Value = (UINT16) ((Duration << 8) | ReportId);\r
275 Request.Index = Interface;\r
276 Request.Length = 0;\r
277\r
278 Result = UsbIo->UsbControlTransfer (\r
279 UsbIo,\r
280 &Request,\r
281 EfiUsbNoData,\r
282 TIMEOUT_VALUE,\r
283 NULL,\r
284 0,\r
285 &Status\r
286 );\r
287 return Result;\r
288}\r
289\r
290EFI_STATUS\r
291UsbGetIdleRequest (\r
292 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
293 IN UINT8 Interface,\r
294 IN UINT8 ReportId,\r
295 OUT UINT8 *Duration\r
296 )\r
297/*++\r
298\r
299 Routine Description:\r
300 Get Idel request.\r
301\r
302 Arguments:\r
303 UsbIo - EFI_USB_IO_PROTOCOL\r
304 Interface - Which interface the caller wants to get.\r
305 ReportId - Which report the caller wants to get.\r
306 Duration - Idle rate the caller wants to get.\r
307\r
308 Returns:\r
309 EFI_SUCCESS\r
310 EFI_DEVICE_ERROR\r
311 EFI_TIMEOUT\r
312\r
313--*/\r
314{\r
315 UINT32 Status;\r
316 EFI_STATUS Result;\r
317 EFI_USB_DEVICE_REQUEST Request;\r
318\r
319 //\r
320 // Fill Device request packet\r
321 //\r
322 Request.RequestType = 0xa1;\r
323 //\r
324 // 10100001b;\r
325 //\r
326 Request.Request = EFI_USB_GET_IDLE_REQUEST;\r
327 Request.Value = ReportId;\r
328 Request.Index = Interface;\r
329 Request.Length = 1;\r
330\r
331 Result = UsbIo->UsbControlTransfer (\r
332 UsbIo,\r
333 &Request,\r
334 EfiUsbDataIn,\r
335 TIMEOUT_VALUE,\r
336 Duration,\r
337 1,\r
338 &Status\r
339 );\r
340\r
341 return Result;\r
342}\r
343\r
344\r
345EFI_STATUS\r
346UsbSetReportRequest (\r
347 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
348 IN UINT8 Interface,\r
349 IN UINT8 ReportId,\r
350 IN UINT8 ReportType,\r
351 IN UINT16 ReportLen,\r
352 IN UINT8 *Report\r
353 )\r
354/*++\r
355\r
356 Routine Description:\r
357 Hid Set Report request.\r
358\r
359 Arguments:\r
360 UsbIo - EFI_USB_IO_PROTOCOL\r
361 Interface - Which interface the caller wants to set.\r
362 ReportId - Which report the caller wants to set.\r
363 ReportType - Type of report.\r
364 ReportLen - Length of report descriptor.\r
365 Report - Report Descriptor buffer.\r
366\r
367 Returns:\r
368 EFI_SUCCESS\r
369 EFI_DEVICE_ERROR\r
370 EFI_TIMEOUT\r
371\r
372--*/\r
373{\r
374 UINT32 Status;\r
375 EFI_STATUS Result;\r
376 EFI_USB_DEVICE_REQUEST Request;\r
377\r
378 //\r
379 // Fill Device request packet\r
380 //\r
381 Request.RequestType = 0x21;\r
382 //\r
383 // 00100001b;\r
384 //\r
385 Request.Request = EFI_USB_SET_REPORT_REQUEST;\r
386 Request.Value = (UINT16) ((ReportType << 8) | ReportId);\r
387 Request.Index = Interface;\r
388 Request.Length = ReportLen;\r
389\r
390 Result = UsbIo->UsbControlTransfer (\r
391 UsbIo,\r
392 &Request,\r
393 EfiUsbDataOut,\r
394 TIMEOUT_VALUE,\r
395 Report,\r
396 ReportLen,\r
397 &Status\r
398 );\r
399\r
400 return Result;\r
401}\r
402\r
403EFI_STATUS\r
404UsbGetReportRequest (\r
405 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
406 IN UINT8 Interface,\r
407 IN UINT8 ReportId,\r
408 IN UINT8 ReportType,\r
409 IN UINT16 ReportLen,\r
410 IN UINT8 *Report\r
411 )\r
412/*++\r
413\r
414 Routine Description:\r
415 Hid Set Report request.\r
416\r
417 Arguments:\r
418 UsbIo - EFI_USB_IO_PROTOCOL\r
419 Interface - Which interface the caller wants to set.\r
420 ReportId - Which report the caller wants to set.\r
421 ReportType - Type of report.\r
422 ReportLen - Length of report descriptor.\r
423 Report - Caller allocated buffer to store Report Descriptor.\r
424\r
425 Returns:\r
426 EFI_SUCCESS\r
427 EFI_DEVICE_ERROR\r
428 EFI_TIMEOUT\r
429\r
430--*/\r
431{\r
432 UINT32 Status;\r
433 EFI_STATUS Result;\r
434 EFI_USB_DEVICE_REQUEST Request;\r
435\r
436 //\r
437 // Fill Device request packet\r
438 //\r
439 Request.RequestType = 0xa1;\r
440 //\r
441 // 10100001b;\r
442 //\r
443 Request.Request = EFI_USB_GET_REPORT_REQUEST;\r
444 Request.Value = (UINT16) ((ReportType << 8) | ReportId);\r
445 Request.Index = Interface;\r
446 Request.Length = ReportLen;\r
447\r
448 Result = UsbIo->UsbControlTransfer (\r
449 UsbIo,\r
450 &Request,\r
451 EfiUsbDataIn,\r
452 TIMEOUT_VALUE,\r
453 Report,\r
454 ReportLen,\r
455 &Status\r
456 );\r
457\r
458 return Result;\r
459}\r