summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers/ps8xxx/src/multi_port.c
blob: 76bcbb4c38cd218dc046086b166ceaf88140162d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Copyright 2023 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "driver/tcpm/tcpci.h"
#include "emul/tcpc/emul_ps8xxx.h"
#include "tcpm/tcpm.h"
#include "test/drivers/stubs.h"
#include "test/drivers/test_state.h"
#include "test/drivers/utils.h"

#include <zephyr/shell/shell.h>
#include <zephyr/ztest.h>

#define PS8XXX_NODE_0 DT_NODELABEL(ps8xxx_emul0)
#define PS8XXX_NODE_1 DT_NODELABEL(ps8xxx_emul1)

ZTEST_SUITE(multi_port, drivers_predicate_post_main, NULL, NULL, NULL, NULL);

const struct emul *ps8xxx_emul_0 = EMUL_DT_GET(PS8XXX_NODE_0);
const struct emul *ps8xxx_emul_1 = EMUL_DT_GET(PS8XXX_NODE_1);

ZTEST(multi_port, test_multiple_ports)
{
	zassert_ok(tcpci_emul_set_reg(ps8xxx_emul_0, TCPC_REG_BCD_DEV, 2),
		   "Unable to set device id for emulator 0.\n");
	zassert_ok(tcpci_emul_set_reg(ps8xxx_emul_1, TCPC_REG_BCD_DEV, 3),
		   "Unable to set device id for emulator 1.\n");

	struct ec_response_pd_chip_info_v1 info[USBC_PORT_COUNT];

	for (enum usbc_port p = USBC_PORT_C0; p < USBC_PORT_COUNT; p++) {
		zassert_ok(tcpm_get_chip_info(p, true, &info[p]),
			   "Failed to process tcpm_get_chip_info for port %d",
			   p);
	}

	zassert_true(info[USBC_PORT_C0].device_id !=
			     info[USBC_PORT_C1].device_id,
		     "port 0 and port 1 contains duplicate information.\n");
}

ZTEST(multi_port, test_fw_version_cache)
{
	zassert_ok(tcpci_emul_set_reg(ps8xxx_emul_0, PS8XXX_REG_FW_REV, 0x12),
		   "Unable to set firmware rev for emulator 0.\n");
	zassert_ok(tcpci_emul_set_reg(ps8xxx_emul_1, PS8XXX_REG_FW_REV, 0x13),
		   "Unable to set firmware rev for emulator 1.\n");

	struct ec_response_pd_chip_info_v1 info[USBC_PORT_COUNT];

	for (enum usbc_port p = USBC_PORT_C0; p < USBC_PORT_COUNT; p++) {
		zassert_ok(tcpm_get_chip_info(p, true, &info[p]),
			   "Failed to process tcpm_get_chip_info for port %d",
			   p);
	}

	/* info is read from the cache the second time */
	for (enum usbc_port p = USBC_PORT_C0; p < USBC_PORT_COUNT; p++) {
		zassert_ok(tcpm_get_chip_info(p, false, &info[p]),
			   "Failed to process tcpm_get_chip_info for port %d",
			   p);
	}

	zassert_true(info[USBC_PORT_C0].fw_version_number == 0x12,
		     "port 0 fw version cache is incorrect.\n");
	zassert_true(info[USBC_PORT_C1].fw_version_number == 0x13,
		     "port 1 fw version cache is incorrect.\n");
}