1#ifndef QEMU_SMBUS_H
2#define QEMU_SMBUS_H
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#include "hw/i2c/i2c.h"
29
30#define TYPE_SMBUS_DEVICE "smbus-device"
31#define SMBUS_DEVICE(obj) \
32 OBJECT_CHECK(SMBusDevice, (obj), TYPE_SMBUS_DEVICE)
33#define SMBUS_DEVICE_CLASS(klass) \
34 OBJECT_CLASS_CHECK(SMBusDeviceClass, (klass), TYPE_SMBUS_DEVICE)
35#define SMBUS_DEVICE_GET_CLASS(obj) \
36 OBJECT_GET_CLASS(SMBusDeviceClass, (obj), TYPE_SMBUS_DEVICE)
37
38typedef struct SMBusDeviceClass
39{
40 I2CSlaveClass parent_class;
41 int (*init)(SMBusDevice *dev);
42 void (*quick_cmd)(SMBusDevice *dev, uint8_t read);
43 void (*send_byte)(SMBusDevice *dev, uint8_t val);
44 uint8_t (*receive_byte)(SMBusDevice *dev);
45
46
47
48
49 void (*write_data)(SMBusDevice *dev, uint8_t cmd, uint8_t *buf, int len);
50
51
52
53
54 uint8_t (*read_data)(SMBusDevice *dev, uint8_t cmd, int n);
55} SMBusDeviceClass;
56
57struct SMBusDevice {
58
59 I2CSlave i2c;
60
61
62 int mode;
63 int data_len;
64 uint8_t data_buf[34];
65 uint8_t command;
66};
67
68
69int smbus_quick_command(I2CBus *bus, uint8_t addr, int read);
70int smbus_receive_byte(I2CBus *bus, uint8_t addr);
71int smbus_send_byte(I2CBus *bus, uint8_t addr, uint8_t data);
72int smbus_read_byte(I2CBus *bus, uint8_t addr, uint8_t command);
73int smbus_write_byte(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t data);
74int smbus_read_word(I2CBus *bus, uint8_t addr, uint8_t command);
75int smbus_write_word(I2CBus *bus, uint8_t addr, uint8_t command, uint16_t data);
76int smbus_read_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t *data);
77int smbus_write_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t *data,
78 int len);
79
80void smbus_eeprom_init(I2CBus *smbus, int nb_eeprom,
81 const uint8_t *eeprom_spd, int size);
82
83#endif
84