]> git.proxmox.com Git - mirror_edk2.git/blame - Vlv2TbltDevicePkg/Include/Protocol/I2cSlave.h
Vlv2TbltDevicePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / Vlv2TbltDevicePkg / Include / Protocol / I2cSlave.h
CommitLineData
3cbfba02
DW
1/*++\r
2\r
3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
4 \r\r
9dc8036d
MK
5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
6\r
3cbfba02
DW
7 \r\r
8\r
9\r
10**/\r
11\r
12#ifndef __I2C_SLAVE_H__\r
13#define __I2C_SLAVE_H__\r
14\r
15#include <Protocol/I2cHostMcg.h>\r
16\r
17/**\r
18 Declare the forward references\r
19\r
20**/\r
21typedef struct _EFI_I2C_SLAVE_PROTOCOL EFI_I2C_SLAVE_PROTOCOL; ///< I2C slave protocol\r
22\r
23/**\r
24 The I2C controller received a data byte from the\r
25 I2C msster.\r
26\r
27 @param[in] Context The value passed to the slave enable routine.\r
28 @param[in] NumberOfBytes Number of data bytes received\r
29 @param[in] Data Buffer containing the received data bytes\r
30\r
31 @retval EFI_SUCCESS ACK the data byte\r
32 @retval EFI_UNSUPPORTED NACK the data byte\r
33\r
34**/\r
35typedef\r
36EFI_STATUS\r
37(EFIAPI *EFI_I2C_SLAVE_RECEIVE_DATA) (\r
38 IN VOID *Context,\r
39 IN UINTN NumberOfBytes,\r
40 IN CONST UINT8 *Data\r
41 );\r
42\r
43/**\r
44 The I2C controller received the start bit from the\r
45 I2C master.\r
46\r
47 @param[in] Context The value passed to the slave enable routine.\r
48\r
49**/\r
50typedef\r
51VOID\r
52(EFIAPI *EFI_I2C_SLAVE_RECEIVE_START) (\r
53 IN VOID *Context,\r
54 IN UINTN BytesSent,\r
55 IN EFI_STATUS Status\r
56 );\r
57\r
58/**\r
59 The I2C controller received the stop bit from the\r
60 I2C master.\r
61\r
62 @param[in] Context The value passed to the slave enable routine.\r
63 @param[in] BytesSent Number of bytes successfully ACKed by the\r
64 I2C master. This is a hint, not all I2C\r
65 controllers support the ability to return\r
66 the number of bytes sent. When it is not\r
67 possible, the port driver returns zero.\r
68 @param[in] Status <ul>\r
69 <li>EFI_SUCCESS - All of the data was successfully sent</li>\r
70 <li>EFI_ABORTED - The controller was reset</li>\r
71 <li>EFI_DEVICE_ERROR - A NACK was received when sending the data.</li>\r
72 <li>EFI_END_OF_FILE - The stop bit was received before all of\r
73 the data was sent.</li>\r
74 </ul>\r
75\r
76**/\r
77typedef\r
78VOID\r
79(EFIAPI *EFI_I2C_SLAVE_RECEIVE_STOP) (\r
80 IN VOID *Context,\r
81 IN UINTN BytesSent,\r
82 IN EFI_STATUS Status\r
83 );\r
84\r
85/**\r
86 Enable or disable I2C slave operation.\r
87\r
88 The ReceiveData callback allows the port driver to return data\r
89 to the driver or application handling slave mode operations. This\r
90 is data that a remote master has sent to the local I2C controller.\r
91 The data may be returned one byte at a time if the controller supports\r
92 the ability to ACK/NACK on each receive byte. If not, a block of\r
93 data may be returned by the I2C port driver and the ACK/NACK status\r
94 is used only as a hint for the port driver.\r
95\r
96 The slave mode driver or application should buffer the data until\r
97 either ReceiveStart or ReceiveStop is called. At that time all of\r
98 the data is received and the command may be processed.\r
99\r
100 ReceiveStart is called when the I2C master is expecting a response.\r
101 After processing the command, but before sending the response the\r
102 slave driver or application should mark the command as processed to\r
103 avoid processing it a second time when ReceiveStop is called. The\r
104 slave driver or application then calls SendData to send to queue the\r
105 response data for transmission. The data must remain valid in the\r
106 WriteBuffer until ReceiveStop is called.\r
107\r
108 ReceiveStop is called when the stop bit is received on the I2C bus.\r
109 The slave driver or application starts processing the command if an\r
110 command data is pending in the slave driver's or application's buffer.\r
111 The BytesSent value is a hint to the slave driver or application as\r
112 to how much data was returned to the I2C master. If the controller\r
113 does not provide this level of support then this value is set to zero.\r
114\r
115 @param[in] This Address of an EFI_I2C_SLAVE_PROTOCOL\r
116 structure\r
117 @param[in] SlaveAddress Slave address for the I2C controller\r
118 @param[in] Context Address of a context structure for use when\r
119 calling ReceiveData or ReceiveStop\r
120 @param[in] ReceiveData Called by the I2C port driver as data bytes\r
121 are received from the master. Response status\r
122 indicates if the byte is ACKed or NACKed. When\r
123 data is passed back a byte at a time, the port\r
124 driver must hold the clock until this callback\r
125 returns.\r
126 @param[in] ReceiveStart Called when the I2C controller receives a start bit.\r
127 @param[in] ReceiveStop Called after all of the data bytes are\r
128 received.\r
129\r
130 @retval EFI_SUCCESS Slave operation is enabled on the controller.\r
131 @retval EFI_UNSUPPORTED The controller does not support this frequency.\r
132\r
133**/\r
134typedef\r
135EFI_STATUS\r
136(EFIAPI *EFI_I2C_SLAVE_ENABLE) (\r
137 IN CONST EFI_I2C_SLAVE_PROTOCOL *This,\r
138 IN UINT32 SlaveAddress,\r
139 IN VOID *Context,\r
140 IN EFI_I2C_SLAVE_RECEIVE_DATA ReceiveData,\r
141 IN EFI_I2C_SLAVE_RECEIVE_START ReceiveStart,\r
142 IN EFI_I2C_SLAVE_RECEIVE_STOP ReceiveStop\r
143 );\r
144\r
145/**\r
146 Send data to the I2C master.\r
147\r
148 Port drivers may implement this as a blocking or non-blocking call.\r
149 The data in the write buffer must remain valid until ReceiveStop or\r
150 ReceiveStart is called indicating that the I2C master has terminated\r
151 the transfer.\r
152\r
153 @param[in] This Address of an EFI_I2C_SLAVE_PROTOCOL\r
154 structure\r
155 @param[in] WriteBytes Number of bytes to write\r
156 @param[in] WriteBuffer Buffer containing the data to send\r
157\r
158 @retval EFI_SUCCESS Data waiting for master access.\r
159 @retval EFI_INVALID_PARAMETER WriteBuffer is NULL or WriteBytes\r
160 is zero.\r
161\r
162**/\r
163typedef\r
164EFI_STATUS\r
165(EFIAPI *EFI_I2C_SLAVE_SEND) (\r
166 IN CONST EFI_I2C_SLAVE_PROTOCOL *This,\r
167 IN UINTN WriteBytes,\r
168 IN CONST UINT8 *WriteBuffer\r
169 );\r
170\r
171///\r
172/// I2C slave protocol\r
173///\r
174/// The port driver publishes this protocol when slave mode is\r
175/// supported by the controller.\r
176///\r
177struct _EFI_I2C_SLAVE_PROTOCOL {\r
178 ///\r
179 /// Enable or disable I2C slave operation\r
180 ///\r
181 EFI_I2C_SLAVE_ENABLE SlaveEnable;\r
182\r
183 ///\r
184 /// Send data to the I2C master\r
185 ///\r
186 EFI_I2C_SLAVE_SEND SendData;\r
187};\r
188\r
189///\r
190/// GUID for the EFI_I2C_SLAVE_PROTOCOL\r
191///\r
192extern EFI_GUID gEfiI2cSlaveProtocolGuid;\r
193\r
194#endif // __I2C_SLAVE_H__\r