2013-01-16 04:57:54 +04:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2017-09-11 20:19:59 +03:00
|
|
|
#include "libqtest.h"
|
2019-03-18 15:48:23 +03:00
|
|
|
#include "libqos/qgraph.h"
|
2013-01-16 04:57:54 +04:00
|
|
|
|
|
|
|
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);
|
2017-09-11 20:19:59 +03:00
|
|
|
|
|
|
|
QTestState *qts;
|
2013-01-16 04:57:54 +04:00
|
|
|
};
|
|
|
|
|
2019-03-18 17:06:50 +03:00
|
|
|
typedef struct QI2CAddress QI2CAddress;
|
|
|
|
struct QI2CAddress {
|
|
|
|
uint8_t addr;
|
|
|
|
};
|
|
|
|
|
2019-03-18 15:48:23 +03:00
|
|
|
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;
|
2019-03-18 17:06:50 +03:00
|
|
|
uint8_t addr;
|
2019-03-18 15:48:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr);
|
2019-03-18 17:06:50 +03:00
|
|
|
void add_qi2c_address(QOSGraphEdgeOptions *opts, QI2CAddress *addr);
|
2019-03-18 15:48:23 +03:00
|
|
|
|
2019-03-18 17:06:50 +03:00
|
|
|
void i2c_send(QI2CDevice *dev, const uint8_t *buf, uint16_t len);
|
|
|
|
void i2c_recv(QI2CDevice *dev, uint8_t *buf, uint16_t len);
|
2013-01-16 04:57:54 +04:00
|
|
|
|
2019-03-18 17:06:50 +03:00
|
|
|
void i2c_read_block(QI2CDevice *dev, uint8_t reg,
|
2019-03-18 17:09:51 +03:00
|
|
|
uint8_t *buf, uint16_t len);
|
2019-03-18 17:06:50 +03:00
|
|
|
void i2c_write_block(QI2CDevice *dev, uint8_t reg,
|
2019-03-18 17:09:51 +03:00
|
|
|
const uint8_t *buf, uint16_t len);
|
2019-03-18 17:06:50 +03:00
|
|
|
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);
|
2019-03-18 17:09:51 +03:00
|
|
|
|
2019-03-18 19:12:25 +03:00
|
|
|
/* i2c-omap.c */
|
|
|
|
typedef struct OMAPI2C {
|
2019-03-18 15:48:23 +03:00
|
|
|
QOSGraphObject obj;
|
2019-03-18 19:12:25 +03:00
|
|
|
I2CAdapter parent;
|
|
|
|
|
|
|
|
uint64_t addr;
|
|
|
|
} OMAPI2C;
|
|
|
|
|
|
|
|
void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr);
|
|
|
|
|
|
|
|
/* i2c-imx.c */
|
|
|
|
typedef struct IMXI2C {
|
2019-03-18 15:48:23 +03:00
|
|
|
QOSGraphObject obj;
|
2019-03-18 19:12:25 +03:00
|
|
|
I2CAdapter parent;
|
|
|
|
|
|
|
|
uint64_t addr;
|
|
|
|
} IMXI2C;
|
2013-01-16 04:57:54 +04:00
|
|
|
|
2019-03-18 19:12:25 +03:00
|
|
|
void imx_i2c_init(IMXI2C *s, QTestState *qts, uint64_t addr);
|
2015-09-07 12:39:31 +03:00
|
|
|
|
2013-01-16 04:57:54 +04:00
|
|
|
#endif
|