1
2
3
4
5
6
7
8
9#ifndef LIBQOS_I2C_H
10#define LIBQOS_I2C_H
11
12#include "libqtest.h"
13#include "libqos/qgraph.h"
14
15typedef struct I2CAdapter I2CAdapter;
16struct I2CAdapter {
17 void (*send)(I2CAdapter *adapter, uint8_t addr,
18 const uint8_t *buf, uint16_t len);
19 void (*recv)(I2CAdapter *adapter, uint8_t addr,
20 uint8_t *buf, uint16_t len);
21
22 QTestState *qts;
23};
24
25typedef struct QI2CAddress QI2CAddress;
26struct QI2CAddress {
27 uint8_t addr;
28};
29
30typedef struct QI2CDevice QI2CDevice;
31struct QI2CDevice {
32
33
34
35
36
37
38
39
40
41
42 QOSGraphObject obj;
43 I2CAdapter *bus;
44 uint8_t addr;
45};
46
47void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr);
48void add_qi2c_address(QOSGraphEdgeOptions *opts, QI2CAddress *addr);
49
50void i2c_send(QI2CDevice *dev, const uint8_t *buf, uint16_t len);
51void i2c_recv(QI2CDevice *dev, uint8_t *buf, uint16_t len);
52
53void i2c_read_block(QI2CDevice *dev, uint8_t reg,
54 uint8_t *buf, uint16_t len);
55void i2c_write_block(QI2CDevice *dev, uint8_t reg,
56 const uint8_t *buf, uint16_t len);
57uint8_t i2c_get8(QI2CDevice *dev, uint8_t reg);
58uint16_t i2c_get16(QI2CDevice *dev, uint8_t reg);
59void i2c_set8(QI2CDevice *dev, uint8_t reg, uint8_t value);
60void i2c_set16(QI2CDevice *dev, uint8_t reg, uint16_t value);
61
62
63typedef struct OMAPI2C {
64 QOSGraphObject obj;
65 I2CAdapter parent;
66
67 uint64_t addr;
68} OMAPI2C;
69
70void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr);
71
72
73typedef struct IMXI2C {
74 QOSGraphObject obj;
75 I2CAdapter parent;
76
77 uint64_t addr;
78} IMXI2C;
79
80void imx_i2c_init(IMXI2C *s, QTestState *qts, uint64_t addr);
81
82#endif
83