diff options
author | John Wang <wangzhiqiang.bj@bytedance.com> | 2020-12-10 12:11:03 +0100 |
---|---|---|
committer | Cédric Le Goater <clg@kaod.org> | 2020-12-10 12:11:03 +0100 |
commit | 5e623f2bf1b4a43022c2fd31919c76ddb9556e17 (patch) | |
tree | 52d5054d3f7c739f6258197c234bb0add69ec211 /tests | |
parent | 5e7b204dbfae9a562fc73684986f936b97f63877 (diff) | |
download | qemu-5e623f2bf1b4a43022c2fd31919c76ddb9556e17.zip qemu-5e623f2bf1b4a43022c2fd31919c76ddb9556e17.tar.gz qemu-5e623f2bf1b4a43022c2fd31919c76ddb9556e17.tar.bz2 |
hw/misc: add an EMC141{3,4} device model
Largely inspired by the TMP421 temperature sensor, here is a model for
the EMC1413/EMC1414 temperature sensors.
Specs can be found here :
http://ww1.microchip.com/downloads/en/DeviceDoc/20005274A.pdf
Signed-off-by: John Wang <wangzhiqiang.bj@bytedance.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Message-Id: <20201122105134.671-1-wangzhiqiang.bj@bytedance.com>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/qtest/emc141x-test.c | 81 | ||||
-rw-r--r-- | tests/qtest/meson.build | 1 |
2 files changed, 82 insertions, 0 deletions
diff --git a/tests/qtest/emc141x-test.c b/tests/qtest/emc141x-test.c new file mode 100644 index 0000000..7140588 --- /dev/null +++ b/tests/qtest/emc141x-test.c @@ -0,0 +1,81 @@ +/* + * QTest testcase for the EMC141X temperature sensor + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#include "libqtest-single.h" +#include "libqos/qgraph.h" +#include "libqos/i2c.h" +#include "qapi/qmp/qdict.h" +#include "hw/misc/emc141x_regs.h" + +#define EMC1414_TEST_ID "emc1414-test" + +static int qmp_emc1414_get_temperature(const char *id) +{ + QDict *response; + int ret; + + response = qmp("{ 'execute': 'qom-get', 'arguments': { 'path': %s, " + "'property': 'temperature0' } }", id); + g_assert(qdict_haskey(response, "return")); + ret = qdict_get_int(response, "return"); + qobject_unref(response); + return ret; +} + +static void qmp_emc1414_set_temperature(const char *id, int value) +{ + QDict *response; + + response = qmp("{ 'execute': 'qom-set', 'arguments': { 'path': %s, " + "'property': 'temperature0', 'value': %d } }", id, value); + g_assert(qdict_haskey(response, "return")); + qobject_unref(response); +} + +static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc) +{ + uint16_t value; + QI2CDevice *i2cdev = (QI2CDevice *)obj; + + value = qmp_emc1414_get_temperature(EMC1414_TEST_ID); + g_assert_cmpuint(value, ==, 0); + + value = i2c_get8(i2cdev, EMC141X_TEMP_HIGH0); + g_assert_cmphex(value, ==, 0); + + /* The default max value is 85C, 0x55=85 */ + value = i2c_get8(i2cdev, EMC141X_TEMP_MAX_HIGH0); + g_assert_cmphex(value, ==, 0x55); + + value = i2c_get8(i2cdev, EMC141X_TEMP_MIN_HIGH0); + g_assert_cmphex(value, ==, 0); + + /* 3000mc = 30C */ + qmp_emc1414_set_temperature(EMC1414_TEST_ID, 30000); + value = qmp_emc1414_get_temperature(EMC1414_TEST_ID); + g_assert_cmpuint(value, ==, 30000); + + value = i2c_get8(i2cdev, EMC141X_TEMP_HIGH0); + g_assert_cmphex(value, ==, 30); + +} + +static void emc1414_register_nodes(void) +{ + QOSGraphEdgeOptions opts = { + .extra_device_opts = "id=" EMC1414_TEST_ID ",address=0x70" + }; + add_qi2c_address(&opts, &(QI2CAddress) { 0x70 }); + + qos_node_create_driver("emc1414", i2c_device_create); + qos_node_consumes("emc1414", "i2c-bus", &opts); + + qos_add_test("tx-rx", "emc1414", send_and_receive, NULL); +} +libqos_init(emc1414_register_nodes); diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index c19f1c8..d776bef 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -188,6 +188,7 @@ qos_test_ss.add( 'sdhci-test.c', 'spapr-phb-test.c', 'tmp105-test.c', + 'emc141x-test.c', 'usb-hcd-ohci-test.c', 'virtio-test.c', 'virtio-blk-test.c', |