Merge commit 'd34e8f6e9d3a396c3327aa9807c83f9e1f4a7bd7' into upstream-merge
[qemu-kvm.git] / hw / i2c.h
blob31fd59c82c15c0132474bc07f28245976861e568
1 #ifndef QEMU_I2C_H
2 #define QEMU_I2C_H
4 #include "qdev.h"
6 /* The QEMU I2C implementation only supports simple transfers that complete
7 immediately. It does not support slave devices that need to be able to
8 defer their response (eg. CPU slave interfaces where the data is supplied
9 by the device driver in response to an interrupt). */
11 enum i2c_event {
12 I2C_START_RECV,
13 I2C_START_SEND,
14 I2C_FINISH,
15 I2C_NACK /* Masker NACKed a receive byte. */
18 typedef struct I2CSlave I2CSlave;
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)
28 typedef struct I2CSlaveClass
30 DeviceClass parent_class;
32 /* Callbacks provided by the device. */
33 int (*init)(I2CSlave *dev);
35 /* Master to slave. */
36 int (*send)(I2CSlave *s, uint8_t data);
38 /* Slave to master. */
39 int (*recv)(I2CSlave *s);
41 /* Notify the slave of a bus state change. */
42 void (*event)(I2CSlave *s, enum i2c_event event);
43 } I2CSlaveClass;
45 struct I2CSlave
47 DeviceState qdev;
49 /* Remaining fields for internal use by the I2C code. */
50 uint8_t address;
53 i2c_bus *i2c_init_bus(DeviceState *parent, const char *name);
54 void i2c_set_slave_address(I2CSlave *dev, uint8_t address);
55 int i2c_bus_busy(i2c_bus *bus);
56 int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv);
57 void i2c_end_transfer(i2c_bus *bus);
58 void i2c_nack(i2c_bus *bus);
59 int i2c_send(i2c_bus *bus, uint8_t data);
60 int i2c_recv(i2c_bus *bus);
62 #define I2C_SLAVE_FROM_QDEV(dev) DO_UPCAST(I2CSlave, qdev, dev)
63 #define FROM_I2C_SLAVE(type, dev) DO_UPCAST(type, i2c, dev)
65 void i2c_register_slave(DeviceInfo *type);
66 void i2c_register_slave_subclass(DeviceInfo *info, const char *parent);
68 DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr);
70 /* wm8750.c */
71 void wm8750_data_req_set(DeviceState *dev,
72 void (*data_req)(void *, int, int), void *opaque);
73 void wm8750_dac_dat(void *opaque, uint32_t sample);
74 uint32_t wm8750_adc_dat(void *opaque);
75 void *wm8750_dac_buffer(void *opaque, int samples);
76 void wm8750_dac_commit(void *opaque);
77 void wm8750_set_bclk_in(void *opaque, int new_hz);
79 /* tmp105.c */
80 void tmp105_set(I2CSlave *i2c, int temp);
82 /* lm832x.c */
83 void lm832x_key_event(DeviceState *dev, int key, int state);
85 extern const VMStateDescription vmstate_i2c_slave;
87 #define VMSTATE_I2C_SLAVE(_field, _state) { \
88 .name = (stringify(_field)), \
89 .size = sizeof(I2CSlave), \
90 .vmsd = &vmstate_i2c_slave, \
91 .flags = VMS_STRUCT, \
92 .offset = vmstate_offset_value(_state, _field, I2CSlave), \
95 #endif