root / hw / i2c.h @ 07f9fd48
History | View | Annotate | Download (2.8 kB)
1 | 0ff596d0 | pbrook | #ifndef QEMU_I2C_H
|
---|---|---|---|
2 | 0ff596d0 | pbrook | #define QEMU_I2C_H
|
3 | 0ff596d0 | pbrook | |
4 | fe8de492 | Paul Brook | #include "qdev.h" |
5 | fe8de492 | Paul Brook | |
6 | 0ff596d0 | pbrook | /* The QEMU I2C implementation only supports simple transfers that complete
|
7 | 0ff596d0 | pbrook | immediately. It does not support slave devices that need to be able to
|
8 | 0ff596d0 | pbrook | defer their response (eg. CPU slave interfaces where the data is supplied
|
9 | 0ff596d0 | pbrook | by the device driver in response to an interrupt). */
|
10 | 0ff596d0 | pbrook | |
11 | 0ff596d0 | pbrook | enum i2c_event {
|
12 | 0ff596d0 | pbrook | I2C_START_RECV, |
13 | 0ff596d0 | pbrook | I2C_START_SEND, |
14 | 0ff596d0 | pbrook | I2C_FINISH, |
15 | aa1f17c1 | ths | I2C_NACK /* Masker NACKed a receive byte. */
|
16 | 0ff596d0 | pbrook | }; |
17 | 0ff596d0 | pbrook | |
18 | 9e07bdf8 | Anthony Liguori | typedef struct I2CSlave I2CSlave; |
19 | 9e07bdf8 | Anthony Liguori | |
20 | b5ea9327 | Anthony Liguori | #define TYPE_I2C_SLAVE "i2c-slave" |
21 | b5ea9327 | Anthony Liguori | #define I2C_SLAVE(obj) \
|
22 | b5ea9327 | Anthony Liguori | OBJECT_CHECK(I2CSlave, (obj), TYPE_I2C_SLAVE) |
23 | b5ea9327 | Anthony Liguori | #define I2C_SLAVE_CLASS(klass) \
|
24 | b5ea9327 | Anthony Liguori | OBJECT_CLASS_CHECK(I2CSlaveClass, (klass), TYPE_I2C_SLAVE) |
25 | b5ea9327 | Anthony Liguori | #define I2C_SLAVE_GET_CLASS(obj) \
|
26 | b5ea9327 | Anthony Liguori | OBJECT_GET_CLASS(I2CSlaveClass, (obj), TYPE_I2C_SLAVE) |
27 | 0ff596d0 | pbrook | |
28 | b5ea9327 | Anthony Liguori | typedef struct I2CSlaveClass |
29 | b5ea9327 | Anthony Liguori | { |
30 | b5ea9327 | Anthony Liguori | DeviceClass parent_class; |
31 | 02e2da45 | Paul Brook | |
32 | fe8de492 | Paul Brook | /* Callbacks provided by the device. */
|
33 | b5ea9327 | Anthony Liguori | int (*init)(I2CSlave *dev);
|
34 | b5ea9327 | Anthony Liguori | |
35 | b5ea9327 | Anthony Liguori | /* Master to slave. */
|
36 | b5ea9327 | Anthony Liguori | int (*send)(I2CSlave *s, uint8_t data);
|
37 | b5ea9327 | Anthony Liguori | |
38 | b5ea9327 | Anthony Liguori | /* Slave to master. */
|
39 | b5ea9327 | Anthony Liguori | int (*recv)(I2CSlave *s);
|
40 | b5ea9327 | Anthony Liguori | |
41 | b5ea9327 | Anthony Liguori | /* Notify the slave of a bus state change. */
|
42 | b5ea9327 | Anthony Liguori | void (*event)(I2CSlave *s, enum i2c_event event); |
43 | b5ea9327 | Anthony Liguori | } I2CSlaveClass; |
44 | fe8de492 | Paul Brook | |
45 | 9e07bdf8 | Anthony Liguori | struct I2CSlave
|
46 | 0ff596d0 | pbrook | { |
47 | fe8de492 | Paul Brook | DeviceState qdev; |
48 | 0ff596d0 | pbrook | |
49 | 0ff596d0 | pbrook | /* Remaining fields for internal use by the I2C code. */
|
50 | 5b7f5327 | Juan Quintela | uint8_t address; |
51 | 0ff596d0 | pbrook | }; |
52 | 0ff596d0 | pbrook | |
53 | 02e2da45 | Paul Brook | i2c_bus *i2c_init_bus(DeviceState *parent, const char *name); |
54 | 9e07bdf8 | Anthony Liguori | void i2c_set_slave_address(I2CSlave *dev, uint8_t address);
|
55 | 0ff596d0 | pbrook | int i2c_bus_busy(i2c_bus *bus);
|
56 | 5b7f5327 | Juan Quintela | int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv); |
57 | 0ff596d0 | pbrook | void i2c_end_transfer(i2c_bus *bus);
|
58 | 0ff596d0 | pbrook | void i2c_nack(i2c_bus *bus);
|
59 | 0ff596d0 | pbrook | int i2c_send(i2c_bus *bus, uint8_t data);
|
60 | 0ff596d0 | pbrook | int i2c_recv(i2c_bus *bus);
|
61 | 0ff596d0 | pbrook | |
62 | 9e07bdf8 | Anthony Liguori | #define I2C_SLAVE_FROM_QDEV(dev) DO_UPCAST(I2CSlave, qdev, dev)
|
63 | fe8de492 | Paul Brook | #define FROM_I2C_SLAVE(type, dev) DO_UPCAST(type, i2c, dev)
|
64 | fe8de492 | Paul Brook | |
65 | 5b7f5327 | Juan Quintela | DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr); |
66 | fe8de492 | Paul Brook | |
67 | adb86c37 | balrog | /* wm8750.c */
|
68 | cdbe40ca | Paul Brook | void wm8750_data_req_set(DeviceState *dev,
|
69 | adb86c37 | balrog | void (*data_req)(void *, int, int), void *opaque); |
70 | adb86c37 | balrog | void wm8750_dac_dat(void *opaque, uint32_t sample); |
71 | adb86c37 | balrog | uint32_t wm8750_adc_dat(void *opaque);
|
72 | 662caa6f | balrog | void *wm8750_dac_buffer(void *opaque, int samples); |
73 | 662caa6f | balrog | void wm8750_dac_commit(void *opaque); |
74 | b0f74c87 | balrog | void wm8750_set_bclk_in(void *opaque, int new_hz); |
75 | adb86c37 | balrog | |
76 | 7e7c5e4c | balrog | /* tmp105.c */
|
77 | 9e07bdf8 | Anthony Liguori | void tmp105_set(I2CSlave *i2c, int temp); |
78 | 7e7c5e4c | balrog | |
79 | 1d4e547b | balrog | /* lm832x.c */
|
80 | c4f05c8c | Peter Maydell | void lm832x_key_event(DeviceState *dev, int key, int state); |
81 | 1d4e547b | balrog | |
82 | 701a8f76 | Paolo Bonzini | extern const VMStateDescription vmstate_i2c_slave; |
83 | 701a8f76 | Paolo Bonzini | |
84 | 701a8f76 | Paolo Bonzini | #define VMSTATE_I2C_SLAVE(_field, _state) { \
|
85 | 701a8f76 | Paolo Bonzini | .name = (stringify(_field)), \ |
86 | 9e07bdf8 | Anthony Liguori | .size = sizeof(I2CSlave), \
|
87 | 701a8f76 | Paolo Bonzini | .vmsd = &vmstate_i2c_slave, \ |
88 | 701a8f76 | Paolo Bonzini | .flags = VMS_STRUCT, \ |
89 | 9e07bdf8 | Anthony Liguori | .offset = vmstate_offset_value(_state, _field, I2CSlave), \ |
90 | 701a8f76 | Paolo Bonzini | } |
91 | 701a8f76 | Paolo Bonzini | |
92 | 0ff596d0 | pbrook | #endif |