xref: /qemu/tests/qtest/libqos/i2c.h (revision 732c919cf04c0aaf1b092238e8b84cdb7adf657a)
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 
14 typedef struct I2CAdapter I2CAdapter;
15 struct I2CAdapter {
16     void (*send)(I2CAdapter *adapter, uint8_t addr,
17                  const uint8_t *buf, uint16_t len);
18     void (*recv)(I2CAdapter *adapter, uint8_t addr,
19                  uint8_t *buf, uint16_t len);
20 
21     QTestState *qts;
22 };
23 
24 #define OMAP2_I2C_1_BASE 0x48070000
25 
26 void i2c_send(I2CAdapter *i2c, uint8_t addr,
27               const uint8_t *buf, uint16_t len);
28 void i2c_recv(I2CAdapter *i2c, uint8_t addr,
29               uint8_t *buf, uint16_t len);
30 
31 void i2c_read_block(I2CAdapter *i2c, uint8_t addr, uint8_t reg,
32                     uint8_t *buf, uint16_t len);
33 void i2c_write_block(I2CAdapter *i2c, uint8_t addr, uint8_t reg,
34                      const uint8_t *buf, uint16_t len);
35 uint8_t i2c_get8(I2CAdapter *i2c, uint8_t addr, uint8_t reg);
36 uint16_t i2c_get16(I2CAdapter *i2c, uint8_t addr, uint8_t reg);
37 void i2c_set8(I2CAdapter *i2c, uint8_t addr, uint8_t reg,
38               uint8_t value);
39 void i2c_set16(I2CAdapter *i2c, uint8_t addr, uint8_t reg,
40                uint16_t value);
41 
42 /* i2c-omap.c */
43 typedef struct OMAPI2C {
44     I2CAdapter parent;
45 
46     uint64_t addr;
47 } OMAPI2C;
48 
49 void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr);
50 I2CAdapter *omap_i2c_create(QTestState *qts, uint64_t addr);
51 void omap_i2c_free(I2CAdapter *i2c);
52 
53 /* i2c-imx.c */
54 typedef struct IMXI2C {
55     I2CAdapter parent;
56 
57     uint64_t addr;
58 } IMXI2C;
59 
60 void imx_i2c_init(IMXI2C *s, QTestState *qts, uint64_t addr);
61 I2CAdapter *imx_i2c_create(QTestState *qts, uint64_t addr);
62 void imx_i2c_free(I2CAdapter *i2c);
63 
64 #endif
65