3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #ifndef __I2C_SLAVE_H__
18 #define __I2C_SLAVE_H__
20 #include <Protocol/I2cHostMcg.h>
23 Declare the forward references
26 typedef struct _EFI_I2C_SLAVE_PROTOCOL EFI_I2C_SLAVE_PROTOCOL
; ///< I2C slave protocol
29 The I2C controller received a data byte from the
32 @param[in] Context The value passed to the slave enable routine.
33 @param[in] NumberOfBytes Number of data bytes received
34 @param[in] Data Buffer containing the received data bytes
36 @retval EFI_SUCCESS ACK the data byte
37 @retval EFI_UNSUPPORTED NACK the data byte
42 (EFIAPI
*EFI_I2C_SLAVE_RECEIVE_DATA
) (
44 IN UINTN NumberOfBytes
,
49 The I2C controller received the start bit from the
52 @param[in] Context The value passed to the slave enable routine.
57 (EFIAPI
*EFI_I2C_SLAVE_RECEIVE_START
) (
64 The I2C controller received the stop bit from the
67 @param[in] Context The value passed to the slave enable routine.
68 @param[in] BytesSent Number of bytes successfully ACKed by the
69 I2C master. This is a hint, not all I2C
70 controllers support the ability to return
71 the number of bytes sent. When it is not
72 possible, the port driver returns zero.
73 @param[in] Status <ul>
74 <li>EFI_SUCCESS - All of the data was successfully sent</li>
75 <li>EFI_ABORTED - The controller was reset</li>
76 <li>EFI_DEVICE_ERROR - A NACK was received when sending the data.</li>
77 <li>EFI_END_OF_FILE - The stop bit was received before all of
78 the data was sent.</li>
84 (EFIAPI
*EFI_I2C_SLAVE_RECEIVE_STOP
) (
91 Enable or disable I2C slave operation.
93 The ReceiveData callback allows the port driver to return data
94 to the driver or application handling slave mode operations. This
95 is data that a remote master has sent to the local I2C controller.
96 The data may be returned one byte at a time if the controller supports
97 the ability to ACK/NACK on each receive byte. If not, a block of
98 data may be returned by the I2C port driver and the ACK/NACK status
99 is used only as a hint for the port driver.
101 The slave mode driver or application should buffer the data until
102 either ReceiveStart or ReceiveStop is called. At that time all of
103 the data is received and the command may be processed.
105 ReceiveStart is called when the I2C master is expecting a response.
106 After processing the command, but before sending the response the
107 slave driver or application should mark the command as processed to
108 avoid processing it a second time when ReceiveStop is called. The
109 slave driver or application then calls SendData to send to queue the
110 response data for transmission. The data must remain valid in the
111 WriteBuffer until ReceiveStop is called.
113 ReceiveStop is called when the stop bit is received on the I2C bus.
114 The slave driver or application starts processing the command if an
115 command data is pending in the slave driver's or application's buffer.
116 The BytesSent value is a hint to the slave driver or application as
117 to how much data was returned to the I2C master. If the controller
118 does not provide this level of support then this value is set to zero.
120 @param[in] This Address of an EFI_I2C_SLAVE_PROTOCOL
122 @param[in] SlaveAddress Slave address for the I2C controller
123 @param[in] Context Address of a context structure for use when
124 calling ReceiveData or ReceiveStop
125 @param[in] ReceiveData Called by the I2C port driver as data bytes
126 are received from the master. Response status
127 indicates if the byte is ACKed or NACKed. When
128 data is passed back a byte at a time, the port
129 driver must hold the clock until this callback
131 @param[in] ReceiveStart Called when the I2C controller receives a start bit.
132 @param[in] ReceiveStop Called after all of the data bytes are
135 @retval EFI_SUCCESS Slave operation is enabled on the controller.
136 @retval EFI_UNSUPPORTED The controller does not support this frequency.
141 (EFIAPI
*EFI_I2C_SLAVE_ENABLE
) (
142 IN CONST EFI_I2C_SLAVE_PROTOCOL
*This
,
143 IN UINT32 SlaveAddress
,
145 IN EFI_I2C_SLAVE_RECEIVE_DATA ReceiveData
,
146 IN EFI_I2C_SLAVE_RECEIVE_START ReceiveStart
,
147 IN EFI_I2C_SLAVE_RECEIVE_STOP ReceiveStop
151 Send data to the I2C master.
153 Port drivers may implement this as a blocking or non-blocking call.
154 The data in the write buffer must remain valid until ReceiveStop or
155 ReceiveStart is called indicating that the I2C master has terminated
158 @param[in] This Address of an EFI_I2C_SLAVE_PROTOCOL
160 @param[in] WriteBytes Number of bytes to write
161 @param[in] WriteBuffer Buffer containing the data to send
163 @retval EFI_SUCCESS Data waiting for master access.
164 @retval EFI_INVALID_PARAMETER WriteBuffer is NULL or WriteBytes
170 (EFIAPI
*EFI_I2C_SLAVE_SEND
) (
171 IN CONST EFI_I2C_SLAVE_PROTOCOL
*This
,
173 IN CONST UINT8
*WriteBuffer
177 /// I2C slave protocol
179 /// The port driver publishes this protocol when slave mode is
180 /// supported by the controller.
182 struct _EFI_I2C_SLAVE_PROTOCOL
{
184 /// Enable or disable I2C slave operation
186 EFI_I2C_SLAVE_ENABLE SlaveEnable
;
189 /// Send data to the I2C master
191 EFI_I2C_SLAVE_SEND SendData
;
195 /// GUID for the EFI_I2C_SLAVE_PROTOCOL
197 extern EFI_GUID gEfiI2cSlaveProtocolGuid
;
199 #endif // __I2C_SLAVE_H__