]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | Implementation of SmBusLib class library for PEI phase.\r | |
3 | \r | |
4 | Copyright (c) 2006, Intel Corporation<BR>\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 | \r | |
14 | Module Name: SmbusLib.c\r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
18 | #include "InternalSmbusLib.h"\r | |
19 | \r | |
20 | /**\r | |
21 | Executes an SMBUS quick read command.\r | |
22 | \r | |
23 | Executes an SMBUS quick read command on the SMBUS device specified by SmBusAddress.\r | |
24 | Only the SMBUS slave address field of SmBusAddress is required.\r | |
25 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
26 | If PEC is set in SmBusAddress, then ASSERT().\r | |
27 | If Command in SmBusAddress is not zero, then ASSERT().\r | |
28 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
29 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
30 | \r | |
31 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
32 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
33 | @param Status Return status for the executed command.\r | |
34 | This is an optional parameter and may be NULL.\r | |
35 | \r | |
36 | **/\r | |
37 | VOID\r | |
38 | EFIAPI\r | |
39 | SmBusQuickRead (\r | |
40 | IN UINTN SmBusAddress,\r | |
41 | OUT RETURN_STATUS *Status OPTIONAL\r | |
42 | )\r | |
43 | {\r | |
44 | ASSERT (!SMBUS_LIB_PEC (SmBusAddress));\r | |
45 | ASSERT (SMBUS_LIB_COMMAND (SmBusAddress) == 0);\r | |
46 | ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r | |
47 | ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r | |
48 | \r | |
49 | InternalSmBusExec (EfiSmbusQuickRead, SmBusAddress, 0, NULL, Status);\r | |
50 | }\r | |
51 | \r | |
52 | /**\r | |
53 | Executes an SMBUS quick write command.\r | |
54 | \r | |
55 | Executes an SMBUS quick write command on the SMBUS device specified by SmBusAddress.\r | |
56 | Only the SMBUS slave address field of SmBusAddress is required.\r | |
57 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
58 | If PEC is set in SmBusAddress, then ASSERT().\r | |
59 | If Command in SmBusAddress is not zero, then ASSERT().\r | |
60 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
61 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
62 | \r | |
63 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
64 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
65 | @param Status Return status for the executed command.\r | |
66 | This is an optional parameter and may be NULL.\r | |
67 | \r | |
68 | **/\r | |
69 | BOOLEAN\r | |
70 | EFIAPI\r | |
71 | SmBusQuickWrite (\r | |
72 | IN UINTN SmBusAddress,\r | |
73 | OUT RETURN_STATUS *Status OPTIONAL\r | |
74 | )\r | |
75 | {\r | |
76 | ASSERT (!SMBUS_LIB_PEC (SmBusAddress));\r | |
77 | ASSERT (SMBUS_LIB_COMMAND (SmBusAddress) == 0);\r | |
78 | ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r | |
79 | ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r | |
80 | \r | |
81 | InternalSmBusExec (EfiSmbusQuickWrite, SmBusAddress, 0, NULL, Status);\r | |
82 | //\r | |
83 | // Bugbug: Undefined return value in spec\r | |
84 | //\r | |
85 | return TRUE;\r | |
86 | }\r | |
87 | \r | |
88 | /**\r | |
89 | Executes an SMBUS receive byte command.\r | |
90 | \r | |
91 | Executes an SMBUS receive byte command on the SMBUS device specified by SmBusAddress.\r | |
92 | Only the SMBUS slave address field of SmBusAddress is required.\r | |
93 | The byte received from the SMBUS is returned.\r | |
94 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
95 | If Command in SmBusAddress is not zero, then ASSERT().\r | |
96 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
97 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
98 | \r | |
99 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
100 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
101 | @param Status Return status for the executed command.\r | |
102 | This is an optional parameter and may be NULL.\r | |
103 | \r | |
104 | @return The byte received from the SMBUS.\r | |
105 | \r | |
106 | **/\r | |
107 | UINT8\r | |
108 | EFIAPI\r | |
109 | SmBusReceiveByte (\r | |
110 | IN UINTN SmBusAddress,\r | |
111 | OUT RETURN_STATUS *Status OPTIONAL\r | |
112 | )\r | |
113 | {\r | |
114 | UINT8 Byte;\r | |
115 | \r | |
116 | ASSERT (SMBUS_LIB_COMMAND (SmBusAddress) == 0);\r | |
117 | ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r | |
118 | ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r | |
119 | \r | |
120 | InternalSmBusExec (EfiSmbusReceiveByte, SmBusAddress, 1, &Byte, Status);\r | |
121 | \r | |
122 | return Byte;\r | |
123 | }\r | |
124 | \r | |
125 | /**\r | |
126 | Executes an SMBUS send byte command.\r | |
127 | \r | |
128 | Executes an SMBUS send byte command on the SMBUS device specified by SmBusAddress.\r | |
129 | The byte specified by Value is sent.\r | |
130 | Only the SMBUS slave address field of SmBusAddress is required. Value is returned.\r | |
131 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
132 | If Command in SmBusAddress is not zero, then ASSERT().\r | |
133 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
134 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
135 | \r | |
136 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
137 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
138 | @param Value The 8-bit value to send.\r | |
139 | @param Status Return status for the executed command.\r | |
140 | This is an optional parameter and may be NULL.\r | |
141 | \r | |
142 | @return The parameter of Value.\r | |
143 | \r | |
144 | **/\r | |
145 | UINT8\r | |
146 | EFIAPI\r | |
147 | SmBusSendByte (\r | |
148 | IN UINTN SmBusAddress,\r | |
149 | IN UINT8 Value,\r | |
150 | OUT RETURN_STATUS *Status OPTIONAL\r | |
151 | )\r | |
152 | {\r | |
153 | UINT8 Byte;\r | |
154 | \r | |
155 | ASSERT (SMBUS_LIB_COMMAND (SmBusAddress) == 0);\r | |
156 | ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r | |
157 | ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r | |
158 | \r | |
159 | Byte = Value;\r | |
160 | InternalSmBusExec (EfiSmbusSendByte, SmBusAddress, 1, &Byte, Status);\r | |
161 | \r | |
162 | return Value;\r | |
163 | }\r | |
164 | \r | |
165 | /**\r | |
166 | Executes an SMBUS read data byte command.\r | |
167 | \r | |
168 | Executes an SMBUS read data byte command on the SMBUS device specified by SmBusAddress.\r | |
169 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
170 | The 8-bit value read from the SMBUS is returned.\r | |
171 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
172 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
173 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
174 | \r | |
175 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
176 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
177 | @param Status Return status for the executed command.\r | |
178 | This is an optional parameter and may be NULL.\r | |
179 | \r | |
180 | @return The byte read from the SMBUS.\r | |
181 | \r | |
182 | **/\r | |
183 | UINT8\r | |
184 | EFIAPI\r | |
185 | SmBusReadDataByte (\r | |
186 | IN UINTN SmBusAddress,\r | |
187 | OUT RETURN_STATUS *Status OPTIONAL\r | |
188 | )\r | |
189 | {\r | |
190 | UINT8 Byte;\r | |
191 | \r | |
192 | ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r | |
193 | ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r | |
194 | \r | |
195 | InternalSmBusExec (EfiSmbusReadByte, SmBusAddress, 1, &Byte, Status);\r | |
196 | \r | |
197 | return Byte;\r | |
198 | }\r | |
199 | \r | |
200 | /**\r | |
201 | Executes an SMBUS write data byte command.\r | |
202 | \r | |
203 | Executes an SMBUS write data byte command on the SMBUS device specified by SmBusAddress.\r | |
204 | The 8-bit value specified by Value is written.\r | |
205 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
206 | Value is returned.\r | |
207 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
208 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
209 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
210 | \r | |
211 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
212 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
213 | @param Value The 8-bit value to write.\r | |
214 | @param Status Return status for the executed command.\r | |
215 | This is an optional parameter and may be NULL.\r | |
216 | \r | |
217 | @return The parameter of Value.\r | |
218 | \r | |
219 | **/\r | |
220 | UINT8\r | |
221 | EFIAPI\r | |
222 | SmBusWriteDataByte (\r | |
223 | IN UINTN SmBusAddress,\r | |
224 | IN UINT8 Value,\r | |
225 | OUT RETURN_STATUS *Status OPTIONAL\r | |
226 | )\r | |
227 | {\r | |
228 | UINT8 Byte;\r | |
229 | \r | |
230 | ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r | |
231 | ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r | |
232 | \r | |
233 | Byte = Value;\r | |
234 | InternalSmBusExec (EfiSmbusWriteByte, SmBusAddress, 1, &Byte, Status);\r | |
235 | \r | |
236 | return Value;\r | |
237 | }\r | |
238 | \r | |
239 | /**\r | |
240 | Executes an SMBUS read data word command.\r | |
241 | \r | |
242 | Executes an SMBUS read data word command on the SMBUS device specified by SmBusAddress.\r | |
243 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
244 | The 16-bit value read from the SMBUS is returned.\r | |
245 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
246 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
247 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
248 | \r | |
249 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
250 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
251 | @param Status Return status for the executed command.\r | |
252 | This is an optional parameter and may be NULL.\r | |
253 | \r | |
254 | @return The byte read from the SMBUS.\r | |
255 | \r | |
256 | **/\r | |
257 | UINT16\r | |
258 | EFIAPI\r | |
259 | SmBusReadDataWord (\r | |
260 | IN UINTN SmBusAddress,\r | |
261 | OUT RETURN_STATUS *Status OPTIONAL\r | |
262 | )\r | |
263 | {\r | |
264 | UINT16 Word;\r | |
265 | \r | |
266 | ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r | |
267 | ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r | |
268 | \r | |
269 | InternalSmBusExec (EfiSmbusReadWord, SmBusAddress, 2, &Word, Status);\r | |
270 | \r | |
271 | return Word;\r | |
272 | }\r | |
273 | \r | |
274 | /**\r | |
275 | Executes an SMBUS write data word command.\r | |
276 | \r | |
277 | Executes an SMBUS write data word command on the SMBUS device specified by SmBusAddress.\r | |
278 | The 16-bit value specified by Value is written.\r | |
279 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
280 | Value is returned.\r | |
281 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
282 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
283 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
284 | \r | |
285 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
286 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
287 | @param Value The 16-bit value to write.\r | |
288 | @param Status Return status for the executed command.\r | |
289 | This is an optional parameter and may be NULL.\r | |
290 | \r | |
291 | @return The parameter of Value.\r | |
292 | \r | |
293 | **/\r | |
294 | UINT16\r | |
295 | EFIAPI\r | |
296 | SmBusWriteDataWord (\r | |
297 | IN UINTN SmBusAddress,\r | |
298 | IN UINT16 Value,\r | |
299 | OUT RETURN_STATUS *Status OPTIONAL\r | |
300 | )\r | |
301 | {\r | |
302 | UINT16 Word;\r | |
303 | \r | |
304 | ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r | |
305 | ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r | |
306 | \r | |
307 | Word = Value;\r | |
308 | InternalSmBusExec (EfiSmbusWriteWord, SmBusAddress, 2, &Word, Status);\r | |
309 | \r | |
310 | return Value;\r | |
311 | }\r | |
312 | \r | |
313 | /**\r | |
314 | Executes an SMBUS process call command.\r | |
315 | \r | |
316 | Executes an SMBUS process call command on the SMBUS device specified by SmBusAddress.\r | |
317 | The 16-bit value specified by Value is written.\r | |
318 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
319 | The 16-bit value returned by the process call command is returned.\r | |
320 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
321 | If Length in SmBusAddress is not zero, then ASSERT().\r | |
322 | If any reserved bits of SmBusAddress are set, then ASSERT().\r | |
323 | \r | |
324 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
325 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
326 | @param Value The 16-bit value to write.\r | |
327 | @param Status Return status for the executed command.\r | |
328 | This is an optional parameter and may be NULL.\r | |
329 | \r | |
330 | @return The 16-bit value returned by the process call command.\r | |
331 | \r | |
332 | **/\r | |
333 | UINT16\r | |
334 | EFIAPI\r | |
335 | SmBusProcessCall (\r | |
336 | IN UINTN SmBusAddress,\r | |
337 | IN UINT16 Value,\r | |
338 | OUT RETURN_STATUS *Status OPTIONAL\r | |
339 | )\r | |
340 | {\r | |
341 | ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r | |
342 | ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r | |
343 | \r | |
344 | InternalSmBusExec (EfiSmbusProcessCall, SmBusAddress, 2, &Value, Status);\r | |
345 | \r | |
346 | return Value;\r | |
347 | }\r | |
348 | \r | |
349 | /**\r | |
350 | Executes an SMBUS read block command.\r | |
351 | \r | |
352 | Executes an SMBUS read block command on the SMBUS device specified by SmBusAddress.\r | |
353 | Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r | |
354 | Bytes are read from the SMBUS and stored in Buffer.\r | |
355 | The number of bytes read is returned, and will never return a value larger than 32-bytes.\r | |
356 | If Status is not NULL, then the status of the executed command is returned in Status.\r | |
357 |