1*6a0bc352SPatrick Delaunay /* SPDX-License-Identifier: GPL-2.0-or-later */
2*6a0bc352SPatrick Delaunay /*
3*6a0bc352SPatrick Delaunay  * OP-TEE STM32MP BSEC PTA interface, used by STM32 ROMEM driver
4*6a0bc352SPatrick Delaunay  *
5*6a0bc352SPatrick Delaunay  * Copyright (C) 2022, STMicroelectronics - All Rights Reserved
6*6a0bc352SPatrick Delaunay  */
7*6a0bc352SPatrick Delaunay 
8*6a0bc352SPatrick Delaunay #if IS_ENABLED(CONFIG_NVMEM_STM32_BSEC_OPTEE_TA)
9*6a0bc352SPatrick Delaunay /**
10*6a0bc352SPatrick Delaunay  * stm32_bsec_optee_ta_open() - initialize the STM32 BSEC TA
11*6a0bc352SPatrick Delaunay  * @ctx: the OP-TEE context on success
12*6a0bc352SPatrick Delaunay  *
13*6a0bc352SPatrick Delaunay  * Return:
14*6a0bc352SPatrick Delaunay  *	On success, 0. On failure, -errno.
15*6a0bc352SPatrick Delaunay  */
16*6a0bc352SPatrick Delaunay int stm32_bsec_optee_ta_open(struct tee_context **ctx);
17*6a0bc352SPatrick Delaunay 
18*6a0bc352SPatrick Delaunay /**
19*6a0bc352SPatrick Delaunay  * stm32_bsec_optee_ta_close() - release the STM32 BSEC TA
20*6a0bc352SPatrick Delaunay  * @ctx: the OP-TEE context
21*6a0bc352SPatrick Delaunay  *
22*6a0bc352SPatrick Delaunay  * This function used to clean the OP-TEE resources initialized in
23*6a0bc352SPatrick Delaunay  * stm32_bsec_optee_ta_open(); it can be used as callback to
24*6a0bc352SPatrick Delaunay  * devm_add_action_or_reset()
25*6a0bc352SPatrick Delaunay  */
26*6a0bc352SPatrick Delaunay void stm32_bsec_optee_ta_close(void *ctx);
27*6a0bc352SPatrick Delaunay 
28*6a0bc352SPatrick Delaunay /**
29*6a0bc352SPatrick Delaunay  * stm32_bsec_optee_ta_read() - nvmem read access using TA client driver
30*6a0bc352SPatrick Delaunay  * @ctx: the OP-TEE context provided by stm32_bsec_optee_ta_open
31*6a0bc352SPatrick Delaunay  * @offset: nvmem offset
32*6a0bc352SPatrick Delaunay  * @buf: buffer to fill with nvem values
33*6a0bc352SPatrick Delaunay  * @bytes: number of bytes to read
34*6a0bc352SPatrick Delaunay  *
35*6a0bc352SPatrick Delaunay  * Return:
36*6a0bc352SPatrick Delaunay  *	On success, 0. On failure, -errno.
37*6a0bc352SPatrick Delaunay  */
38*6a0bc352SPatrick Delaunay int stm32_bsec_optee_ta_read(struct tee_context *ctx, unsigned int offset,
39*6a0bc352SPatrick Delaunay 			     void *buf, size_t bytes);
40*6a0bc352SPatrick Delaunay 
41*6a0bc352SPatrick Delaunay /**
42*6a0bc352SPatrick Delaunay  * stm32_bsec_optee_ta_write() - nvmem write access using TA client driver
43*6a0bc352SPatrick Delaunay  * @ctx: the OP-TEE context provided by stm32_bsec_optee_ta_open
44*6a0bc352SPatrick Delaunay  * @lower: number of lower OTP, not protected by ECC
45*6a0bc352SPatrick Delaunay  * @offset: nvmem offset
46*6a0bc352SPatrick Delaunay  * @buf: buffer with nvem values
47*6a0bc352SPatrick Delaunay  * @bytes: number of bytes to write
48*6a0bc352SPatrick Delaunay  *
49*6a0bc352SPatrick Delaunay  * Return:
50*6a0bc352SPatrick Delaunay  *	On success, 0. On failure, -errno.
51*6a0bc352SPatrick Delaunay  */
52*6a0bc352SPatrick Delaunay int stm32_bsec_optee_ta_write(struct tee_context *ctx, unsigned int lower,
53*6a0bc352SPatrick Delaunay 			      unsigned int offset, void *buf, size_t bytes);
54*6a0bc352SPatrick Delaunay 
55*6a0bc352SPatrick Delaunay #else
56*6a0bc352SPatrick Delaunay 
stm32_bsec_optee_ta_open(struct tee_context ** ctx)57*6a0bc352SPatrick Delaunay static inline int stm32_bsec_optee_ta_open(struct tee_context **ctx)
58*6a0bc352SPatrick Delaunay {
59*6a0bc352SPatrick Delaunay 	return -EOPNOTSUPP;
60*6a0bc352SPatrick Delaunay }
61*6a0bc352SPatrick Delaunay 
stm32_bsec_optee_ta_close(void * ctx)62*6a0bc352SPatrick Delaunay static inline void stm32_bsec_optee_ta_close(void *ctx)
63*6a0bc352SPatrick Delaunay {
64*6a0bc352SPatrick Delaunay }
65*6a0bc352SPatrick Delaunay 
stm32_bsec_optee_ta_read(struct tee_context * ctx,unsigned int offset,void * buf,size_t bytes)66*6a0bc352SPatrick Delaunay static inline int stm32_bsec_optee_ta_read(struct tee_context *ctx,
67*6a0bc352SPatrick Delaunay 					   unsigned int offset, void *buf,
68*6a0bc352SPatrick Delaunay 					   size_t bytes)
69*6a0bc352SPatrick Delaunay {
70*6a0bc352SPatrick Delaunay 	return -EOPNOTSUPP;
71*6a0bc352SPatrick Delaunay }
72*6a0bc352SPatrick Delaunay 
stm32_bsec_optee_ta_write(struct tee_context * ctx,unsigned int lower,unsigned int offset,void * buf,size_t bytes)73*6a0bc352SPatrick Delaunay static inline int stm32_bsec_optee_ta_write(struct tee_context *ctx,
74*6a0bc352SPatrick Delaunay 					    unsigned int lower,
75*6a0bc352SPatrick Delaunay 					    unsigned int offset, void *buf,
76*6a0bc352SPatrick Delaunay 					    size_t bytes)
77*6a0bc352SPatrick Delaunay {
78*6a0bc352SPatrick Delaunay 	return -EOPNOTSUPP;
79*6a0bc352SPatrick Delaunay }
80*6a0bc352SPatrick Delaunay #endif /* CONFIG_NVMEM_STM32_BSEC_OPTEE_TA */
81