summaryrefslogtreecommitdiff
path: root/zephyr/include/emul/tcpc/emul_rt1718s.h
blob: 09614bc02ccd0952195c2e7828b4194aa7ffd360 (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
/* 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.
 */

#ifndef __EMUL_RT1718S_H
#define __EMUL_RT1718S_H

#include "emul/tcpc/emul_tcpci.h"

#include <zephyr/drivers/emul.h>
#include <zephyr/sys/slist.h>

#define RT1718S_EMUL_REG_COUNT_PER_PAGE 0x100

struct set_reg_entry_t {
	struct _snode node;
	int reg;
	uint16_t val;
	int64_t access_time;
};

/** Run-time data used by the emulator */
struct rt1718s_emul_data {
	/* Composite with the tcpc_emul_data to extend it. */
	struct tcpc_emul_data embedded_tcpc_emul_data;
	uint8_t reg_page1[RT1718S_EMUL_REG_COUNT_PER_PAGE];
	uint8_t reg_page2[RT1718S_EMUL_REG_COUNT_PER_PAGE];
	uint8_t current_page;
	uint8_t current_page2_register;
	struct _slist set_private_reg_history;
};

/**
 * @brief Getting each byte of register from rt1718s emulator
 *
 * @param emul Pointer to I2C rt1718s emulator
 * @param reg First byte of last write message
 * @param val Pointer where byte to read should be stored
 *
 * @return 0 on success
 * @return -EINVAL when register is out of range defined in rt1718s private
 *                 register or val is NULL
 */
int rt1718s_emul_get_reg(const struct emul *emul, int reg, uint16_t *val);

/**
 * @brief Reset the register set history
 *
 * @param emul Pointer to I2C rt1718s emulator
 *
 */
void rt1718s_emul_reset_set_history(const struct emul *emul);

/**
 * @brief Set the device id of
 *
 * @param emul Pointer to I2C rt1718s emulator
 * @param device_id the 16 bits device id
 *
 */
void rt1718s_emul_set_device_id(const struct emul *emul, uint16_t device_id);

#endif /* __EMUL_RT1718S_H */