root / hw / i2c.h @ c65fc1df
History | View | Annotate | Download (2.2 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 | 0ff596d0 | pbrook | /* Master to slave. */
|
19 | 0ff596d0 | pbrook | typedef int (*i2c_send_cb)(i2c_slave *s, uint8_t data); |
20 | 0ff596d0 | pbrook | /* Slave to master. */
|
21 | 0ff596d0 | pbrook | typedef int (*i2c_recv_cb)(i2c_slave *s); |
22 | 0ff596d0 | pbrook | /* Notify the slave of a bus state change. */
|
23 | 0ff596d0 | pbrook | typedef void (*i2c_event_cb)(i2c_slave *s, enum i2c_event event); |
24 | 0ff596d0 | pbrook | |
25 | 81a322d4 | Gerd Hoffmann | typedef int (*i2c_slave_initfn)(i2c_slave *dev); |
26 | fe8de492 | Paul Brook | |
27 | fe8de492 | Paul Brook | typedef struct { |
28 | 02e2da45 | Paul Brook | DeviceInfo qdev; |
29 | 02e2da45 | Paul Brook | |
30 | fe8de492 | Paul Brook | /* Callbacks provided by the device. */
|
31 | fe8de492 | Paul Brook | i2c_slave_initfn init; |
32 | fe8de492 | Paul Brook | i2c_event_cb event; |
33 | fe8de492 | Paul Brook | i2c_recv_cb recv; |
34 | fe8de492 | Paul Brook | i2c_send_cb send; |
35 | fe8de492 | Paul Brook | } I2CSlaveInfo; |
36 | fe8de492 | Paul Brook | |
37 | 0ff596d0 | pbrook | struct i2c_slave
|
38 | 0ff596d0 | pbrook | { |
39 | fe8de492 | Paul Brook | DeviceState qdev; |
40 | fe8de492 | Paul Brook | I2CSlaveInfo *info; |
41 | 0ff596d0 | pbrook | |
42 | 0ff596d0 | pbrook | /* Remaining fields for internal use by the I2C code. */
|
43 | 5b7f5327 | Juan Quintela | uint8_t address; |
44 | 0ff596d0 | pbrook | }; |
45 | 0ff596d0 | pbrook | |
46 | 02e2da45 | Paul Brook | i2c_bus *i2c_init_bus(DeviceState *parent, const char *name); |
47 | 5b7f5327 | Juan Quintela | void i2c_set_slave_address(i2c_slave *dev, uint8_t address);
|
48 | 0ff596d0 | pbrook | int i2c_bus_busy(i2c_bus *bus);
|
49 | 5b7f5327 | Juan Quintela | int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv); |
50 | 0ff596d0 | pbrook | void i2c_end_transfer(i2c_bus *bus);
|
51 | 0ff596d0 | pbrook | void i2c_nack(i2c_bus *bus);
|
52 | 0ff596d0 | pbrook | int i2c_send(i2c_bus *bus, uint8_t data);
|
53 | 0ff596d0 | pbrook | int i2c_recv(i2c_bus *bus);
|
54 | 0ff596d0 | pbrook | |
55 | fe8de492 | Paul Brook | #define I2C_SLAVE_FROM_QDEV(dev) DO_UPCAST(i2c_slave, qdev, dev)
|
56 | fe8de492 | Paul Brook | #define FROM_I2C_SLAVE(type, dev) DO_UPCAST(type, i2c, dev)
|
57 | fe8de492 | Paul Brook | |
58 | 074f2fff | Gerd Hoffmann | void i2c_register_slave(I2CSlaveInfo *type);
|
59 | fe8de492 | Paul Brook | |
60 | 5b7f5327 | Juan Quintela | DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr); |
61 | fe8de492 | Paul Brook | |
62 | adb86c37 | balrog | /* wm8750.c */
|
63 | cdbe40ca | Paul Brook | void wm8750_data_req_set(DeviceState *dev,
|
64 | adb86c37 | balrog | void (*data_req)(void *, int, int), void *opaque); |
65 | adb86c37 | balrog | void wm8750_dac_dat(void *opaque, uint32_t sample); |
66 | adb86c37 | balrog | uint32_t wm8750_adc_dat(void *opaque);
|
67 | 662caa6f | balrog | void *wm8750_dac_buffer(void *opaque, int samples); |
68 | 662caa6f | balrog | void wm8750_dac_commit(void *opaque); |
69 | b0f74c87 | balrog | void wm8750_set_bclk_in(void *opaque, int new_hz); |
70 | adb86c37 | balrog | |
71 | 7e7c5e4c | balrog | /* tmp105.c */
|
72 | 7e7c5e4c | balrog | void tmp105_set(i2c_slave *i2c, int temp); |
73 | 7e7c5e4c | balrog | |
74 | 1d4e547b | balrog | /* lm832x.c */
|
75 | c4f05c8c | Peter Maydell | void lm832x_key_event(DeviceState *dev, int key, int state); |
76 | 1d4e547b | balrog | |
77 | 0ff596d0 | pbrook | #endif |