i2c.h 2.3 KB
Newer Older
A
Andreas Färber 已提交
1 2 3 4 5 6 7 8 9 10 11
/*
 * I2C libqos
 *
 * Copyright (c) 2012 Andreas Färber
 *
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
 * See the COPYING file in the top-level directory.
 */
#ifndef LIBQOS_I2C_H
#define LIBQOS_I2C_H

12
#include "libqtest.h"
P
Paolo Bonzini 已提交
13
#include "libqos/qgraph.h"
A
Andreas Färber 已提交
14 15 16 17 18 19 20

typedef struct I2CAdapter I2CAdapter;
struct I2CAdapter {
    void (*send)(I2CAdapter *adapter, uint8_t addr,
                 const uint8_t *buf, uint16_t len);
    void (*recv)(I2CAdapter *adapter, uint8_t addr,
                 uint8_t *buf, uint16_t len);
21 22

    QTestState *qts;
A
Andreas Färber 已提交
23 24
};

25 26 27 28 29
typedef struct QI2CAddress QI2CAddress;
struct QI2CAddress {
    uint8_t addr;
};

P
Paolo Bonzini 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43
typedef struct QI2CDevice QI2CDevice;
struct QI2CDevice {
    /*
     * For now, all devices are simple enough that there is no need for
     * them to define their own constructor and get_driver functions.
     * Therefore, QOSGraphObject is included directly in QI2CDevice;
     * the tests expect to get a QI2CDevice rather than doing something
     * like obj->get_driver("i2c-device").
     *
     * In fact there is no i2c-device interface even, because there are
     * no generic I2C tests).
     */
    QOSGraphObject obj;
    I2CAdapter *bus;
44
    uint8_t addr;
P
Paolo Bonzini 已提交
45 46 47
};

void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr);
48
void add_qi2c_address(QOSGraphEdgeOptions *opts, QI2CAddress *addr);
P
Paolo Bonzini 已提交
49

50 51
void i2c_send(QI2CDevice *dev, const uint8_t *buf, uint16_t len);
void i2c_recv(QI2CDevice *dev, uint8_t *buf, uint16_t len);
A
Andreas Färber 已提交
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 58 59 60
uint8_t i2c_get8(QI2CDevice *dev, uint8_t reg);
uint16_t i2c_get16(QI2CDevice *dev, uint8_t reg);
void i2c_set8(QI2CDevice *dev, uint8_t reg, uint8_t value);
void i2c_set16(QI2CDevice *dev, uint8_t reg, uint16_t value);
61

62 63
/* i2c-omap.c */
typedef struct OMAPI2C {
P
Paolo Bonzini 已提交
64
    QOSGraphObject obj;
65 66 67 68 69 70 71 72 73
    I2CAdapter parent;

    uint64_t addr;
} OMAPI2C;

void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr);

/* i2c-imx.c */
typedef struct IMXI2C {
P
Paolo Bonzini 已提交
74
    QOSGraphObject obj;
75 76 77 78
    I2CAdapter parent;

    uint64_t addr;
} IMXI2C;
A
Andreas Färber 已提交
79

80
void imx_i2c_init(IMXI2C *s, QTestState *qts, uint64_t addr);
81

A
Andreas Färber 已提交
82
#endif