xref: /qemu/tests/qtest/libqos/i2c.h (revision 93c3fe2a349970aaba8d196b8c2cbcd7c472bb81)
1 /*
2  * I2C libqos
3  *
4  * Copyright (c) 2012 Andreas Färber
5  *
6  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7  * See the COPYING file in the top-level directory.
8  */
9 #ifndef LIBQOS_I2C_H
10 #define LIBQOS_I2C_H
11 
12 #include "libqtest.h"
13 #include "libqos/qgraph.h"
14 
15 typedef struct I2CAdapter I2CAdapter;
16 struct 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 
25 typedef struct QI2CDevice QI2CDevice;
26 struct QI2CDevice {
27     /*
28      * For now, all devices are simple enough that there is no need for
29      * them to define their own constructor and get_driver functions.
30      * Therefore, QOSGraphObject is included directly in QI2CDevice;
31      * the tests expect to get a QI2CDevice rather than doing something
32      * like obj->get_driver("i2c-device").
33      *
34      * In fact there is no i2c-device interface even, because there are
35      * no generic I2C tests).
36      */
37     QOSGraphObject obj;
38     I2CAdapter *bus;
39 };
40 
41 void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr);
42 
43 void i2c_send(I2CAdapter *i2c, uint8_t addr,
44               const uint8_t *buf, uint16_t len);
45 void i2c_recv(I2CAdapter *i2c, uint8_t addr,
46               uint8_t *buf, uint16_t len);
47 
48 void i2c_read_block(I2CAdapter *i2c, uint8_t addr, uint8_t reg,
49                     uint8_t *buf, uint16_t len);
50 void i2c_write_block(I2CAdapter *i2c, uint8_t addr, uint8_t reg,
51                      const uint8_t *buf, uint16_t len);
52 uint8_t i2c_get8(I2CAdapter *i2c, uint8_t addr, uint8_t reg);
53 uint16_t i2c_get16(I2CAdapter *i2c, uint8_t addr, uint8_t reg);
54 void i2c_set8(I2CAdapter *i2c, uint8_t addr, uint8_t reg,
55               uint8_t value);
56 void i2c_set16(I2CAdapter *i2c, uint8_t addr, uint8_t reg,
57                uint16_t value);
58 
59 /* i2c-omap.c */
60 typedef struct OMAPI2C {
61     QOSGraphObject obj;
62     I2CAdapter parent;
63 
64     uint64_t addr;
65 } OMAPI2C;
66 
67 void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr);
68 
69 /* i2c-imx.c */
70 typedef struct IMXI2C {
71     QOSGraphObject obj;
72     I2CAdapter parent;
73 
74     uint64_t addr;
75 } IMXI2C;
76 
77 void imx_i2c_init(IMXI2C *s, QTestState *qts, uint64_t addr);
78 I2CAdapter *imx_i2c_create(QTestState *qts, uint64_t addr);
79 void imx_i2c_free(I2CAdapter *i2c);
80 
81 #endif
82