]> git.proxmox.com Git - mirror_qemu.git/blob - tests/tmp105-test.c
Merge remote-tracking branch 'remotes/kvm/uq/master' into staging
[mirror_qemu.git] / tests / tmp105-test.c
1 /*
2 * QTest testcase for the TMP105 temperature sensor
3 *
4 * Copyright (c) 2012 Andreas Färber
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 <glib.h>
11
12 #include "libqtest.h"
13 #include "libqos/i2c.h"
14 #include "hw/misc/tmp105_regs.h"
15
16 #define OMAP2_I2C_1_BASE 0x48070000
17
18 #define N8X0_ADDR 0x48
19
20 static I2CAdapter *i2c;
21 static uint8_t addr;
22
23 static void send_and_receive(void)
24 {
25 uint8_t cmd[3];
26 uint8_t resp[2];
27
28 cmd[0] = TMP105_REG_TEMPERATURE;
29 i2c_send(i2c, addr, cmd, 1);
30 i2c_recv(i2c, addr, resp, 2);
31 g_assert_cmpuint(((uint16_t)resp[0] << 8) | resp[1], ==, 0);
32
33 cmd[0] = TMP105_REG_CONFIG;
34 cmd[1] = 0x0; /* matches the reset value */
35 i2c_send(i2c, addr, cmd, 2);
36 i2c_recv(i2c, addr, resp, 1);
37 g_assert_cmphex(resp[0], ==, cmd[1]);
38
39 cmd[0] = TMP105_REG_T_LOW;
40 cmd[1] = 0x12;
41 cmd[2] = 0x34;
42 i2c_send(i2c, addr, cmd, 3);
43 i2c_recv(i2c, addr, resp, 2);
44 g_assert_cmphex(resp[0], ==, cmd[1]);
45 g_assert_cmphex(resp[1], ==, cmd[2]);
46
47 cmd[0] = TMP105_REG_T_HIGH;
48 cmd[1] = 0x42;
49 cmd[2] = 0x31;
50 i2c_send(i2c, addr, cmd, 3);
51 i2c_recv(i2c, addr, resp, 2);
52 g_assert_cmphex(resp[0], ==, cmd[1]);
53 g_assert_cmphex(resp[1], ==, cmd[2]);
54 }
55
56 int main(int argc, char **argv)
57 {
58 QTestState *s = NULL;
59 int ret;
60
61 g_test_init(&argc, &argv, NULL);
62
63 s = qtest_start("-machine n800");
64 i2c = omap_i2c_create(OMAP2_I2C_1_BASE);
65 addr = N8X0_ADDR;
66
67 qtest_add_func("/tmp105/tx-rx", send_and_receive);
68
69 ret = g_test_run();
70
71 if (s) {
72 qtest_quit(s);
73 }
74 g_free(i2c);
75
76 return ret;
77 }