1#ifndef QEMU_I2C_H
2#define QEMU_I2C_H
3
4#include "hw/qdev.h"
5
6
7
8
9
10
11enum i2c_event {
12 I2C_START_RECV,
13 I2C_START_SEND,
14 I2C_FINISH,
15 I2C_NACK
16};
17
18typedef struct I2CSlave I2CSlave;
19
20#define TYPE_I2C_SLAVE "i2c-slave"
21#define I2C_SLAVE(obj) \
22 OBJECT_CHECK(I2CSlave, (obj), TYPE_I2C_SLAVE)
23#define I2C_SLAVE_CLASS(klass) \
24 OBJECT_CLASS_CHECK(I2CSlaveClass, (klass), TYPE_I2C_SLAVE)
25#define I2C_SLAVE_GET_CLASS(obj) \
26 OBJECT_GET_CLASS(I2CSlaveClass, (obj), TYPE_I2C_SLAVE)
27
28typedef struct I2CSlaveClass
29{
30 DeviceClass parent_class;
31
32
33 int (*init)(I2CSlave *dev);
34
35
36 int (*send)(I2CSlave *s, uint8_t data);
37
38
39 int (*recv)(I2CSlave *s);
40
41
42 void (*event)(I2CSlave *s, enum i2c_event event);
43
44
45
46
47 int (*decode_address)(I2CSlave *s, uint8_t address);
48} I2CSlaveClass;
49
50struct I2CSlave
51{
52 DeviceState qdev;
53
54
55 uint8_t address;
56 uint8_t address_range;
57};
58
59struct I2CBus {
60 BusState qbus;
61 QLIST_HEAD(, I2CNode) current_devs;
62 uint8_t saved_address;
63 bool broadcast;
64};
65
66I2CBus *i2c_init_bus(DeviceState *parent, const char *name);
67void i2c_set_slave_address(I2CSlave *dev, uint8_t address);
68int i2c_bus_busy(I2CBus *bus);
69int i2c_start_transfer(I2CBus *bus, uint8_t address, int recv);
70void i2c_end_transfer(I2CBus *bus);
71void i2c_nack(I2CBus *bus);
72int i2c_send_recv(I2CBus *bus, uint8_t *data, bool send);
73int i2c_send(I2CBus *bus, uint8_t data);
74int i2c_recv(I2CBus *bus);
75
76DeviceState *i2c_create_slave(I2CBus *bus, const char *name, uint8_t addr);
77
78
79void wm8750_data_req_set(DeviceState *dev,
80 void (*data_req)(void *, int, int), void *opaque);
81void wm8750_dac_dat(void *opaque, uint32_t sample);
82uint32_t wm8750_adc_dat(void *opaque);
83void *wm8750_dac_buffer(void *opaque, int samples);
84void wm8750_dac_commit(void *opaque);
85void wm8750_set_bclk_in(void *opaque, int new_hz);
86
87
88void lm832x_key_event(DeviceState *dev, int key, int state);
89
90extern const VMStateDescription vmstate_i2c_slave;
91
92#define VMSTATE_I2C_SLAVE(_field, _state) { \
93 .name = (stringify(_field)), \
94 .size = sizeof(I2CSlave), \
95 .vmsd = &vmstate_i2c_slave, \
96 .flags = VMS_STRUCT, \
97 .offset = vmstate_offset_value(_state, _field, I2CSlave), \
98}
99
100#endif
101