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