11cf4323eSThomas Huth /* 21cf4323eSThomas Huth * I2C libqos 31cf4323eSThomas Huth * 41cf4323eSThomas Huth * Copyright (c) 2012 Andreas Färber 51cf4323eSThomas Huth * 61cf4323eSThomas Huth * This work is licensed under the terms of the GNU GPL, version 2 or later. 71cf4323eSThomas Huth * See the COPYING file in the top-level directory. 81cf4323eSThomas Huth */ 91cf4323eSThomas Huth #ifndef LIBQOS_I2C_H 101cf4323eSThomas Huth #define LIBQOS_I2C_H 111cf4323eSThomas Huth 121cf4323eSThomas Huth #include "libqtest.h" 131cf4323eSThomas Huth #include "libqos/qgraph.h" 141cf4323eSThomas Huth 151cf4323eSThomas Huth typedef struct I2CAdapter I2CAdapter; 161cf4323eSThomas Huth struct I2CAdapter { 171cf4323eSThomas Huth void (*send)(I2CAdapter *adapter, uint8_t addr, 181cf4323eSThomas Huth const uint8_t *buf, uint16_t len); 191cf4323eSThomas Huth void (*recv)(I2CAdapter *adapter, uint8_t addr, 201cf4323eSThomas Huth uint8_t *buf, uint16_t len); 211cf4323eSThomas Huth 221cf4323eSThomas Huth QTestState *qts; 231cf4323eSThomas Huth }; 241cf4323eSThomas Huth 251cf4323eSThomas Huth typedef struct QI2CAddress QI2CAddress; 261cf4323eSThomas Huth struct QI2CAddress { 271cf4323eSThomas Huth uint8_t addr; 281cf4323eSThomas Huth }; 291cf4323eSThomas Huth 301cf4323eSThomas Huth typedef struct QI2CDevice QI2CDevice; 311cf4323eSThomas Huth struct QI2CDevice { 321cf4323eSThomas Huth /* 331cf4323eSThomas Huth * For now, all devices are simple enough that there is no need for 341cf4323eSThomas Huth * them to define their own constructor and get_driver functions. 351cf4323eSThomas Huth * Therefore, QOSGraphObject is included directly in QI2CDevice; 361cf4323eSThomas Huth * the tests expect to get a QI2CDevice rather than doing something 371cf4323eSThomas Huth * like obj->get_driver("i2c-device"). 381cf4323eSThomas Huth * 391cf4323eSThomas Huth * In fact there is no i2c-device interface even, because there are 401cf4323eSThomas Huth * no generic I2C tests). 411cf4323eSThomas Huth */ 421cf4323eSThomas Huth QOSGraphObject obj; 431cf4323eSThomas Huth I2CAdapter *bus; 441cf4323eSThomas Huth uint8_t addr; 451cf4323eSThomas Huth }; 461cf4323eSThomas Huth 471cf4323eSThomas Huth void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr); 481cf4323eSThomas Huth void add_qi2c_address(QOSGraphEdgeOptions *opts, QI2CAddress *addr); 491cf4323eSThomas Huth 50*39397a9aSAlexander Bulekov void qi2c_send(QI2CDevice *dev, const uint8_t *buf, uint16_t len); 51*39397a9aSAlexander Bulekov void qi2c_recv(QI2CDevice *dev, uint8_t *buf, uint16_t len); 521cf4323eSThomas Huth 531cf4323eSThomas Huth void i2c_read_block(QI2CDevice *dev, uint8_t reg, 541cf4323eSThomas Huth uint8_t *buf, uint16_t len); 551cf4323eSThomas Huth void i2c_write_block(QI2CDevice *dev, uint8_t reg, 561cf4323eSThomas Huth const uint8_t *buf, uint16_t len); 571cf4323eSThomas Huth uint8_t i2c_get8(QI2CDevice *dev, uint8_t reg); 581cf4323eSThomas Huth uint16_t i2c_get16(QI2CDevice *dev, uint8_t reg); 591cf4323eSThomas Huth void i2c_set8(QI2CDevice *dev, uint8_t reg, uint8_t value); 601cf4323eSThomas Huth void i2c_set16(QI2CDevice *dev, uint8_t reg, uint16_t value); 611cf4323eSThomas Huth 621cf4323eSThomas Huth /* i2c-omap.c */ 631cf4323eSThomas Huth typedef struct OMAPI2C { 641cf4323eSThomas Huth QOSGraphObject obj; 651cf4323eSThomas Huth I2CAdapter parent; 661cf4323eSThomas Huth 671cf4323eSThomas Huth uint64_t addr; 681cf4323eSThomas Huth } OMAPI2C; 691cf4323eSThomas Huth 701cf4323eSThomas Huth void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr); 711cf4323eSThomas Huth 721cf4323eSThomas Huth /* i2c-imx.c */ 731cf4323eSThomas Huth typedef struct IMXI2C { 741cf4323eSThomas Huth QOSGraphObject obj; 751cf4323eSThomas Huth I2CAdapter parent; 761cf4323eSThomas Huth 771cf4323eSThomas Huth uint64_t addr; 781cf4323eSThomas Huth } IMXI2C; 791cf4323eSThomas Huth 801cf4323eSThomas Huth void imx_i2c_init(IMXI2C *s, QTestState *qts, uint64_t addr); 811cf4323eSThomas Huth 821cf4323eSThomas Huth #endif 83