]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/I2c/I2cDxe/I2cDxe.h
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Bus / I2c / I2cDxe / I2cDxe.h
CommitLineData
43e543bc
EL
1/** @file\r
2 Private data structures for the I2C DXE driver.\r
3\r
4 This file defines common data structures, macro definitions and some module\r
5 internal function header files.\r
6\r
d1102dba 7 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
43e543bc
EL
8 This program and the accompanying materials\r
9 are licensed and made available under the terms and conditions of the BSD License\r
10 which accompanies this distribution. The full text of the license may be found at\r
11 http://opensource.org/licenses/bsd-license.php\r
12\r
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15\r
16**/\r
17\r
18#ifndef __I2C_DXE_H__\r
19#define __I2C_DXE_H__\r
20\r
21#include <Uefi.h>\r
22#include <Library/BaseMemoryLib.h>\r
23#include <Library/DebugLib.h>\r
24#include <Library/DevicePathLib.h>\r
25#include <Library/MemoryAllocationLib.h>\r
26#include <Library/TimerLib.h>\r
27#include <Library/UefiBootServicesTableLib.h>\r
28#include <Library/UefiDriverEntryPoint.h>\r
29#include <Library/UefiLib.h>\r
30\r
31#include <Protocol/DriverBinding.h>\r
32#include <Protocol/I2cEnumerate.h>\r
33#include <Protocol/I2cHost.h>\r
34#include <Protocol/I2cIo.h>\r
35#include <Protocol/I2cMaster.h>\r
36#include <Protocol/I2cBusConfigurationManagement.h>\r
37#include <Protocol/LoadedImage.h>\r
38\r
39#define I2C_DEVICE_SIGNATURE SIGNATURE_32 ('I', '2', 'C', 'D')\r
40#define I2C_HOST_SIGNATURE SIGNATURE_32 ('I', '2', 'C', 'H')\r
41#define I2C_REQUEST_SIGNATURE SIGNATURE_32 ('I', '2', 'C', 'R')\r
42\r
43//\r
44// Synchronize access to the list of requests\r
45//\r
46#define TPL_I2C_SYNC TPL_NOTIFY\r
47\r
48//\r
49// I2C bus context\r
50//\r
51typedef struct {\r
52 EFI_I2C_ENUMERATE_PROTOCOL *I2cEnumerate;\r
53 EFI_I2C_HOST_PROTOCOL *I2cHost;\r
54 EFI_HANDLE Controller;\r
55 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
d1102dba 56 EFI_HANDLE DriverBindingHandle;\r
43e543bc
EL
57} I2C_BUS_CONTEXT;\r
58\r
59//\r
60// I2C device context\r
61//\r
62typedef struct {\r
63 //\r
64 // Structure identification\r
65 //\r
66 UINT32 Signature;\r
67\r
68 //\r
69 // I2c device handle\r
70 //\r
71 EFI_HANDLE Handle;\r
72\r
73 //\r
74 // Upper level API to support the I2C device I/O\r
75 //\r
76 EFI_I2C_IO_PROTOCOL I2cIo;\r
77\r
78 //\r
79 // Device path for this device\r
80 //\r
81 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
82\r
83 //\r
84 // Platform specific data for this device\r
85 //\r
86 CONST EFI_I2C_DEVICE *I2cDevice;\r
87\r
88 //\r
89 // Context for the common I/O support including the\r
90 // lower level API to the host controller.\r
91 //\r
92 I2C_BUS_CONTEXT *I2cBusContext;\r
93} I2C_DEVICE_CONTEXT;\r
94\r
95#define I2C_DEVICE_CONTEXT_FROM_PROTOCOL(a) CR (a, I2C_DEVICE_CONTEXT, I2cIo, I2C_DEVICE_SIGNATURE)\r
96\r
97//\r
98// I2C Request\r
99//\r
100typedef struct {\r
101 //\r
102 // Signature\r
103 //\r
104 UINT32 Signature;\r
d1102dba 105\r
43e543bc
EL
106 //\r
107 // Next request in the pending request list\r
108 //\r
109 LIST_ENTRY Link;\r
110\r
111 //\r
112 // I2C bus configuration for the operation\r
113 //\r
114 UINTN I2cBusConfiguration;\r
115\r
116 //\r
117 // I2C slave address for the operation\r
118 //\r
119 UINTN SlaveAddress;\r
120\r
121 //\r
122 // Event to set for asynchronous operations, NULL for\r
123 // synchronous operations\r
124 //\r
125 EFI_EVENT Event;\r
126\r
127 //\r
128 // I2C operation description\r
129 //\r
130 EFI_I2C_REQUEST_PACKET *RequestPacket;\r
131\r
132 //\r
133 // Optional buffer to receive the I2C operation completion status\r
134 //\r
135 EFI_STATUS *Status;\r
136} I2C_REQUEST;\r
137\r
138#define I2C_REQUEST_FROM_ENTRY(a) CR (a, I2C_REQUEST, Link, I2C_REQUEST_SIGNATURE);\r
139\r
140//\r
141// I2C host context\r
142//\r
143typedef struct {\r
144 //\r
145 // Structure identification\r
146 //\r
147 UINTN Signature;\r
148\r
149 //\r
150 // Current I2C bus configuration\r
151 //\r
152 UINTN I2cBusConfiguration;\r
153\r
154 //\r
155 // I2C bus configuration management event\r
156 //\r
157 EFI_EVENT I2cBusConfigurationEvent;\r
158\r
159 //\r
160 // I2C operation completion event\r
161 //\r
162 EFI_EVENT I2cEvent;\r
163\r
164 //\r
165 // I2C operation and I2C bus configuration management status\r
166 //\r
167 EFI_STATUS Status;\r
168\r
169 //\r
170 // I2C bus configuration management operation pending\r
171 //\r
172 BOOLEAN I2cBusConfigurationManagementPending;\r
173\r
174 //\r
175 // I2C request list maintained by I2C Host\r
176 //\r
177 LIST_ENTRY RequestList;\r
178\r
179 //\r
180 // Upper level API\r
181 //\r
182 EFI_I2C_HOST_PROTOCOL I2cHost;\r
183\r
184 //\r
185 // I2C bus configuration management protocol\r
186 //\r
187 EFI_I2C_BUS_CONFIGURATION_MANAGEMENT_PROTOCOL *I2cBusConfigurationManagement;\r
188\r
189 //\r
190 // Lower level API for I2C master (controller)\r
191 //\r
192 EFI_I2C_MASTER_PROTOCOL *I2cMaster;\r
193} I2C_HOST_CONTEXT;\r
194\r
195#define I2C_HOST_CONTEXT_FROM_PROTOCOL(a) CR (a, I2C_HOST_CONTEXT, I2cHost, I2C_HOST_SIGNATURE)\r
196\r
197//\r
198// Global Variables\r
199//\r
200extern EFI_COMPONENT_NAME_PROTOCOL gI2cBusComponentName;\r
201extern EFI_COMPONENT_NAME2_PROTOCOL gI2cBusComponentName2;\r
202extern EFI_DRIVER_BINDING_PROTOCOL gI2cBusDriverBinding;\r
203\r
204extern EFI_COMPONENT_NAME_PROTOCOL gI2cHostComponentName;\r
205extern EFI_COMPONENT_NAME2_PROTOCOL gI2cHostComponentName2;\r
206extern EFI_DRIVER_BINDING_PROTOCOL gI2cHostDriverBinding;\r
207\r
208/**\r
209 Start the I2C driver\r
210\r
211 This routine allocates the necessary resources for the driver.\r
212\r
213 This routine is called by I2cBusDriverStart to complete the driver\r
214 initialization.\r
215\r
216 @param[in] I2cBus Address of an I2C_BUS_CONTEXT structure\r
217 @param[in] Controller Handle to the controller\r
218 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.\r
219\r
220 @retval EFI_SUCCESS Driver API properly initialized\r
d1102dba 221\r
43e543bc
EL
222**/\r
223EFI_STATUS\r
224RegisterI2cDevice (\r
225 IN I2C_BUS_CONTEXT *I2cBus,\r
226 IN EFI_HANDLE Controller,\r
227 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
228 );\r
229\r
230/**\r
231 Unregister an I2C device.\r
232\r
233 This function removes the protocols installed on the controller handle and\r
234 frees the resources allocated for the I2C device.\r
235\r
236 @param This The pointer to EFI_DRIVER_BINDING_PROTOCOL instance.\r
237 @param Controller The controller handle of the I2C device.\r
238 @param Handle The child handle.\r
239\r
240 @retval EFI_SUCCESS The I2C device is successfully unregistered.\r
241 @return Others Some error occurs when unregistering the I2C device.\r
242\r
243**/\r
244EFI_STATUS\r
245UnRegisterI2cDevice (\r
246 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
247 IN EFI_HANDLE Controller,\r
248 IN EFI_HANDLE Handle\r
249 );\r
250\r
251/**\r
252 Create a path for the I2C device\r
253\r
254 Append the I2C slave path to the I2C master controller path.\r
255\r
256 @param[in] I2cDeviceContext Address of an I2C_DEVICE_CONTEXT structure.\r
257 @param[in] BuildControllerNode Flag to build controller node in device path.\r
258\r
259 @retval EFI_SUCCESS The I2C device path is built successfully.\r
260 @return Others It is failed to built device path.\r
261\r
262**/\r
263EFI_STATUS\r
264I2cBusDevicePathAppend (\r
265 IN I2C_DEVICE_CONTEXT *I2cDeviceContext,\r
266 IN BOOLEAN BuildControllerNode\r
267 );\r
268\r
269/**\r
270 Queue an I2C transaction for execution on the I2C device.\r
271\r
272 This routine must be called at or below TPL_NOTIFY. For synchronous\r
273 requests this routine must be called at or below TPL_CALLBACK.\r
274\r
275 This routine queues an I2C transaction to the I2C controller for\r
276 execution on the I2C bus.\r
277\r
278 When Event is NULL, QueueRequest() operates synchronously and returns\r
279 the I2C completion status as its return value.\r
280\r
281 When Event is not NULL, QueueRequest() synchronously returns EFI_SUCCESS\r
282 indicating that the asynchronous I2C transaction was queued. The values\r
283 above are returned in the buffer pointed to by I2cStatus upon the\r
284 completion of the I2C transaction when I2cStatus is not NULL.\r
285\r
286 The upper layer driver writer provides the following to the platform\r
287 vendor:\r
d1102dba 288\r
43e543bc
EL
289 1. Vendor specific GUID for the I2C part\r
290 2. Guidance on proper construction of the slave address array when the\r
291 I2C device uses more than one slave address. The I2C bus protocol\r
292 uses the SlaveAddressIndex to perform relative to physical address\r
293 translation to access the blocks of hardware within the I2C device.\r
294\r
295 @param[in] This Pointer to an EFI_I2C_IO_PROTOCOL structure.\r
296 @param[in] SlaveAddressIndex Index value into an array of slave addresses\r
297 for the I2C device. The values in the array\r
298 are specified by the board designer, with the\r
299 third party I2C device driver writer providing\r
300 the slave address order.\r
301\r
302 For devices that have a single slave address,\r
303 this value must be zero. If the I2C device\r
304 uses more than one slave address then the\r
305 third party (upper level) I2C driver writer\r
306 needs to specify the order of entries in the\r
307 slave address array.\r
308\r
309 \ref ThirdPartyI2cDrivers "Third Party I2C\r
310 Drivers" section in I2cMaster.h.\r
311 @param[in] Event Event to signal for asynchronous transactions,\r
312 NULL for synchronous transactions\r
313 @param[in] RequestPacket Pointer to an EFI_I2C_REQUEST_PACKET structure\r
314 describing the I2C transaction\r
315 @param[out] I2cStatus Optional buffer to receive the I2C transaction\r
316 completion status\r
317\r
318 @retval EFI_SUCCESS The asynchronous transaction was successfully\r
319 queued when Event is not NULL.\r
320 @retval EFI_SUCCESS The transaction completed successfully when\r
321 Event is NULL.\r
322 @retval EFI_ABORTED The request did not complete because the driver\r
323 binding Stop() routine was called.\r
324 @retval EFI_BAD_BUFFER_SIZE The RequestPacket->LengthInBytes value is too\r
325 large.\r
326 @retval EFI_DEVICE_ERROR There was an I2C error (NACK) during the\r
327 transaction.\r
328 @retval EFI_INVALID_PARAMETER RequestPacket is NULL\r
329 @retval EFI_NOT_FOUND Reserved bit set in the SlaveAddress parameter\r
330 @retval EFI_NO_MAPPING The EFI_I2C_HOST_PROTOCOL could not set the\r
331 bus configuration required to access this I2C\r
332 device.\r
333 @retval EFI_NO_RESPONSE The I2C device is not responding to the slave\r
334 address selected by SlaveAddressIndex.\r
335 EFI_DEVICE_ERROR will be returned if the\r
336 controller cannot distinguish when the NACK\r
337 occurred.\r
338 @retval EFI_OUT_OF_RESOURCES Insufficient memory for I2C transaction\r
339 @retval EFI_UNSUPPORTED The controller does not support the requested\r
340 transaction.\r
341\r
342**/\r
343EFI_STATUS\r
344EFIAPI\r
345I2cBusQueueRequest (\r
346 IN CONST EFI_I2C_IO_PROTOCOL *This,\r
347 IN UINTN SlaveAddressIndex,\r
348 IN EFI_EVENT Event OPTIONAL,\r
349 IN EFI_I2C_REQUEST_PACKET *RequestPacket,\r
350 OUT EFI_STATUS *I2cStatus OPTIONAL\r
351 );\r
352\r
353/**\r
354 Tests to see if this driver supports a given controller. If a child device is provided,\r
355 it further tests to see if this driver supports creating a handle for the specified child device.\r
356\r
357 This function checks to see if the driver specified by This supports the device specified by\r
358 ControllerHandle. Drivers will typically use the device path attached to\r
359 ControllerHandle and/or the services from the bus I/O abstraction attached to\r
360 ControllerHandle to determine if the driver supports ControllerHandle. This function\r
361 may be called many times during platform initialization. In order to reduce boot times, the tests\r
362 performed by this function must be very small, and take as little time as possible to execute. This\r
363 function must not change the state of any hardware devices, and this function must be aware that the\r
364 device specified by ControllerHandle may already be managed by the same driver or a\r
365 different driver. This function must match its calls to AllocatePages() with FreePages(),\r
366 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
367 Since ControllerHandle may have been previously started by the same driver, if a protocol is\r
368 already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
369 to guarantee the state of ControllerHandle is not modified by this function.\r
370\r
371 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
372 @param[in] ControllerHandle The handle of the controller to test. This handle\r
373 must support a protocol interface that supplies\r
374 an I/O abstraction to the driver.\r
375 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
376 parameter is ignored by device drivers, and is optional for bus\r
377 drivers. For bus drivers, if this parameter is not NULL, then\r
378 the bus driver must determine if the bus controller specified\r
379 by ControllerHandle and the child controller specified\r
380 by RemainingDevicePath are both supported by this\r
381 bus driver.\r
382\r
383 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
384 RemainingDevicePath is supported by the driver specified by This.\r
385 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
386 RemainingDevicePath is already being managed by the driver\r
387 specified by This.\r
388 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
389 RemainingDevicePath is already being managed by a different\r
390 driver or an application that requires exclusive access.\r
391 Currently not implemented.\r
392 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
393 RemainingDevicePath is not supported by the driver specified by This.\r
394**/\r
395EFI_STATUS\r
396EFIAPI\r
397I2cBusDriverSupported (\r
398 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
399 IN EFI_HANDLE Controller,\r
400 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
401 );\r
402\r
403/**\r
404 Starts a device controller or a bus controller.\r
405\r
406 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
407 As a result, much of the error checking on the parameters to Start() has been moved into this\r
408 common boot service. It is legal to call Start() from other locations,\r
409 but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
410 1. ControllerHandle must be a valid EFI_HANDLE.\r
411 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
412 EFI_DEVICE_PATH_PROTOCOL.\r
413 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
414 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
415\r
416 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
417 @param[in] ControllerHandle The handle of the controller to start. This handle\r
418 must support a protocol interface that supplies\r
419 an I/O abstraction to the driver.\r
420 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
421 parameter is ignored by device drivers, and is optional for bus\r
422 drivers. For a bus driver, if this parameter is NULL, then handles\r
423 for all the children of Controller are created by this driver.\r
424 If this parameter is not NULL and the first Device Path Node is\r
425 not the End of Device Path Node, then only the handle for the\r
426 child device specified by the first Device Path Node of\r
427 RemainingDevicePath is created by this driver.\r
428 If the first Device Path Node of RemainingDevicePath is\r
429 the End of Device Path Node, no child handle is created by this\r
430 driver.\r
431\r
432 @retval EFI_SUCCESS The device was started.\r
433 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
434 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
435 @retval Others The driver failded to start the device.\r
436\r
437**/\r
438EFI_STATUS\r
439EFIAPI\r
440I2cBusDriverStart (\r
441 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
442 IN EFI_HANDLE Controller,\r
443 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
444 );\r
445\r
446/**\r
447 Stops a device controller or a bus controller.\r
448\r
449 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
450 As a result, much of the error checking on the parameters to Stop() has been moved\r
451 into this common boot service. It is legal to call Stop() from other locations,\r
452 but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
453 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
454 same driver's Start() function.\r
455 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
456 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
457 Start() function, and the Start() function must have called OpenProtocol() on\r
458 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
459\r
460 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
461 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
462 support a bus specific I/O protocol for the driver\r
463 to use to stop the device.\r
464 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
465 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
466 if NumberOfChildren is 0.\r
467\r
468 @retval EFI_SUCCESS The device was stopped.\r
469 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
470\r
471**/\r
472EFI_STATUS\r
473EFIAPI\r
474I2cBusDriverStop (\r
475 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
476 IN EFI_HANDLE Controller,\r
477 IN UINTN NumberOfChildren,\r
478 IN EFI_HANDLE *ChildHandleBuffer\r
479 );\r
480\r
481/**\r
482 Retrieves a Unicode string that is the user readable name of the driver.\r
483\r
484 This function retrieves the user readable name of a driver in the form of a\r
485 Unicode string. If the driver specified by This has a user readable name in\r
486 the language specified by Language, then a pointer to the driver name is\r
487 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
488 by This does not support the language specified by Language,\r
489 then EFI_UNSUPPORTED is returned.\r
490\r
491 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
492 EFI_COMPONENT_NAME_PROTOCOL instance.\r
493\r
494 @param Language[in] A pointer to a Null-terminated ASCII string\r
495 array indicating the language. This is the\r
496 language of the driver name that the caller is\r
497 requesting, and it must match one of the\r
498 languages specified in SupportedLanguages. The\r
499 number of languages supported by a driver is up\r
500 to the driver writer. Language is specified\r
501 in RFC 4646 or ISO 639-2 language code format.\r
502\r
503 @param DriverName[out] A pointer to the Unicode string to return.\r
504 This Unicode string is the name of the\r
505 driver specified by This in the language\r
506 specified by Language.\r
507\r
508 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
509 This and the language specified by Language was\r
510 returned in DriverName.\r
511\r
512 @retval EFI_INVALID_PARAMETER Language is NULL.\r
513\r
514 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
515\r
516 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
517 the language specified by Language.\r
518\r
519**/\r
520EFI_STATUS\r
521EFIAPI\r
522I2cBusComponentNameGetDriverName (\r
523 IN EFI_COMPONENT_NAME2_PROTOCOL *This,\r
524 IN CHAR8 *Language,\r
525 OUT CHAR16 **DriverName\r
526 );\r
d1102dba 527\r
43e543bc
EL
528/**\r
529 Retrieves a Unicode string that is the user readable name of the controller\r
530 that is being managed by a driver.\r
531\r
532 This function retrieves the user readable name of the controller specified by\r
533 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
534 driver specified by This has a user readable name in the language specified by\r
535 Language, then a pointer to the controller name is returned in ControllerName,\r
536 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
537 managing the controller specified by ControllerHandle and ChildHandle,\r
538 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
539 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
540\r
541 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
542 EFI_COMPONENT_NAME_PROTOCOL instance.\r
543\r
544 @param ControllerHandle[in] The handle of a controller that the driver\r
545 specified by This is managing. This handle\r
546 specifies the controller whose name is to be\r
547 returned.\r
548\r
549 @param ChildHandle[in] The handle of the child controller to retrieve\r
550 the name of. This is an optional parameter that\r
551 may be NULL. It will be NULL for device\r
552 drivers. It will also be NULL for a bus drivers\r
553 that wish to retrieve the name of the bus\r
554 controller. It will not be NULL for a bus\r
555 driver that wishes to retrieve the name of a\r
556 child controller.\r
557\r
558 @param Language[in] A pointer to a Null-terminated ASCII string\r
559 array indicating the language. This is the\r
560 language of the driver name that the caller is\r
561 requesting, and it must match one of the\r
562 languages specified in SupportedLanguages. The\r
563 number of languages supported by a driver is up\r
564 to the driver writer. Language is specified in\r
565 RFC 4646 or ISO 639-2 language code format.\r
566\r
567 @param ControllerName[out] A pointer to the Unicode string to return.\r
568 This Unicode string is the name of the\r
569 controller specified by ControllerHandle and\r
570 ChildHandle in the language specified by\r
571 Language from the point of view of the driver\r
572 specified by This.\r
573\r
574 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
575 the language specified by Language for the\r
576 driver specified by This was returned in\r
577 DriverName.\r
578\r
579 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
580\r
581 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
582 EFI_HANDLE.\r
583\r
584 @retval EFI_INVALID_PARAMETER Language is NULL.\r
585\r
586 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
587\r
588 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
589 managing the controller specified by\r
590 ControllerHandle and ChildHandle.\r
591\r
592 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
593 the language specified by Language.\r
594\r
595**/\r
596EFI_STATUS\r
597EFIAPI\r
598I2cBusComponentNameGetControllerName (\r
599 IN EFI_COMPONENT_NAME2_PROTOCOL *This,\r
600 IN EFI_HANDLE ControllerHandle,\r
601 IN EFI_HANDLE ChildHandle OPTIONAL,\r
602 IN CHAR8 *Language,\r
603 OUT CHAR16 **ControllerName\r
604 );\r
605\r
606/**\r
607 The user entry point for the I2C bus module. The user code starts with\r
608 this function.\r
609\r
610 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
611 @param[in] SystemTable A pointer to the EFI System Table.\r
612\r
613 @retval EFI_SUCCESS The entry point is executed successfully.\r
614 @retval other Some error occurs when executing this entry point.\r
615\r
616**/\r
617EFI_STATUS\r
618EFIAPI\r
619InitializeI2cBus(\r
620 IN EFI_HANDLE ImageHandle,\r
621 IN EFI_SYSTEM_TABLE *SystemTable\r
622 );\r
623\r
624/**\r
625 This is the unload handle for I2C bus module.\r
626\r
627 Disconnect the driver specified by ImageHandle from all the devices in the handle database.\r
628 Uninstall all the protocols installed in the driver entry point.\r
629\r
630 @param[in] ImageHandle The drivers' driver image.\r
631\r
632 @retval EFI_SUCCESS The image is unloaded.\r
633 @retval Others Failed to unload the image.\r
634\r
635**/\r
636EFI_STATUS\r
637EFIAPI\r
638I2cBusUnload (\r
639 IN EFI_HANDLE ImageHandle\r
640 );\r
641\r
642/**\r
643 Release all the resources allocated for the I2C device.\r
644\r
645 This function releases all the resources allocated for the I2C device.\r
646\r
647 @param I2cDeviceContext The I2C child device involved for the operation.\r
648\r
649**/\r
650VOID\r
651ReleaseI2cDeviceContext (\r
652 IN I2C_DEVICE_CONTEXT *I2cDeviceContext\r
653 );\r
654\r
655/**\r
656 Complete the current request\r
657\r
658 @param[in] I2cHost Address of an I2C_HOST_CONTEXT structure.\r
659 @param[in] Status Status of the I<sub>2</sub>C operation.\r
660\r
661 @return This routine returns the input status value.\r
662\r
663**/\r
664EFI_STATUS\r
665I2cHostRequestComplete (\r
666 I2C_HOST_CONTEXT *I2cHost,\r
667 EFI_STATUS Status\r
668 );\r
669\r
670/**\r
671 Enable access to the I2C bus configuration\r
672\r
673 @param[in] I2cHostContext Address of an I2C_HOST_CONTEXT structure\r
674\r
675 @retval EFI_SUCCESS The operation completed successfully.\r
676 @retval EFI_ABORTED The request did not complete because the driver\r
677 was shutdown.\r
678 @retval EFI_BAD_BUFFER_SIZE The WriteBytes or ReadBytes buffer size is too large.\r
679 @retval EFI_DEVICE_ERROR There was an I2C error (NACK) during the operation.\r
680 This could indicate the slave device is not present.\r
681 @retval EFI_INVALID_PARAMETER RequestPacket is NULL\r
682 @retval EFI_NO_MAPPING Invalid I2cBusConfiguration value\r
683 @retval EFI_NO_RESPONSE The I2C device is not responding to the\r
684 slave address. EFI_DEVICE_ERROR may also be\r
685 returned if the controller can not distinguish\r
686 when the NACK occurred.\r
687 @retval EFI_NOT_FOUND I2C slave address exceeds maximum address\r
688 @retval EFI_NOT_READY I2C bus is busy or operation pending, wait for\r
689 the event and then read status.\r
690 @retval EFI_OUT_OF_RESOURCES Insufficient memory for I2C operation\r
691 @retval EFI_TIMEOUT The transaction did not complete within an internally\r
692 specified timeout period.\r
693\r
694**/\r
695EFI_STATUS\r
696I2cHostRequestEnable (\r
697 I2C_HOST_CONTEXT *I2cHost\r
698 );\r
699\r
700/**\r
701 Tests to see if this driver supports a given controller. If a child device is provided,\r
702 it further tests to see if this driver supports creating a handle for the specified child device.\r
703\r
704 This function checks to see if the driver specified by This supports the device specified by\r
705 ControllerHandle. Drivers will typically use the device path attached to\r
706 ControllerHandle and/or the services from the bus I/O abstraction attached to\r
707 ControllerHandle to determine if the driver supports ControllerHandle. This function\r
708 may be called many times during platform initialization. In order to reduce boot times, the tests\r
709 performed by this function must be very small, and take as little time as possible to execute. This\r
710 function must not change the state of any hardware devices, and this function must be aware that the\r
711 device specified by ControllerHandle may already be managed by the same driver or a\r
712 different driver. This function must match its calls to AllocatePages() with FreePages(),\r
713 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
714 Since ControllerHandle may have been previously started by the same driver, if a protocol is\r
715 already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
716 to guarantee the state of ControllerHandle is not modified by this function.\r
717\r
718 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
719 @param[in] ControllerHandle The handle of the controller to test. This handle\r
720 must support a protocol interface that supplies\r
721 an I/O abstraction to the driver.\r
722 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
723 parameter is ignored by device drivers, and is optional for bus\r
724 drivers. For bus drivers, if this parameter is not NULL, then\r
725 the bus driver must determine if the bus controller specified\r
726 by ControllerHandle and the child controller specified\r
727 by RemainingDevicePath are both supported by this\r
728 bus driver.\r
729\r
730 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
731 RemainingDevicePath is supported by the driver specified by This.\r
732 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
733 RemainingDevicePath is already being managed by the driver\r
734 specified by This.\r
735 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
736 RemainingDevicePath is already being managed by a different\r
737 driver or an application that requires exclusive access.\r
738 Currently not implemented.\r
739 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
740 RemainingDevicePath is not supported by the driver specified by This.\r
741**/\r
742EFI_STATUS\r
743EFIAPI\r
744I2cHostDriverSupported (\r
745 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
746 IN EFI_HANDLE Controller,\r
747 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
748 );\r
749\r
750/**\r
751 Starts a device controller or a bus controller.\r
752\r
753 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
754 As a result, much of the error checking on the parameters to Start() has been moved into this\r
755 common boot service. It is legal to call Start() from other locations,\r
756 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
757 1. ControllerHandle must be a valid EFI_HANDLE.\r
758 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
759 EFI_DEVICE_PATH_PROTOCOL.\r
760 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
761 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
762\r
763 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
764 @param[in] ControllerHandle The handle of the controller to start. This handle\r
765 must support a protocol interface that supplies\r
766 an I/O abstraction to the driver.\r
767 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
768 parameter is ignored by device drivers, and is optional for bus\r
769 drivers. For a bus driver, if this parameter is NULL, then handles\r
770 for all the children of Controller are created by this driver.\r
771 If this parameter is not NULL and the first Device Path Node is\r
772 not the End of Device Path Node, then only the handle for the\r
773 child device specified by the first Device Path Node of\r
774 RemainingDevicePath is created by this driver.\r
775 If the first Device Path Node of RemainingDevicePath is\r
776 the End of Device Path Node, no child handle is created by this\r
777 driver.\r
778\r
779 @retval EFI_SUCCESS The device was started.\r
780 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
781 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
782 @retval Others The driver failded to start the device.\r
783\r
784**/\r
785EFI_STATUS\r
786EFIAPI\r
787I2cHostDriverStart (\r
788 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
789 IN EFI_HANDLE Controller,\r
790 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
791 );\r
d1102dba 792\r
43e543bc
EL
793/**\r
794 Stops a device controller or a bus controller.\r
795\r
796 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
797 As a result, much of the error checking on the parameters to Stop() has been moved\r
798 into this common boot service. It is legal to call Stop() from other locations,\r
799 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
800 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
801 same driver's Start() function.\r
802 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
803 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
804 Start() function, and the Start() function must have called OpenProtocol() on\r
805 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
806\r
807 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
808 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
809 support a bus specific I/O protocol for the driver\r
810 to use to stop the device.\r
811 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
812 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
813 if NumberOfChildren is 0.\r
814\r
815 @retval EFI_SUCCESS The device was stopped.\r
816 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
817\r
818**/\r
819EFI_STATUS\r
820EFIAPI\r
821I2cHostDriverStop (\r
822 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
823 IN EFI_HANDLE Controller,\r
824 IN UINTN NumberOfChildren,\r
825 IN EFI_HANDLE *ChildHandleBuffer\r
826 );\r
827\r
828/**\r
829 Retrieves a Unicode string that is the user readable name of the driver.\r
830\r
831 This function retrieves the user readable name of a driver in the form of a\r
832 Unicode string. If the driver specified by This has a user readable name in\r
833 the language specified by Language, then a pointer to the driver name is\r
834 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
835 by This does not support the language specified by Language,\r
836 then EFI_UNSUPPORTED is returned.\r
837\r
838 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
839 EFI_COMPONENT_NAME_PROTOCOL instance.\r
840\r
841 @param Language[in] A pointer to a Null-terminated ASCII string\r
842 array indicating the language. This is the\r
843 language of the driver name that the caller is\r
844 requesting, and it must match one of the\r
845 languages specified in SupportedLanguages. The\r
846 number of languages supported by a driver is up\r
847 to the driver writer. Language is specified\r
848 in RFC 4646 or ISO 639-2 language code format.\r
849\r
850 @param DriverName[out] A pointer to the Unicode string to return.\r
851 This Unicode string is the name of the\r
852 driver specified by This in the language\r
853 specified by Language.\r
854\r
855 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
856 This and the language specified by Language was\r
857 returned in DriverName.\r
858\r
859 @retval EFI_INVALID_PARAMETER Language is NULL.\r
860\r
861 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
862\r
863 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
864 the language specified by Language.\r
865\r
866**/\r
867EFI_STATUS\r
868EFIAPI\r
869I2cHostComponentNameGetDriverName (\r
870 IN EFI_COMPONENT_NAME2_PROTOCOL *This,\r
871 IN CHAR8 *Language,\r
872 OUT CHAR16 **DriverName\r
873 );\r
d1102dba 874\r
43e543bc
EL
875/**\r
876 Retrieves a Unicode string that is the user readable name of the controller\r
877 that is being managed by a driver.\r
878\r
879 This function retrieves the user readable name of the controller specified by\r
880 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
881 driver specified by This has a user readable name in the language specified by\r
882 Language, then a pointer to the controller name is returned in ControllerName,\r
883 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
884 managing the controller specified by ControllerHandle and ChildHandle,\r
885 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
886 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
887\r
888 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
889 EFI_COMPONENT_NAME_PROTOCOL instance.\r
890\r
891 @param ControllerHandle[in] The handle of a controller that the driver\r
892 specified by This is managing. This handle\r
893 specifies the controller whose name is to be\r
894 returned.\r
895\r
896 @param ChildHandle[in] The handle of the child controller to retrieve\r
897 the name of. This is an optional parameter that\r
898 may be NULL. It will be NULL for device\r
899 drivers. It will also be NULL for a bus drivers\r
900 that wish to retrieve the name of the bus\r
901 controller. It will not be NULL for a bus\r
902 driver that wishes to retrieve the name of a\r
903 child controller.\r
904\r
905 @param Language[in] A pointer to a Null-terminated ASCII string\r
906 array indicating the language. This is the\r
907 language of the driver name that the caller is\r
908 requesting, and it must match one of the\r
909 languages specified in SupportedLanguages. The\r
910 number of languages supported by a driver is up\r
911 to the driver writer. Language is specified in\r
912 RFC 4646 or ISO 639-2 language code format.\r
913\r
914 @param ControllerName[out] A pointer to the Unicode string to return.\r
915 This Unicode string is the name of the\r
916 controller specified by ControllerHandle and\r
917 ChildHandle in the language specified by\r
918 Language from the point of view of the driver\r
919 specified by This.\r
920\r
921 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
922 the language specified by Language for the\r
923 driver specified by This was returned in\r
924 DriverName.\r
925\r
926 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
927\r
928 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
929 EFI_HANDLE.\r
930\r
931 @retval EFI_INVALID_PARAMETER Language is NULL.\r
932\r
933 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
934\r
935 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
936 managing the controller specified by\r
937 ControllerHandle and ChildHandle.\r
938\r
939 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
940 the language specified by Language.\r
941\r
942**/\r
943EFI_STATUS\r
944EFIAPI\r
945I2cHostComponentNameGetControllerName (\r
946 IN EFI_COMPONENT_NAME2_PROTOCOL *This,\r
947 IN EFI_HANDLE ControllerHandle,\r
948 IN EFI_HANDLE ChildHandle OPTIONAL,\r
949 IN CHAR8 *Language,\r
950 OUT CHAR16 **ControllerName\r
951 );\r
952\r
953/**\r
954 Handle the bus available event\r
955\r
956 This routine is called at TPL_I2C_SYNC.\r
957\r
958 @param[in] Event Address of an EFI_EVENT handle\r
959 @param[in] Context Address of an I2C_HOST_CONTEXT structure\r
960\r
961**/\r
962VOID\r
963EFIAPI\r
964I2cHostRequestCompleteEvent (\r
965 IN EFI_EVENT Event,\r
966 IN VOID *Context\r
967 );\r
968\r
969/**\r
970 Handle the I2C bus configuration available event\r
971\r
972 This routine is called at TPL_I2C_SYNC.\r
973\r
974 @param[in] Event Address of an EFI_EVENT handle\r
975 @param[in] Context Address of an I2C_HOST_CONTEXT structure\r
976\r
977**/\r
978VOID\r
979EFIAPI\r
980I2cHostI2cBusConfigurationAvailable (\r
981 IN EFI_EVENT Event,\r
982 IN VOID *Context\r
983 );\r
984\r
985/**\r
986 Queue an I2C operation for execution on the I2C controller.\r
987\r
988 This routine must be called at or below TPL_NOTIFY. For synchronous\r
989 requests this routine must be called at or below TPL_CALLBACK.\r
990\r
991 N.B. The typical consumers of this API are the I2C bus driver and\r
992 on rare occasions the I2C test application. Extreme care must be\r
993 taken by other consumers of this API to prevent confusing the\r
994 third party I2C drivers due to a state change at the I2C device\r
995 which the third party I2C drivers did not initiate. I2C platform\r
996 drivers may use this API within these guidelines.\r
997\r
998 This layer uses the concept of I2C bus configurations to describe\r
999 the I2C bus. An I2C bus configuration is defined as a unique\r
1000 setting of the multiplexers and switches in the I2C bus which\r
1001 enable access to one or more I2C devices. When using a switch\r
1002 to divide a bus, due to speed differences, the I2C platform layer\r
1003 would define an I2C bus configuration for the I2C devices on each\r
1004 side of the switch. When using a multiplexer, the I2C platform\r
1005 layer defines an I2C bus configuration for each of the selector\r
1006 values required to control the multiplexer. See Figure 1 in the\r
1007 <a href="http://www.nxp.com/documents/user_manual/UM10204.pdf">I<sup>2</sup>C\r
1008 Specification</a> for a complex I2C bus configuration.\r
1009\r
1010 The I2C host driver processes all operations in FIFO order. Prior to\r
1011 performing the operation, the I2C host driver calls the I2C platform\r
1012 driver to reconfigure the switches and multiplexers in the I2C bus\r
1013 enabling access to the specified I2C device. The I2C platform driver\r
1014 also selects the maximum bus speed for the device. After the I2C bus\r
1015 is configured, the I2C host driver calls the I2C port driver to\r
1016 initialize the I2C controller and start the I2C operation.\r
1017\r
1018 @param[in] This Address of an EFI_I2C_HOST_PROTOCOL instance.\r
1019 @param[in] I2cBusConfiguration I2C bus configuration to access the I2C\r
1020 device.\r
1021 @param[in] SlaveAddress Address of the device on the I2C bus.\r
1022 @param[in] Event Event to set for asynchronous operations,\r
1023 NULL for synchronous operations\r
1024 @param[in] RequestPacket Address of an EFI_I2C_REQUEST_PACKET\r
1025 structure describing the I2C operation\r
1026 @param[out] I2cStatus Optional buffer to receive the I2C operation\r
1027 completion status\r
1028\r
1029 @retval EFI_SUCCESS The operation completed successfully.\r
1030 @retval EFI_ABORTED The request did not complete because the driver\r
1031 was shutdown.\r
1032 @retval EFI_BAD_BUFFER_SIZE The WriteBytes or ReadBytes buffer size is too large.\r
1033 @retval EFI_DEVICE_ERROR There was an I2C error (NACK) during the operation.\r
1034 This could indicate the slave device is not present.\r
1035 @retval EFI_INVALID_PARAMETER RequestPacket is NULL\r
1036 @retval EFI_INVALID_PARAMETER TPL is too high\r
1037 @retval EFI_NO_MAPPING Invalid I2cBusConfiguration value\r
1038 @retval EFI_NO_RESPONSE The I2C device is not responding to the\r
1039 slave address. EFI_DEVICE_ERROR may also be\r
1040 returned if the controller can not distinguish\r
1041 when the NACK occurred.\r
1042 @retval EFI_NOT_FOUND I2C slave address exceeds maximum address\r
1043 @retval EFI_NOT_READY I2C bus is busy or operation pending, wait for\r
1044 the event and then read status pointed to by\r
1045 the request packet.\r
1046 @retval EFI_OUT_OF_RESOURCES Insufficient memory for I2C operation\r
1047 @retval EFI_TIMEOUT The transaction did not complete within an internally\r
1048 specified timeout period.\r
1049\r
1050**/\r
1051EFI_STATUS\r
1052EFIAPI\r
1053I2cHostQueueRequest (\r
1054 IN CONST EFI_I2C_HOST_PROTOCOL *This,\r
1055 IN UINTN I2cBusConfiguration,\r
1056 IN UINTN SlaveAddress,\r
1057 IN EFI_EVENT Event OPTIONAL,\r
1058 IN EFI_I2C_REQUEST_PACKET *RequestPacket,\r
1059 OUT EFI_STATUS *I2cStatus OPTIONAL\r
1060 );\r
1061\r
1062/**\r
1063 The user Entry Point for I2C host module. The user code starts with this function.\r
1064\r
1065 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
1066 @param[in] SystemTable A pointer to the EFI System Table.\r
1067\r
1068 @retval EFI_SUCCESS The entry point is executed successfully.\r
1069 @retval other Some error occurs when executing this entry point.\r
1070\r
1071**/\r
1072EFI_STATUS\r
1073EFIAPI\r
1074InitializeI2cHost(\r
1075 IN EFI_HANDLE ImageHandle,\r
1076 IN EFI_SYSTEM_TABLE *SystemTable\r
1077 );\r
1078\r
1079/**\r
1080 This is the unload handle for I2C host module.\r
1081\r
1082 Disconnect the driver specified by ImageHandle from all the devices in the handle database.\r
1083 Uninstall all the protocols installed in the driver entry point.\r
1084\r
1085 @param[in] ImageHandle The drivers' driver image.\r
1086\r
1087 @retval EFI_SUCCESS The image is unloaded.\r
1088 @retval Others Failed to unload the image.\r
1089\r
1090**/\r
1091EFI_STATUS\r
1092EFIAPI\r
1093I2cHostUnload (\r
1094 IN EFI_HANDLE ImageHandle\r
1095 );\r
1096\r
1097#endif // __I2C_DXE_H__\r