2 I2C Library for Quark I2C Controller.
3 Follows I2C Controller setup instructions as detailed in
4 Quark DataSheet (doc id: 329676) Section 19.1/19.1.3.
7 Copyright (c) 2013-2015 Intel Corporation.
9 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include "CommonHeader.h"
16 The Called to Common Service Entry.
23 I2cCommonServiceEntry (
24 OUT UINT16
*SaveCmdPtr
,
25 OUT UINT32
*SaveBar0Ptr
28 *SaveBar0Ptr
= IohMmPci32 (0, I2C_Bus
, I2C_Device
, I2C_Func
, PCI_BAR0
);
29 if (((*SaveBar0Ptr
) & B_IOH_I2C_GPIO_MEMBAR_ADDR_MASK
) == 0) {
31 IohMmPci32(0, I2C_Bus
, I2C_Device
, I2C_Func
, PCI_BAR0
) =
32 FixedPcdGet32 (PcdIohI2cMmioBase
) & B_IOH_I2C_GPIO_MEMBAR_ADDR_MASK
;
35 // also Save Cmd Register, Setup by InitializeInternal later during xfers.
37 *SaveCmdPtr
= IohMmPci16 (0, I2C_Bus
, I2C_Device
, I2C_Func
, PCI_CMD
);
42 The Called on Common Service Exit.
48 I2cCommonServiceExit (
49 IN CONST UINT16 SaveCmd
,
50 IN CONST UINT32 SaveBar0
54 if ((SaveBar0
& B_IOH_I2C_GPIO_MEMBAR_ADDR_MASK
) == 0) {
55 IohMmPci16 (0, I2C_Bus
, I2C_Device
, I2C_Func
, PCI_CMD
) = SaveCmd
;
56 IohMmPci32 (0, I2C_Bus
, I2C_Device
, I2C_Func
, PCI_BAR0
) = SaveBar0
;
62 The GetI2CIoPortBaseAddress() function gets IO port base address of I2C Controller.
64 Always reads PCI configuration space to get MMIO base address of I2C Controller.
66 @return The IO port base address of I2C controller.
70 GetI2CIoPortBaseAddress (
74 UINTN I2CIoPortBaseAddress
;
77 // Get I2C Memory Mapped registers base address.
79 I2CIoPortBaseAddress
= IohMmPci32(0, I2C_Bus
, I2C_Device
, I2C_Func
, PCI_BAR0
);
82 // Make sure that the IO port base address has been properly set.
84 ASSERT (I2CIoPortBaseAddress
!= 0);
85 ASSERT (I2CIoPortBaseAddress
!= 0xFF);
87 return I2CIoPortBaseAddress
;
92 The EnableI2CMmioSpace() function enables access to I2C MMIO space.
103 // Read PCICMD. Bus=0, Dev=0, Func=0, Reg=0x4
105 PciCmd
= IohMmPci8(0, I2C_Bus
, I2C_Device
, I2C_Func
, PCI_REG_PCICMD
);
108 // Enable Bus Master(Bit2), MMIO Space(Bit1) & I/O Space(Bit0)
111 IohMmPci8(0, I2C_Bus
, I2C_Device
, I2C_Func
, PCI_REG_PCICMD
) = PciCmd
;
116 The DisableI2CController() functions disables I2C Controller.
120 DisableI2CController (
124 UINTN I2CIoPortBaseAddress
;
132 // Get I2C Memory Mapped registers base address.
134 I2CIoPortBaseAddress
= GetI2CIoPortBaseAddress ();
137 // Disable the I2C Controller by setting IC_ENABLE.ENABLE to zero
139 Addr
= I2CIoPortBaseAddress
+ I2C_REG_ENABLE
;
140 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
141 Data
&= ~B_I2C_REG_ENABLE
;
142 *((volatile UINT32
*) (UINTN
)(Addr
)) = Data
;
145 // Read the IC_ENABLE_STATUS.IC_EN Bit to check if Controller is disabled
148 Addr
= I2CIoPortBaseAddress
+ I2C_REG_ENABLE_STATUS
;
149 Data
= *((volatile UINT32
*) (UINTN
)(Addr
)) & I2C_REG_ENABLE_STATUS
;
152 // Poll the IC_ENABLE_STATUS.IC_EN Bit to check if Controller is disabled, until timeout (TI2C_POLL*MAX_T_POLL_COUNT).
155 if (PollCount
>= MAX_T_POLL_COUNT
) {
158 MicroSecondDelay(TI2C_POLL
);
159 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
160 Data
&= I2C_REG_ENABLE_STATUS
;
164 // Asset if controller does not enter Disabled state.
166 ASSERT (PollCount
< MAX_T_POLL_COUNT
);
169 // Read IC_CLR_INTR register to automatically clear the combined interrupt,
170 // all individual interrupts and the IC_TX_ABRT_SOURCE register.
172 Addr
= I2CIoPortBaseAddress
+ I2C_REG_CLR_INT
;
173 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
178 The EnableI2CController() function enables the I2C Controller.
182 EnableI2CController (
186 UINTN I2CIoPortBaseAddress
;
191 // Get I2C Memory Mapped registers base address.
193 I2CIoPortBaseAddress
= GetI2CIoPortBaseAddress ();
196 // Enable the I2C Controller by setting IC_ENABLE.ENABLE to 1
198 Addr
= I2CIoPortBaseAddress
+ I2C_REG_ENABLE
;
199 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
200 Data
|= B_I2C_REG_ENABLE
;
201 *((volatile UINT32
*) (UINTN
)(Addr
)) = Data
;
204 // Clear overflow and abort error status bits before transactions.
206 Addr
= I2CIoPortBaseAddress
+ I2C_REG_CLR_RX_OVER
;
207 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
208 Addr
= I2CIoPortBaseAddress
+ I2C_REG_CLR_TX_OVER
;
209 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
210 Addr
= I2CIoPortBaseAddress
+ I2C_REG_CLR_TX_ABRT
;
211 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
216 The WaitForStopDet() function waits until I2C STOP Condition occurs,
217 indicating transfer completion.
219 @retval EFI_SUCCESS Stop detected.
220 @retval EFI_TIMEOUT Timeout while waiting for stop condition.
221 @retval EFI_ABORTED Tx abort signaled in HW status register.
222 @retval EFI_DEVICE_ERROR Tx or Rx overflow detected.
230 UINTN I2CIoPortBaseAddress
;
236 Status
= EFI_SUCCESS
;
241 // Get I2C Memory Mapped registers base address.
243 I2CIoPortBaseAddress
= GetI2CIoPortBaseAddress ();
246 // Wait for STOP Detect.
248 Addr
= I2CIoPortBaseAddress
+ I2C_REG_RAW_INTR_STAT
;
251 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
252 if ((Data
& I2C_REG_RAW_INTR_STAT_TX_ABRT
) != 0) {
253 Status
= EFI_ABORTED
;
256 if ((Data
& I2C_REG_RAW_INTR_STAT_TX_OVER
) != 0) {
257 Status
= EFI_DEVICE_ERROR
;
260 if ((Data
& I2C_REG_RAW_INTR_STAT_RX_OVER
) != 0) {
261 Status
= EFI_DEVICE_ERROR
;
264 if ((Data
& I2C_REG_RAW_INTR_STAT_STOP_DET
) != 0) {
265 Status
= EFI_SUCCESS
;
268 MicroSecondDelay(TI2C_POLL
);
270 if (PollCount
>= MAX_STOP_DET_POLL_COUNT
) {
271 Status
= EFI_TIMEOUT
;
282 The InitializeInternal() function initialises internal I2C Controller
283 register values that are commonly required for I2C Write and Read transfers.
285 @param AddrMode I2C Addressing Mode: 7-bit or 10-bit address.
287 @retval EFI_SUCCESS I2C Operation completed successfully.
292 IN EFI_I2C_ADDR_MODE AddrMode
295 UINTN I2CIoPortBaseAddress
;
300 Status
= EFI_SUCCESS
;
303 // Enable access to I2C Controller MMIO space.
305 EnableI2CMmioSpace ();
308 // Disable I2C Controller initially
310 DisableI2CController ();
313 // Get I2C Memory Mapped registers base address.
315 I2CIoPortBaseAddress
= GetI2CIoPortBaseAddress ();
320 Addr
= I2CIoPortBaseAddress
+ I2C_REG_CLR_START_DET
;
321 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
322 Data
&= ~B_I2C_REG_CLR_START_DET
;
323 *((volatile UINT32
*) (UINTN
)(Addr
)) = Data
;
328 Addr
= I2CIoPortBaseAddress
+ I2C_REG_CLR_STOP_DET
;
329 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
330 Data
&= ~B_I2C_REG_CLR_STOP_DET
;
331 *((volatile UINT32
*) (UINTN
)(Addr
)) = Data
;
334 // Set addressing mode to user defined (7 or 10 bit) and
335 // speed mode to that defined by PCD (standard mode default).
337 Addr
= I2CIoPortBaseAddress
+ I2C_REG_CON
;
338 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
339 // Set Addressing Mode
340 if (AddrMode
== EfiI2CSevenBitAddrMode
) {
341 Data
&= ~B_I2C_REG_CON_10BITADD_MASTER
;
343 Data
|= B_I2C_REG_CON_10BITADD_MASTER
;
346 Data
&= ~B_I2C_REG_CON_SPEED
;
347 if (FeaturePcdGet (PcdI2CFastModeEnabled
)) {
352 *((volatile UINT32
*) (UINTN
)(Addr
)) = Data
;
354 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
362 The WriteByte() function provides a standard way to execute a
363 standard single byte write to an IC2 device (without accessing
364 sub-addresses), as defined in the I2C Specification.
366 @param I2CAddress I2C Slave device address
367 @param Value The 8-bit value to write.
369 @retval EFI_SUCCESS Transfer success.
370 @retval EFI_UNSUPPORTED Unsupported input param.
371 @retval EFI_TIMEOUT Timeout while waiting xfer.
372 @retval EFI_ABORTED Controller aborted xfer.
373 @retval EFI_DEVICE_ERROR Device error detected by controller.
383 UINTN I2CIoPortBaseAddress
;
389 // Get I2C Memory Mapped registers base address
391 I2CIoPortBaseAddress
= GetI2CIoPortBaseAddress ();
394 // Write to the IC_TAR register the address of the slave device to be addressed
396 Addr
= I2CIoPortBaseAddress
+ I2C_REG_TAR
;
397 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
398 Data
&= ~B_I2C_REG_TAR
;
400 *((volatile UINT32
*) (UINTN
)(Addr
)) = Data
;
403 // Enable the I2C Controller
405 EnableI2CController ();
408 // Write the data and transfer direction to the IC_DATA_CMD register.
409 // Also specify that transfer should be terminated by STOP condition.
411 Addr
= I2CIoPortBaseAddress
+ I2C_REG_DATA_CMD
;
412 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
414 Data
|= (UINT8
)Value
;
415 Data
&= ~B_I2C_REG_DATA_CMD_RW
;
416 Data
|= B_I2C_REG_DATA_CMD_STOP
;
417 *((volatile UINT32
*) (UINTN
)(Addr
)) = Data
;
420 // Wait for transfer completion.
422 Status
= WaitForStopDet ();
425 // Ensure I2C Controller disabled.
427 DisableI2CController();
434 The ReadByte() function provides a standard way to execute a
435 standard single byte read to an IC2 device (without accessing
436 sub-addresses), as defined in the I2C Specification.
438 @param I2CAddress I2C Slave device address
439 @param ReturnDataPtr Pointer to location to receive read byte.
441 @retval EFI_SUCCESS Transfer success.
442 @retval EFI_UNSUPPORTED Unsupported input param.
443 @retval EFI_TIMEOUT Timeout while waiting xfer.
444 @retval EFI_ABORTED Controller aborted xfer.
445 @retval EFI_DEVICE_ERROR Device error detected by controller.
452 OUT UINT8
*ReturnDataPtr
455 UINTN I2CIoPortBaseAddress
;
461 // Get I2C Memory Mapped registers base address.
463 I2CIoPortBaseAddress
= GetI2CIoPortBaseAddress ();
466 // Write to the IC_TAR register the address of the slave device to be addressed
468 Addr
= I2CIoPortBaseAddress
+ I2C_REG_TAR
;
469 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
470 Data
&= ~B_I2C_REG_TAR
;
472 *((volatile UINT32
*) (UINTN
)(Addr
)) = Data
;
475 // Enable the I2C Controller
477 EnableI2CController ();
480 // Write transfer direction to the IC_DATA_CMD register and
481 // specify that transfer should be terminated by STOP condition.
483 Addr
= I2CIoPortBaseAddress
+ I2C_REG_DATA_CMD
;
484 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
486 Data
|= B_I2C_REG_DATA_CMD_RW
;
487 Data
|= B_I2C_REG_DATA_CMD_STOP
;
488 *((volatile UINT32
*) (UINTN
)(Addr
)) = Data
;
491 // Wait for transfer completion
493 Status
= WaitForStopDet ();
494 if (!EFI_ERROR(Status
)) {
497 // Clear RX underflow before reading IC_DATA_CMD.
499 Addr
= I2CIoPortBaseAddress
+ I2C_REG_CLR_RX_UNDER
;
500 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
503 // Obtain and return read data byte from RX buffer (IC_DATA_CMD[7:0]).
505 Addr
= I2CIoPortBaseAddress
+ I2C_REG_DATA_CMD
;
506 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
508 *ReturnDataPtr
= (UINT8
) Data
;
510 Addr
= I2CIoPortBaseAddress
+ I2C_REG_RAW_INTR_STAT
;
511 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
512 Data
&= I2C_REG_RAW_INTR_STAT_RX_UNDER
;
514 Status
= EFI_DEVICE_ERROR
;
519 // Ensure I2C Controller disabled.
521 DisableI2CController ();
528 The WriteMultipleByte() function provides a standard way to execute
529 multiple byte writes to an IC2 device (e.g. when accessing sub-addresses or
530 when writing block of data), as defined in the I2C Specification.
532 @param I2CAddress The I2C slave address of the device
533 with which to communicate.
535 @param WriteBuffer Contains the value of byte to be written to the
538 @param Length No. of bytes to be written.
540 @retval EFI_SUCCESS Transfer success.
541 @retval EFI_UNSUPPORTED Unsupported input param.
542 @retval EFI_TIMEOUT Timeout while waiting xfer.
543 @retval EFI_ABORTED Tx abort signaled in HW status register.
544 @retval EFI_DEVICE_ERROR Tx overflow detected.
551 IN UINT8
*WriteBuffer
,
555 UINTN I2CIoPortBaseAddress
;
561 if (Length
> I2C_FIFO_SIZE
) {
562 return EFI_UNSUPPORTED
; // Routine does not handle xfers > fifo size.
565 I2CIoPortBaseAddress
= GetI2CIoPortBaseAddress ();
568 // Write to the IC_TAR register the address of the slave device to be addressed
570 Addr
= I2CIoPortBaseAddress
+ I2C_REG_TAR
;
571 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
572 Data
&= ~B_I2C_REG_TAR
;
574 *((volatile UINT32
*) (UINTN
)(Addr
)) = Data
;
577 // Enable the I2C Controller
579 EnableI2CController ();
582 // Write the data and transfer direction to the IC_DATA_CMD register.
583 // Also specify that transfer should be terminated by STOP condition.
585 Addr
= I2CIoPortBaseAddress
+ I2C_REG_DATA_CMD
;
586 for (Index
= 0; Index
< Length
; Index
++) {
587 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
589 Data
|= (UINT8
)WriteBuffer
[Index
];
590 Data
&= ~B_I2C_REG_DATA_CMD_RW
;
591 if (Index
== (Length
-1)) {
592 Data
|= B_I2C_REG_DATA_CMD_STOP
;
594 *((volatile UINT32
*) (UINTN
)(Addr
)) = Data
;
598 // Wait for transfer completion
600 Status
= WaitForStopDet ();
603 // Ensure I2C Controller disabled.
605 DisableI2CController ();
611 The ReadMultipleByte() function provides a standard way to execute
612 multiple byte writes to an IC2 device (e.g. when accessing sub-addresses or
613 when reading block of data), as defined in the I2C Specification (I2C combined
614 write/read protocol).
616 @param I2CAddress The I2C slave address of the device
617 with which to communicate.
619 @param Buffer Contains the value of byte data written or read from the
622 @param WriteLength No. of bytes to be written. In this case data
623 written typically contains sub-address or sub-addresses
624 in Hi-Lo format, that need to be read (I2C combined
625 write/read protocol).
627 @param ReadLength No. of bytes to be read from I2C slave device.
629 @retval EFI_SUCCESS Transfer success.
630 @retval EFI_UNSUPPORTED Unsupported input param.
631 @retval EFI_TIMEOUT Timeout while waiting xfer.
632 @retval EFI_ABORTED Tx abort signaled in HW status register.
633 @retval EFI_DEVICE_ERROR Rx underflow or Rx/Tx overflow detected.
640 IN OUT UINT8
*Buffer
,
641 IN UINTN WriteLength
,
645 UINTN I2CIoPortBaseAddress
;
652 if (WriteLength
> I2C_FIFO_SIZE
|| ReadLength
> I2C_FIFO_SIZE
) {
653 return EFI_UNSUPPORTED
; // Routine does not handle xfers > fifo size.
656 I2CIoPortBaseAddress
= GetI2CIoPortBaseAddress ();
659 // Write to the IC_TAR register the address of the slave device to be addressed
661 Addr
= I2CIoPortBaseAddress
+ I2C_REG_TAR
;
662 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
663 Data
&= ~B_I2C_REG_TAR
;
665 *((volatile UINT32
*) (UINTN
)(Addr
)) = Data
;
668 // Enable the I2C Controller
670 EnableI2CController ();
673 // Write the data (sub-addresses) to the IC_DATA_CMD register.
675 Addr
= I2CIoPortBaseAddress
+ I2C_REG_DATA_CMD
;
676 for (Index
= 0; Index
< WriteLength
; Index
++) {
677 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
679 Data
|= (UINT8
)Buffer
[Index
];
680 Data
&= ~B_I2C_REG_DATA_CMD_RW
;
681 *((volatile UINT32
*) (UINTN
)(Addr
)) = Data
;
685 // Issue Read Transfers for each byte (Restart issued when write/read bit changed).
687 for (Index
= 0; Index
< ReadLength
; Index
++) {
688 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
689 Data
|= B_I2C_REG_DATA_CMD_RW
;
690 // Issue a STOP for last read transfer.
691 if (Index
== (ReadLength
-1)) {
692 Data
|= B_I2C_REG_DATA_CMD_STOP
;
694 *((volatile UINT32
*) (UINTN
)(Addr
)) = Data
;
698 // Wait for STOP condition.
700 Status
= WaitForStopDet ();
701 if (!EFI_ERROR(Status
)) {
704 // Poll Receive FIFO Buffer Level register until valid (upto MAX_T_POLL_COUNT times).
708 Addr
= I2CIoPortBaseAddress
+ I2C_REG_RXFLR
;
709 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
710 while ((Data
!= ReadLength
) && (PollCount
< MAX_T_POLL_COUNT
)) {
711 MicroSecondDelay(TI2C_POLL
);
713 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
716 Addr
= I2CIoPortBaseAddress
+ I2C_REG_RAW_INTR_STAT
;
717 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
720 // If no timeout or device error then read rx data.
722 if (PollCount
== MAX_T_POLL_COUNT
) {
723 Status
= EFI_TIMEOUT
;
724 } else if ((Data
& I2C_REG_RAW_INTR_STAT_RX_OVER
) != 0) {
725 Status
= EFI_DEVICE_ERROR
;
729 // Clear RX underflow before reading IC_DATA_CMD.
731 Addr
= I2CIoPortBaseAddress
+ I2C_REG_CLR_RX_UNDER
;
732 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
737 Addr
= I2CIoPortBaseAddress
+ I2C_REG_DATA_CMD
;
738 for (Index
= 0; Index
< ReadLength
; Index
++) {
739 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
741 *(Buffer
+Index
) = (UINT8
)Data
;
743 Addr
= I2CIoPortBaseAddress
+ I2C_REG_RAW_INTR_STAT
;
744 Data
= *((volatile UINT32
*) (UINTN
)(Addr
));
745 Data
&= I2C_REG_RAW_INTR_STAT_RX_UNDER
;
747 Status
= EFI_DEVICE_ERROR
;
749 Status
= EFI_SUCCESS
;
755 // Ensure I2C Controller disabled.
757 DisableI2CController ();
764 The I2cWriteByte() function is a wrapper function for the WriteByte function.
765 Provides a standard way to execute a standard single byte write to an IC2 device
766 (without accessing sub-addresses), as defined in the I2C Specification.
768 @param SlaveAddress The I2C slave address of the device
769 with which to communicate.
771 @param AddrMode I2C Addressing Mode: 7-bit or 10-bit address.
773 @param Buffer Contains the value of byte data to execute to the
777 @retval EFI_SUCCESS Transfer success.
778 @retval EFI_INVALID_PARAMETER This or Buffer pointers are invalid.
779 @retval EFI_UNSUPPORTED Unsupported input param.
780 @retval EFI_TIMEOUT Timeout while waiting xfer.
781 @retval EFI_ABORTED Controller aborted xfer.
782 @retval EFI_DEVICE_ERROR Device error detected by controller.
788 IN EFI_I2C_DEVICE_ADDRESS SlaveAddress
,
789 IN EFI_I2C_ADDR_MODE AddrMode
,
798 if (Buffer
== NULL
) {
799 return EFI_INVALID_PARAMETER
;
804 I2cCommonServiceEntry (&SaveCmd
, &SaveBar0
);
806 Status
= EFI_SUCCESS
;
808 I2CAddress
= SlaveAddress
.I2CDeviceAddress
;
809 Status
= InitializeInternal (AddrMode
);
810 if (!EFI_ERROR(Status
)) {
811 Status
= WriteByte (I2CAddress
, *(UINT8
*) Buffer
);
814 I2cCommonServiceExit (SaveCmd
, SaveBar0
);
820 The I2cReadByte() function is a wrapper function for the ReadByte function.
821 Provides a standard way to execute a standard single byte read to an I2C device
822 (without accessing sub-addresses), as defined in the I2C Specification.
824 @param SlaveAddress The I2C slave address of the device
825 with which to communicate.
827 @param AddrMode I2C Addressing Mode: 7-bit or 10-bit address.
829 @param Buffer Contains the value of byte data read from the
833 @retval EFI_SUCCESS Transfer success.
834 @retval EFI_INVALID_PARAMETER This or Buffer pointers are invalid.
835 @retval EFI_TIMEOUT Timeout while waiting xfer.
836 @retval EFI_ABORTED Controller aborted xfer.
837 @retval EFI_DEVICE_ERROR Device error detected by controller.
844 IN EFI_I2C_DEVICE_ADDRESS SlaveAddress
,
845 IN EFI_I2C_ADDR_MODE AddrMode
,
854 if (Buffer
== NULL
) {
855 return EFI_INVALID_PARAMETER
;
860 I2cCommonServiceEntry (&SaveCmd
, &SaveBar0
);
862 Status
= EFI_SUCCESS
;
864 I2CAddress
= SlaveAddress
.I2CDeviceAddress
;
866 Status
= InitializeInternal (AddrMode
);
867 if (!EFI_ERROR(Status
)) {
868 Status
= ReadByte (I2CAddress
, (UINT8
*) Buffer
);
870 I2cCommonServiceExit (SaveCmd
, SaveBar0
);
876 The I2cWriteMultipleByte() function is a wrapper function for the
877 WriteMultipleByte() function. Provides a standard way to execute multiple
878 byte writes to an I2C device (e.g. when accessing sub-addresses or writing
879 block of data), as defined in the I2C Specification.
881 @param SlaveAddress The I2C slave address of the device
882 with which to communicate.
884 @param AddrMode I2C Addressing Mode: 7-bit or 10-bit address.
886 @param Length No. of bytes to be written.
888 @param Buffer Contains the value of byte to be written to the
891 @retval EFI_SUCCESS Transfer success.
892 @retval EFI_INVALID_PARAMETER This, Length or Buffer pointers are invalid.
893 @retval EFI_UNSUPPORTED Unsupported input param.
894 @retval EFI_TIMEOUT Timeout while waiting xfer.
895 @retval EFI_ABORTED Controller aborted xfer.
896 @retval EFI_DEVICE_ERROR Device error detected by controller.
901 I2cWriteMultipleByte (
902 IN EFI_I2C_DEVICE_ADDRESS SlaveAddress
,
903 IN EFI_I2C_ADDR_MODE AddrMode
,
913 if (Buffer
== NULL
|| Length
== NULL
) {
914 return EFI_INVALID_PARAMETER
;
919 I2cCommonServiceEntry (&SaveCmd
, &SaveBar0
);
920 Status
= EFI_SUCCESS
;
922 I2CAddress
= SlaveAddress
.I2CDeviceAddress
;
924 Status
= InitializeInternal (AddrMode
);
925 if (!EFI_ERROR(Status
)) {
926 Status
= WriteMultipleByte (I2CAddress
, Buffer
, (*Length
));
929 I2cCommonServiceExit (SaveCmd
, SaveBar0
);
935 The I2cReadMultipleByte() function is a wrapper function for the ReadMultipleByte() function.
936 Provides a standard way to execute multiple byte writes to an I2C device
937 (e.g. when accessing sub-addresses or when reading block of data), as defined
938 in the I2C Specification (I2C combined write/read protocol).
940 @param SlaveAddress The I2C slave address of the device
941 with which to communicate.
943 @param AddrMode I2C Addressing Mode: 7-bit or 10-bit address.
945 @param WriteLength No. of bytes to be written. In this case data
946 written typically contains sub-address or sub-addresses
947 in Hi-Lo format, that need to be read (I2C combined
948 write/read protocol).
950 @param ReadLength No. of bytes to be read from I2C slave device.
952 @param Buffer Contains the value of byte data read from the
955 @retval EFI_SUCCESS Transfer success.
956 @retval EFI_INVALID_PARAMETER This, WriteLength, ReadLength or Buffer
957 pointers are invalid.
958 @retval EFI_UNSUPPORTED Unsupported input param.
959 @retval EFI_TIMEOUT Timeout while waiting xfer.
960 @retval EFI_ABORTED Controller aborted xfer.
961 @retval EFI_DEVICE_ERROR Device error detected by controller.
966 I2cReadMultipleByte (
967 IN EFI_I2C_DEVICE_ADDRESS SlaveAddress
,
968 IN EFI_I2C_ADDR_MODE AddrMode
,
969 IN UINTN
*WriteLength
,
970 IN UINTN
*ReadLength
,
979 if (Buffer
== NULL
|| WriteLength
== NULL
|| ReadLength
== NULL
) {
980 return EFI_INVALID_PARAMETER
;
985 I2cCommonServiceEntry (&SaveCmd
, &SaveBar0
);
987 Status
= EFI_SUCCESS
;
989 I2CAddress
= SlaveAddress
.I2CDeviceAddress
;
990 Status
= InitializeInternal (AddrMode
);
991 if (!EFI_ERROR(Status
)) {
992 Status
= ReadMultipleByte (I2CAddress
, Buffer
, (*WriteLength
), (*ReadLength
));
994 I2cCommonServiceExit (SaveCmd
, SaveBar0
);