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