1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2020 Foundries Ltd <jorge@foundries.io>
4  */
5 
6 #ifndef __RPC_IO_I2C_H
7 #define __RPC_IO_I2C_H
8 
9 #include <optee_rpc_cmd.h>
10 #include <tee_api_types.h>
11 
12 /* I2C master transfer mode */
13 enum rpc_i2c_mode {
14 	RPC_I2C_MODE_WRITE = OPTEE_RPC_I2C_TRANSFER_WR,
15 	RPC_I2C_MODE_READ = OPTEE_RPC_I2C_TRANSFER_RD,
16 };
17 
18 /* I2C master transfer control flags */
19 #define RPC_I2C_FLAGS_TEN_BIT	OPTEE_RPC_I2C_FLAGS_TEN_BIT
20 
21 /*
22  * The bus identifier defines an implicit ABI with the REE.
23  * Using this service to access I2C slaves on REE dynamically assigned buses is
24  * not recommended unless there is a guarantee that the bus identifier will
25  * persist across reboots.
26  */
27 struct rpc_i2c_request {
28 	enum rpc_i2c_mode mode;
29 	uint16_t bus; /* bus identifier used by the REE [0..n] */
30 	uint16_t chip; /* slave identifier from its data sheet */
31 	uint16_t flags; /* transfer flags (ie: ten bit chip address) */
32 	uint8_t *buffer;
33 	size_t buffer_len;
34 };
35 
36 TEE_Result rpc_io_i2c_transfer(struct rpc_i2c_request *p, size_t *bytes);
37 
38 #endif /* __RPC_IO_I2C_H */
39