summary refs log tree commit diff stats
path: root/tests/ds1338-test.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2019-03-18 15:06:50 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2019-06-03 14:03:02 +0200
commit06599472ec40efef3de7cb2bc98d61e8d4b18a63 (patch)
tree284d2baa0ab63e29a7c0e70adca2d80602a7e16e /tests/ds1338-test.c
parent8130dbcbcda15b3fe5ae1da76bf48868c4ce90fb (diff)
downloadfocaccia-qemu-06599472ec40efef3de7cb2bc98d61e8d4b18a63.tar.gz
focaccia-qemu-06599472ec40efef3de7cb2bc98d61e8d4b18a63.zip
libqos: i2c: move address into QI2CDevice
This removes the hardcoded I2C address from the tests.  The address
is passed via QOSGraphEdgeOptions to i2c_device_create and stored
in the QI2CDevice.

The i2c_send and i2c_recv functions, along with their wrappers,
therefore, can be changed to take a QI2CDevice rather than an
adapter/address pair.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tests/ds1338-test.c')
-rw-r--r--tests/ds1338-test.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/tests/ds1338-test.c b/tests/ds1338-test.c
index fd8fbad533..f6ade9a050 100644
--- a/tests/ds1338-test.c
+++ b/tests/ds1338-test.c
@@ -31,13 +31,12 @@ static inline uint8_t bcd2bin(uint8_t x)
 static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc)
 {
     QI2CDevice *i2cdev = (QI2CDevice *)obj;
-    I2CAdapter *i2c = i2cdev->bus;
 
     uint8_t resp[7];
     time_t now = time(NULL);
     struct tm *tm_ptr = gmtime(&now);
 
-    i2c_read_block(i2c, DS1338_ADDR, 0, resp, sizeof(resp));
+    i2c_read_block(i2cdev, 0, resp, sizeof(resp));
 
     /* check retrieved time againt local time */
     g_assert_cmpuint(bcd2bin(resp[4]), == , tm_ptr->tm_mday);
@@ -50,6 +49,7 @@ static void ds1338_register_nodes(void)
     QOSGraphEdgeOptions opts = {
         .extra_device_opts = "address=0x68"
     };
+    add_qi2c_address(&opts, &(QI2CAddress) { DS1338_ADDR });
 
     qos_node_create_driver("ds1338", i2c_device_create);
     qos_node_consumes("ds1338", "i2c-bus", &opts);