162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * OP-TEE STM32MP BSEC PTA interface, used by STM32 ROMEM driver
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2022, STMicroelectronics - All Rights Reserved
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_NVMEM_STM32_BSEC_OPTEE_TA)
962306a36Sopenharmony_ci/**
1062306a36Sopenharmony_ci * stm32_bsec_optee_ta_open() - initialize the STM32 BSEC TA
1162306a36Sopenharmony_ci * @ctx: the OP-TEE context on success
1262306a36Sopenharmony_ci *
1362306a36Sopenharmony_ci * Return:
1462306a36Sopenharmony_ci *	On success, 0. On failure, -errno.
1562306a36Sopenharmony_ci */
1662306a36Sopenharmony_ciint stm32_bsec_optee_ta_open(struct tee_context **ctx);
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci/**
1962306a36Sopenharmony_ci * stm32_bsec_optee_ta_close() - release the STM32 BSEC TA
2062306a36Sopenharmony_ci * @ctx: the OP-TEE context
2162306a36Sopenharmony_ci *
2262306a36Sopenharmony_ci * This function used to clean the OP-TEE resources initialized in
2362306a36Sopenharmony_ci * stm32_bsec_optee_ta_open(); it can be used as callback to
2462306a36Sopenharmony_ci * devm_add_action_or_reset()
2562306a36Sopenharmony_ci */
2662306a36Sopenharmony_civoid stm32_bsec_optee_ta_close(void *ctx);
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/**
2962306a36Sopenharmony_ci * stm32_bsec_optee_ta_read() - nvmem read access using TA client driver
3062306a36Sopenharmony_ci * @ctx: the OP-TEE context provided by stm32_bsec_optee_ta_open
3162306a36Sopenharmony_ci * @offset: nvmem offset
3262306a36Sopenharmony_ci * @buf: buffer to fill with nvem values
3362306a36Sopenharmony_ci * @bytes: number of bytes to read
3462306a36Sopenharmony_ci *
3562306a36Sopenharmony_ci * Return:
3662306a36Sopenharmony_ci *	On success, 0. On failure, -errno.
3762306a36Sopenharmony_ci */
3862306a36Sopenharmony_ciint stm32_bsec_optee_ta_read(struct tee_context *ctx, unsigned int offset,
3962306a36Sopenharmony_ci			     void *buf, size_t bytes);
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci/**
4262306a36Sopenharmony_ci * stm32_bsec_optee_ta_write() - nvmem write access using TA client driver
4362306a36Sopenharmony_ci * @ctx: the OP-TEE context provided by stm32_bsec_optee_ta_open
4462306a36Sopenharmony_ci * @lower: number of lower OTP, not protected by ECC
4562306a36Sopenharmony_ci * @offset: nvmem offset
4662306a36Sopenharmony_ci * @buf: buffer with nvem values
4762306a36Sopenharmony_ci * @bytes: number of bytes to write
4862306a36Sopenharmony_ci *
4962306a36Sopenharmony_ci * Return:
5062306a36Sopenharmony_ci *	On success, 0. On failure, -errno.
5162306a36Sopenharmony_ci */
5262306a36Sopenharmony_ciint stm32_bsec_optee_ta_write(struct tee_context *ctx, unsigned int lower,
5362306a36Sopenharmony_ci			      unsigned int offset, void *buf, size_t bytes);
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci#else
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_cistatic inline int stm32_bsec_optee_ta_open(struct tee_context **ctx)
5862306a36Sopenharmony_ci{
5962306a36Sopenharmony_ci	return -EOPNOTSUPP;
6062306a36Sopenharmony_ci}
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_cistatic inline void stm32_bsec_optee_ta_close(void *ctx)
6362306a36Sopenharmony_ci{
6462306a36Sopenharmony_ci}
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_cistatic inline int stm32_bsec_optee_ta_read(struct tee_context *ctx,
6762306a36Sopenharmony_ci					   unsigned int offset, void *buf,
6862306a36Sopenharmony_ci					   size_t bytes)
6962306a36Sopenharmony_ci{
7062306a36Sopenharmony_ci	return -EOPNOTSUPP;
7162306a36Sopenharmony_ci}
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_cistatic inline int stm32_bsec_optee_ta_write(struct tee_context *ctx,
7462306a36Sopenharmony_ci					    unsigned int lower,
7562306a36Sopenharmony_ci					    unsigned int offset, void *buf,
7662306a36Sopenharmony_ci					    size_t bytes)
7762306a36Sopenharmony_ci{
7862306a36Sopenharmony_ci	return -EOPNOTSUPP;
7962306a36Sopenharmony_ci}
8062306a36Sopenharmony_ci#endif /* CONFIG_NVMEM_STM32_BSEC_OPTEE_TA */
81