xref: /openbmc/qemu/tests/qtest/libqos/i2c.h (revision ed75658a)
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 "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 QI2CAddress QI2CAddress;
26 struct QI2CAddress {
27     uint8_t addr;
28 };
29 
30 typedef struct QI2CDevice QI2CDevice;
31 struct QI2CDevice {
32     /*
33      * For now, all devices are simple enough that there is no need for
34      * them to define their own constructor and get_driver functions.
35      * Therefore, QOSGraphObject is included directly in QI2CDevice;
36      * the tests expect to get a QI2CDevice rather than doing something
37      * like obj->get_driver("i2c-device").
38      *
39      * In fact there is no i2c-device interface even, because there are
40      * no generic I2C tests).
41      */
42     QOSGraphObject obj;
43     I2CAdapter *bus;
44     uint8_t addr;
45 };
46 
47 void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr);
48 void add_qi2c_address(QOSGraphEdgeOptions *opts, QI2CAddress *addr);
49 
50 void qi2c_send(QI2CDevice *dev, const uint8_t *buf, uint16_t len);
51 void qi2c_recv(QI2CDevice *dev, uint8_t *buf, uint16_t len);
52 
53 void i2c_read_block(QI2CDevice *dev, uint8_t reg,
54                     uint8_t *buf, uint16_t len);
55 void i2c_write_block(QI2CDevice *dev, uint8_t reg,
56                      const uint8_t *buf, uint16_t len);
57 uint8_t i2c_get8(QI2CDevice *dev, uint8_t reg);
58 uint16_t i2c_get16(QI2CDevice *dev, uint8_t reg);
59 void i2c_set8(QI2CDevice *dev, uint8_t reg, uint8_t value);
60 void i2c_set16(QI2CDevice *dev, uint8_t reg, uint16_t value);
61 
62 /* i2c-omap.c */
63 typedef struct OMAPI2C {
64     QOSGraphObject obj;
65     I2CAdapter parent;
66 
67     uint64_t addr;
68 } OMAPI2C;
69 
70 void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr);
71 
72 /* i2c-imx.c */
73 typedef struct IMXI2C {
74     QOSGraphObject obj;
75     I2CAdapter parent;
76 
77     uint64_t addr;
78 } IMXI2C;
79 
80 void imx_i2c_init(IMXI2C *s, QTestState *qts, uint64_t addr);
81 
82 #endif
83