a3c4de3cac51815540c02694d78c6655d1a4183f
[qemu] / hw / i2c.h
1 #ifndef QEMU_I2C_H
2 #define QEMU_I2C_H
3
4 /* The QEMU I2C implementation only supports simple transfers that complete
5    immediately.  It does not support slave devices that need to be able to
6    defer their response (eg. CPU slave interfaces where the data is supplied
7    by the device driver in response to an interrupt).  */
8
9 enum i2c_event {
10     I2C_START_RECV,
11     I2C_START_SEND,
12     I2C_FINISH,
13     I2C_NACK /* Masker NACKed a recieve byte.  */
14 };
15
16 typedef struct i2c_slave i2c_slave;
17
18 /* Master to slave.  */
19 typedef int (*i2c_send_cb)(i2c_slave *s, uint8_t data);
20 /* Slave to master.  */
21 typedef int (*i2c_recv_cb)(i2c_slave *s);
22 /* Notify the slave of a bus state change.  */
23 typedef void (*i2c_event_cb)(i2c_slave *s, enum i2c_event event);
24
25 struct i2c_slave
26 {
27     /* Callbacks to be set by the device.  */
28     i2c_event_cb event;
29     i2c_recv_cb recv;
30     i2c_send_cb send;
31
32     /* Remaining fields for internal use by the I2C code.  */
33     int address;
34     void *next;
35 };
36
37 typedef struct i2c_bus i2c_bus;
38
39 i2c_bus *i2c_init_bus(void);
40 i2c_slave *i2c_slave_init(i2c_bus *bus, int address, int size);
41 void i2c_set_slave_address(i2c_slave *dev, int address);
42 int i2c_bus_busy(i2c_bus *bus);
43 int i2c_start_transfer(i2c_bus *bus, int address, int recv);
44 void i2c_end_transfer(i2c_bus *bus);
45 void i2c_nack(i2c_bus *bus);
46 int i2c_send(i2c_bus *bus, uint8_t data);
47 int i2c_recv(i2c_bus *bus);
48
49 #endif