]> git.ipfire.org Git - thirdparty/qemu.git/blame - tests/pca9552-test.c
hw/rdma: Utilize ibv_reg_mr_iova for memory registration
[thirdparty/qemu.git] / tests / pca9552-test.c
CommitLineData
5141d415
CLG
1/*
2 * QTest testcase for the PCA9552 LED blinker
3 *
4 * Copyright (c) 2017-2018, IBM Corporation.
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
10#include "qemu/osdep.h"
11
12#include "libqtest.h"
93c3fe2a 13#include "libqos/qgraph.h"
5141d415
CLG
14#include "libqos/i2c.h"
15#include "hw/misc/pca9552_regs.h"
16
17#define PCA9552_TEST_ID "pca9552-test"
18#define PCA9552_TEST_ADDR 0x60
19
93c3fe2a 20static void pca9552_init(QI2CDevice *i2cdev)
eadcd3b2
PB
21{
22 /* Switch on LEDs 0 and 12 */
06599472
PB
23 i2c_set8(i2cdev, PCA9552_LS0, 0x54);
24 i2c_set8(i2cdev, PCA9552_LS3, 0x54);
eadcd3b2
PB
25}
26
93c3fe2a 27static void receive_autoinc(void *obj, void *data, QGuestAllocator *alloc)
5141d415 28{
93c3fe2a 29 QI2CDevice *i2cdev = (QI2CDevice *)obj;
5141d415
CLG
30 uint8_t resp;
31 uint8_t reg = PCA9552_LS0 | PCA9552_AUTOINC;
32
eadcd3b2
PB
33 pca9552_init(i2cdev);
34
06599472 35 i2c_send(i2cdev, &reg, 1);
5141d415
CLG
36
37 /* PCA9552_LS0 */
06599472 38 i2c_recv(i2cdev, &resp, 1);
5141d415
CLG
39 g_assert_cmphex(resp, ==, 0x54);
40
41 /* PCA9552_LS1 */
06599472 42 i2c_recv(i2cdev, &resp, 1);
5141d415
CLG
43 g_assert_cmphex(resp, ==, 0x55);
44
45 /* PCA9552_LS2 */
06599472 46 i2c_recv(i2cdev, &resp, 1);
5141d415
CLG
47 g_assert_cmphex(resp, ==, 0x55);
48
49 /* PCA9552_LS3 */
06599472 50 i2c_recv(i2cdev, &resp, 1);
5141d415
CLG
51 g_assert_cmphex(resp, ==, 0x54);
52}
53
93c3fe2a 54static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc)
5141d415 55{
93c3fe2a 56 QI2CDevice *i2cdev = (QI2CDevice *)obj;
5141d415
CLG
57 uint8_t value;
58
06599472 59 value = i2c_get8(i2cdev, PCA9552_LS0);
5141d415
CLG
60 g_assert_cmphex(value, ==, 0x55);
61
06599472 62 value = i2c_get8(i2cdev, PCA9552_INPUT0);
5141d415
CLG
63 g_assert_cmphex(value, ==, 0x0);
64
eadcd3b2
PB
65 pca9552_init(i2cdev);
66
06599472 67 value = i2c_get8(i2cdev, PCA9552_LS0);
5141d415
CLG
68 g_assert_cmphex(value, ==, 0x54);
69
06599472 70 value = i2c_get8(i2cdev, PCA9552_INPUT0);
5141d415
CLG
71 g_assert_cmphex(value, ==, 0x01);
72
06599472 73 value = i2c_get8(i2cdev, PCA9552_LS3);
5141d415
CLG
74 g_assert_cmphex(value, ==, 0x54);
75
06599472 76 value = i2c_get8(i2cdev, PCA9552_INPUT1);
5141d415
CLG
77 g_assert_cmphex(value, ==, 0x10);
78}
79
93c3fe2a 80static void pca9552_register_nodes(void)
5141d415 81{
93c3fe2a
PB
82 QOSGraphEdgeOptions opts = {
83 .extra_device_opts = "address=0x60"
84 };
06599472 85 add_qi2c_address(&opts, &(QI2CAddress) { 0x60 });
5141d415 86
93c3fe2a
PB
87 qos_node_create_driver("pca9552", i2c_device_create);
88 qos_node_consumes("pca9552", "i2c-bus", &opts);
5141d415 89
93c3fe2a
PB
90 qos_add_test("tx-rx", "pca9552", send_and_receive, NULL);
91 qos_add_test("rx-autoinc", "pca9552", receive_autoinc, NULL);
5141d415 92}
93c3fe2a 93libqos_init(pca9552_register_nodes);