Revision 0ff596d0 hw/smbus.h
b/hw/smbus.h | ||
---|---|---|
25 | 25 |
typedef struct SMBusDevice SMBusDevice; |
26 | 26 |
|
27 | 27 |
struct SMBusDevice { |
28 |
uint8_t addr; |
|
28 |
/* The SMBus protocol is implemented on top of I2C. */ |
|
29 |
i2c_slave i2c; |
|
30 |
|
|
31 |
/* Callbacks set by the device. */ |
|
29 | 32 |
void (*quick_cmd)(SMBusDevice *dev, uint8_t read); |
30 | 33 |
void (*send_byte)(SMBusDevice *dev, uint8_t val); |
31 | 34 |
uint8_t (*receive_byte)(SMBusDevice *dev); |
32 |
void (*write_byte)(SMBusDevice *dev, uint8_t cmd, uint8_t val); |
|
33 |
uint8_t (*read_byte)(SMBusDevice *dev, uint8_t cmd); |
|
34 |
void (*write_word)(SMBusDevice *dev, uint8_t cmd, uint16_t val); |
|
35 |
uint16_t (*read_word)(SMBusDevice *dev, uint8_t cmd); |
|
36 |
void (*write_block)(SMBusDevice *dev, uint8_t cmd, uint8_t len, uint8_t *buf); |
|
37 |
uint8_t (*read_block)(SMBusDevice *dev, uint8_t cmd, uint8_t *buf); |
|
35 |
/* We can't distinguish between a word write and a block write with |
|
36 |
length 1, so pass the whole data block including the length byte |
|
37 |
(if present). The device is responsible figuring out what type of |
|
38 |
command this is. */ |
|
39 |
void (*write_data)(SMBusDevice *dev, uint8_t cmd, uint8_t *buf, int len); |
|
40 |
/* Likewise we can't distinguish between defferent reads, or even know |
|
41 |
the length of the read until the read is complete, so read data a |
|
42 |
byte at a time. The device is responsible for adding the length |
|
43 |
byte on block reads. */ |
|
44 |
uint8_t (*read_data)(SMBusDevice *dev, uint8_t cmd, int n); |
|
45 |
|
|
46 |
/* Remaining fields for internal use only. */ |
|
47 |
int mode; |
|
48 |
int data_len; |
|
49 |
uint8_t data_buf[34]; /* command + len + 32 bytes of data. */ |
|
50 |
uint8_t command; |
|
38 | 51 |
}; |
52 |
|
|
53 |
/* Create a slave device. */ |
|
54 |
SMBusDevice *smbus_device_init(i2c_bus *bus, int address, int size); |
|
55 |
|
|
56 |
/* Master device commands. */ |
|
57 |
void smbus_quick_command(i2c_bus *bus, int addr, int read); |
|
58 |
uint8_t smbus_receive_byte(i2c_bus *bus, int addr); |
|
59 |
void smbus_send_byte(i2c_bus *bus, int addr, uint8_t data); |
|
60 |
uint8_t smbus_read_byte(i2c_bus *bus, int addr, uint8_t command); |
|
61 |
void smbus_write_byte(i2c_bus *bus, int addr, uint8_t command, uint8_t data); |
|
62 |
uint16_t smbus_read_word(i2c_bus *bus, int addr, uint8_t command); |
|
63 |
void smbus_write_word(i2c_bus *bus, int addr, uint8_t command, uint16_t data); |
|
64 |
int smbus_read_block(i2c_bus *bus, int addr, uint8_t command, uint8_t *data); |
|
65 |
void smbus_write_block(i2c_bus *bus, int addr, uint8_t command, uint8_t *data, |
|
66 |
int len); |
|
67 |
|
|
68 |
/* smbus_eeprom.c */ |
|
69 |
void smbus_eeprom_device_init(i2c_bus *bus, uint8_t addr, uint8_t *buf); |
|
70 |
|
Also available in: Unified diff