-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipmi_i2c_commands.c
50 lines (46 loc) · 1.2 KB
/
ipmi_i2c_commands.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdint.h>
#include "ipmi_i2c_commands.h"
#include "ipmi.h"
int read_i2c(uint8_t bus, uint8_t addr, uint8_t reg, uint8_t* data)
{
uint8_t cmd_data[4];
#ifndef EXTENDED_BUS_ID
cmd_data[0] = ((bus & 0x7) << 1) | 0x1;
#else
cmd_data[0] = ((bus & 0x7F) << 1) | 0x1;
#endif
cmd_data[1] = (addr << 1);
cmd_data[2] = 1;
cmd_data[3] = reg;
int status, data_sz;
int rc = ipmicmd(BMC_SA, 0, APP_NETFN, MASTER_READ_WRITE_CMD, sizeof(cmd_data), &cmd_data, 1, &data_sz, &status);
if (rc) {
#ifdef DEBUG
fprintf(stderr, "Error! ipmicmd: rc=%d, status=0x%08x\n", rc, status);
#endif
} else {
*data = (uint8_t)(status & 0xff);
}
return rc;
}
int write_i2c(uint8_t bus, uint8_t addr, uint8_t reg, uint8_t val)
{
uint8_t cmd_data[5];
#ifndef EXTENDED_BUS_ID
cmd_data[0] = ((bus & 0x7) << 1) | 0x1;
#else
cmd_data[0] = ((bus & 0x7F) << 1) | 0x1;
#endif
cmd_data[1] = (addr << 1);
cmd_data[2] = 1;
cmd_data[3] = reg;
cmd_data[4] = val;
int status, data_sz;
int rc = ipmicmd(BMC_SA, 0, APP_NETFN, MASTER_READ_WRITE_CMD, sizeof(cmd_data), &cmd_data, 1, &data_sz, &status);
#ifdef DEBUG
if (rc) {
fprintf(stderr, "Error! ipmicmd: rc=%d, status=0x%08x\n", rc, status);
}
#endif
return rc;
}