]>
Commit | Line | Data |
---|---|---|
fb3df220 | 1 | /** @file\r |
2 | SMBUS Functions\r | |
3 | \r | |
4 | Copyright (c) 2006, Intel Corporation\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | Module Name: SmbusLib.h\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #ifndef __SMBUS_LIB__\r | |
18 | #define __SMBUS_LIB__\r | |
19 | \r | |
20 | //\r | |
21 | // PEC BIT is bit 22 in SMBUS address\r | |
22 | //\r | |
23 | #define SMBUS_LIB_PEC_BIT (1 << 22)\r | |
24 | \r | |
25 | /**\r | |
26 | Macro that converts SMBUS slave address, SMBUS command, SMBUS data length,\r | |
27 | and PEC to a value that can be passed to the SMBUS Library functions.\r | |
28 | \r | |
29 | Computes an address that is compatible with the SMBUS Library functions.\r | |
30 | The unused upper bits of SlaveAddress, Command, and Length are stripped\r | |
31 | prior to the generation of the address.\r | |
32 | \r | |
33 | @param SlaveAddress SMBUS Slave Address. Range 0..127.\r | |
34 | @param Command SMBUS Command. Range 0..255.\r | |
35 | @param Length SMBUS Data Length. Range 0..32.\r | |
36 | @param Pec TRUE if Packet Error Checking is enabled. Otherwise FALSE.\r | |
37 | \r | |
38 | **/\r | |
39 | #define SMBUS_LIB_ADDRESS(SlaveAddress,Command,Length,Pec) \\r | |
40 | ( ((Pec) ? SMBUS_LIB_PEC_BIT: 0) | \\r | |
41 | (((SlaveAddress) & 0x7f) << 1) | \\r | |
42 | (((Command) & 0xff) << 8) | \\r | |
43 | (((Length) & 0x3f) << 16) \\r | |
44 | )\r | |
45 | \r | |
46 | /**\r | |
47 | Executes an SMBUS quick read command.\r | |
48 | \r | |
49 | Executes an SMBUS quick read command on the SMBUS device specified by SmBusAddress.\r | |
50 | Only the SMBUS slave address field of SmBusAddress is required.\r | |
51 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
52 | If PEC is set in SmBusAddress, then ASSERT().\r | |
53 | If Command in SmBusAddress is not zero, then ASSERT().\r | |
54 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
55 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
56 | \r | |
57 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
58 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
59 | @param Status Return status for the executed command.\r | |
60 | This is an optional parameter and may be NULL.\r | |
61 | \r | |
62 | **/\r | |
63 | VOID\r | |
64 | EFIAPI\r | |
65 | SmBusQuickRead (\r | |
66 | IN UINTN SmBusAddress,\r | |
67 | OUT RETURN_STATUS *Status OPTIONAL\r | |
68 | )\r | |
69 | ;\r | |
70 | \r | |
71 | /**\r | |
72 | Executes an SMBUS quick write command.\r | |
73 | \r | |
74 | Executes an SMBUS quick write command on the SMBUS device specified by SmBusAddress.\r | |
75 | Only the SMBUS slave address field of SmBusAddress is required.\r | |
76 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
77 | If PEC is set in SmBusAddress, then ASSERT().\r | |
78 | If Command in SmBusAddress is not zero, then ASSERT().\r | |
79 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
80 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
81 | \r | |
82 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
83 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
84 | @param Status Return status for the executed command.\r | |
85 | This is an optional parameter and may be NULL.\r | |
86 | \r | |
87 | **/\r | |
88 | VOID\r | |
89 | EFIAPI\r | |
90 | SmBusQuickWrite (\r | |
91 | IN UINTN SmBusAddress,\r | |
92 | OUT RETURN_STATUS *Status OPTIONAL\r | |
93 | )\r | |
94 | ;\r | |
95 | \r | |
96 | /**\r | |
97 | Executes an SMBUS receive byte command.\r | |
98 | \r | |
99 | Executes an SMBUS receive byte command on the SMBUS device specified by SmBusAddress.\r | |
100 | Only the SMBUS slave address field of SmBusAddress is required.\r | |
101 | The byte received from the SMBUS is returned.\r | |
102 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
103 | If Command in SmBusAddress is not zero, then ASSERT().\r | |
104 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
105 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
106 | \r | |
107 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
108 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
109 | @param Status Return status for the executed command.\r | |
110 | This is an optional parameter and may be NULL.\r | |
111 | \r | |
112 | @return The byte received from the SMBUS.\r | |
113 | \r | |
114 | **/\r | |
115 | UINT8\r | |
116 | EFIAPI\r | |
117 | SmBusReceiveByte (\r | |
118 | IN UINTN SmBusAddress,\r | |
119 | OUT RETURN_STATUS *Status OPTIONAL\r | |
120 | )\r | |
121 | ;\r | |
122 | \r | |
123 | /**\r | |
124 | Executes an SMBUS send byte command.\r | |
125 | \r | |
126 | Executes an SMBUS send byte command on the SMBUS device specified by SmBusAddress.\r | |
127 | The byte specified by Value is sent.\r | |
128 | Only the SMBUS slave address field of SmBusAddress is required. Value is returned.\r | |
129 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
130 | If Command in SmBusAddress is not zero, then ASSERT().\r | |
131 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
132 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
133 | \r | |
134 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
135 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
136 | @param Value The 8-bit value to send.\r | |
137 | @param Status Return status for the executed command.\r | |
138 | This is an optional parameter and may be NULL.\r | |
139 | \r | |
140 | @return The parameter of Value.\r | |
141 | \r | |
142 | **/\r | |
143 | UINT8\r | |
144 | EFIAPI\r | |
145 | SmBusSendByte (\r | |
146 | IN UINTN SmBusAddress,\r | |
147 | IN UINT8 Value,\r | |
148 | OUT RETURN_STATUS *Status OPTIONAL\r | |
149 | )\r | |
150 | ;\r | |
151 | \r | |
152 | /**\r | |
153 | Executes an SMBUS read data byte command.\r | |
154 | \r | |
155 | Executes an SMBUS read data byte command on the SMBUS device specified by SmBusAddress.\r | |
156 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
157 | The 8-bit value read from the SMBUS is returned.\r | |
158 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
159 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
160 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
161 | \r | |
162 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
163 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
164 | @param Status Return status for the executed command.\r | |
165 | This is an optional parameter and may be NULL.\r | |
166 | \r | |
167 | @return The byte read from the SMBUS.\r | |
168 | \r | |
169 | **/\r | |
170 | UINT8\r | |
171 | EFIAPI\r | |
172 | SmBusReadDataByte (\r | |
173 | IN UINTN SmBusAddress,\r | |
174 | OUT RETURN_STATUS *Status OPTIONAL\r | |
175 | )\r | |
176 | ;\r | |
177 | \r | |
178 | /**\r | |
179 | Executes an SMBUS write data byte command.\r | |
180 | \r | |
181 | Executes an SMBUS write data byte command on the SMBUS device specified by SmBusAddress.\r | |
182 | The 8-bit value specified by Value is written.\r | |
183 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
184 | Value is returned.\r | |
185 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
186 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
187 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
188 | \r | |
189 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
190 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
191 | @param Value The 8-bit value to write.\r | |
192 | @param Status Return status for the executed command.\r | |
193 | This is an optional parameter and may be NULL.\r | |
194 | \r | |
195 | @return The parameter of Value.\r | |
196 | \r | |
197 | **/\r | |
198 | UINT8\r | |
199 | EFIAPI\r | |
200 | SmBusWriteDataByte (\r | |
201 | IN UINTN SmBusAddress,\r | |
202 | IN UINT8 Value,\r | |
203 | OUT RETURN_STATUS *Status OPTIONAL\r | |
204 | )\r | |
205 | ;\r | |
206 | \r | |
207 | /**\r | |
208 | Executes an SMBUS read data word command.\r | |
209 | \r | |
210 | Executes an SMBUS read data word command on the SMBUS device specified by SmBusAddress.\r | |
211 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
212 | The 16-bit value read from the SMBUS is returned.\r | |
213 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
214 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
215 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
216 | \r | |
217 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
218 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
219 | @param Status Return status for the executed command.\r | |
220 | This is an optional parameter and may be NULL.\r | |
221 | \r | |
222 | @return The byte read from the SMBUS.\r | |
223 | \r | |
224 | **/\r | |
225 | UINT16\r | |
226 | EFIAPI\r | |
227 | SmBusReadDataWord (\r | |
228 | IN UINTN SmBusAddress,\r | |
229 | OUT RETURN_STATUS *Status OPTIONAL\r | |
230 | )\r | |
231 | ;\r | |
232 | \r | |
233 | /**\r | |
234 | Executes an SMBUS write data word command.\r | |
235 | \r | |
236 | Executes an SMBUS write data word command on the SMBUS device specified by SmBusAddress.\r | |
237 | The 16-bit value specified by Value is written.\r | |
238 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
239 | Value is returned.\r | |
240 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
241 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
242 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
243 | \r | |
244 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
245 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
246 | @param Value The 16-bit value to write.\r | |
247 | @param Status Return status for the executed command.\r | |
248 | This is an optional parameter and may be NULL.\r | |
249 | \r | |
250 | @return The parameter of Value.\r | |
251 | \r | |
252 | **/\r | |
253 | UINT16\r | |
254 | EFIAPI\r | |
255 | SmBusWriteDataWord (\r | |
256 | IN UINTN SmBusAddress,\r | |
257 | IN UINT16 Value,\r | |
258 | OUT RETURN_STATUS *Status OPTIONAL\r | |
259 | )\r | |
260 | ;\r | |
261 | \r | |
262 | /**\r | |
263 | Executes an SMBUS process call command.\r | |
264 | \r | |
265 | Executes an SMBUS process call command on the SMBUS device specified by SmBusAddress.\r | |
266 | The 16-bit value specified by Value is written.\r | |
267 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
268 | The 16-bit value returned by the process call command is returned.\r | |
269 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
270 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
271 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
272 | \r | |
273 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
274 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
275 | @param Value The 16-bit value to write.\r | |
276 | @param Status Return status for the executed command.\r | |
277 | This is an optional parameter and may be NULL.\r | |
278 | \r | |
279 | @return The 16-bit value returned by the process call command.\r | |
280 | \r | |
281 | **/\r | |
282 | UINT16\r | |
283 | EFIAPI\r | |
284 | SmBusProcessCall (\r | |
285 | IN UINTN SmBusAddress,\r | |
286 | IN UINT16 Value,\r | |
287 | OUT RETURN_STATUS *Status OPTIONAL\r | |
288 | )\r | |
289 | ;\r | |
290 | \r | |
291 | /**\r | |
292 | Executes an SMBUS read block command.\r | |
293 | \r | |
294 | Executes an SMBUS read block command on the SMBUS device specified by SmBusAddress.\r | |
295 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
296 | Bytes are read from the SMBUS and stored in Buffer.\r | |
297 | The number of bytes read is returned, and will never return a value larger than 32-bytes.\r | |
298 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
299 | It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.\r | |
300 | SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r | |
301 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
302 | If Buffer is NULL, then ASSERT().\r | |
303 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
304 | \r | |
305 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
306 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
307 | @param Buffer Pointer to the buffer to store the bytes read from the SMBUS.\r | |
308 | @param Status Return status for the executed command.\r | |
309 | This is an optional parameter and may be NULL.\r | |
310 | \r | |
311 | @return The number of bytes read.\r | |
312 | \r | |
313 | **/\r | |
314 | UINTN\r | |
315 | EFIAPI\r | |
316 | SmBusReadBlock (\r | |
317 | IN UINTN SmBusAddress,\r | |
318 | OUT VOID *Buffer,\r | |
319 | OUT RETURN_STATUS *Status OPTIONAL\r | |
320 | )\r | |
321 | ;\r | |
322 | \r | |
323 | /**\r | |
324 | Executes an SMBUS write block command.\r | |
325 | \r | |
326 | Executes an SMBUS write block command on the SMBUS device specified by SmBusAddress.\r | |
327 | The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.\r | |
328 | Bytes are written to the SMBUS from Buffer.\r | |
329 | The number of bytes written is returned, and will never return a value larger than 32-bytes.\r | |
330 | If Status is not NULL, then the status of the executed command is returned in Status. \r | |
331 | If Length in SmBusAddress is zero or greater than 32, then ASSERT().\r | |
332 | If Buffer is NULL, then ASSERT().\r | |
333 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
334 | \r | |
335 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
336 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
337 | @param Buffer Pointer to the buffer to store the bytes read from the SMBUS.\r | |
338 | @param Status Return status for the executed command.\r | |
339 | This is an optional parameter and may be NULL.\r | |
340 | \r | |
341 | @return The number of bytes written.\r | |
342 | \r | |
343 | **/\r | |
344 | UINTN\r | |
345 | EFIAPI\r | |
346 | SmBusWriteBlock (\r | |
347 | IN UINTN SmBusAddress,\r | |
348 | OUT VOID *Buffer,\r | |
349 | OUT RETURN_STATUS *Status OPTIONAL\r | |
350 | )\r | |
351 | ;\r | |
352 | \r | |
353 | /**\r | |
354 | Executes an SMBUS block process call command.\r | |
355 | \r | |
356 | Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress.\r | |
357 | The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.\r | |
358 | Bytes are written to the SMBUS from WriteBuffer. Bytes are then read from the SMBUS into ReadBuffer.\r | |
359 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
360 | It is the caller's responsibility to make sure ReadBuffer is large enough for the total number of bytes read.\r | |
361 | SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r | |
362 | If Length in SmBusAddress is zero or greater than 32, then ASSERT().\r | |
363 | If WriteBuffer is NULL, then ASSERT().\r | |
364 | If ReadBuffer is NULL, then ASSERT().\r | |
365 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
366 | \r | |
367 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
368 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
369 | @param WriteBuffer Pointer to the buffer of bytes to write to the SMBUS.\r | |
370 | @param ReadBuffer Pointer to the buffer of bytes to read from the SMBUS.\r | |
371 | @param Status Return status for the executed command.\r | |
372 | This is an optional parameter and may be NULL.\r | |
373 | \r | |
374 | @return The number of bytes written.\r | |
375 | \r | |
376 | **/\r | |
377 | UINTN\r | |
378 | EFIAPI\r | |
379 | SmBusBlockProcessCall (\r | |
380 | IN UINTN SmBusAddress,\r | |
381 | IN VOID *WriteBuffer,\r | |
382 | OUT VOID *ReadBuffer,\r | |
383 | OUT RETURN_STATUS *Status OPTIONAL\r | |
384 | )\r | |
385 | ;\r | |
386 | \r | |
387 | \r | |
388 | #endif\r |