[PATCH v2 03/14] stm32mp: bsec: add driver data
Patrice CHOTARD
patrice.chotard at foss.st.com
Fri Jan 19 14:24:44 CET 2024
On 1/15/24 15:05, Patrick Delaunay wrote:
> Add driver data in BSEC driver to test presence of OP-TEE TA,
> mandatory for STM32MP13 family and prepare the support of new device
> with more OTP than 95.
>
> Reviewed-by: Patrice Chotard <patrice.chotard at foss.st.com>
> Signed-off-by: Patrick Delaunay <patrick.delaunay at foss.st.com>
> ---
>
> (no changes since v1)
>
> arch/arm/mach-stm32mp/bsec.c | 38 ++++++++++++++++++++++++++++--------
> 1 file changed, 30 insertions(+), 8 deletions(-)
>
> diff --git a/arch/arm/mach-stm32mp/bsec.c b/arch/arm/mach-stm32mp/bsec.c
> index 28a8280b2804..705c994d9307 100644
> --- a/arch/arm/mach-stm32mp/bsec.c
> +++ b/arch/arm/mach-stm32mp/bsec.c
> @@ -20,7 +20,6 @@
> #include <linux/iopoll.h>
> #include <linux/printk.h>
>
> -#define BSEC_OTP_MAX_VALUE 95
> #define BSEC_OTP_UPPER_START 32
> #define BSEC_TIMEOUT_US 10000
>
> @@ -400,6 +399,11 @@ struct stm32mp_bsec_priv {
> struct udevice *tee;
> };
>
> +struct stm32mp_bsec_drvdata {
> + int size;
> + bool ta;
> +};
> +
> static int stm32mp_bsec_read_otp(struct udevice *dev, u32 *val, u32 otp)
> {
> struct stm32mp_bsec_plat *plat;
> @@ -609,6 +613,7 @@ static int stm32mp_bsec_read(struct udevice *dev, int offset,
> void *buf, int size)
> {
> struct stm32mp_bsec_priv *priv = dev_get_priv(dev);
> + struct stm32mp_bsec_drvdata *data = (struct stm32mp_bsec_drvdata *)dev_get_driver_data(dev);
> int ret;
> int i;
> bool shadow = true, lock = false;
> @@ -642,7 +647,7 @@ static int stm32mp_bsec_read(struct udevice *dev, int offset,
>
> otp = offs / sizeof(u32);
>
> - for (i = otp; i < (otp + nb_otp) && i <= BSEC_OTP_MAX_VALUE; i++) {
> + for (i = otp; i < (otp + nb_otp) && i < data->size; i++) {
> u32 *addr = &((u32 *)buf)[i - otp];
>
> if (lock)
> @@ -665,6 +670,7 @@ static int stm32mp_bsec_write(struct udevice *dev, int offset,
> const void *buf, int size)
> {
> struct stm32mp_bsec_priv *priv = dev_get_priv(dev);
> + struct stm32mp_bsec_drvdata *data = (struct stm32mp_bsec_drvdata *)dev_get_driver_data(dev);
> int ret = 0;
> int i;
> bool shadow = true, lock = false;
> @@ -698,7 +704,7 @@ static int stm32mp_bsec_write(struct udevice *dev, int offset,
>
> otp = offs / sizeof(u32);
>
> - for (i = otp; i < otp + nb_otp && i <= BSEC_OTP_MAX_VALUE; i++) {
> + for (i = otp; i < otp + nb_otp && i < data->size; i++) {
> u32 *val = &((u32 *)buf)[i - otp];
>
> if (lock)
> @@ -732,6 +738,7 @@ static int stm32mp_bsec_of_to_plat(struct udevice *dev)
>
> static int stm32mp_bsec_probe(struct udevice *dev)
> {
> + struct stm32mp_bsec_drvdata *data = (struct stm32mp_bsec_drvdata *)dev_get_driver_data(dev);
> int otp;
> struct stm32mp_bsec_plat *plat;
> struct clk_bulk clk_bulk;
> @@ -745,16 +752,22 @@ static int stm32mp_bsec_probe(struct udevice *dev)
> }
>
> if (IS_ENABLED(CONFIG_OPTEE))
> - bsec_optee_open(dev);
> + ret = bsec_optee_open(dev);
> + else
> + ret = -ENOTSUPP;
> + /* failed if OP-TEE TA is required */
> + if (data->ta && !ret)
> + return ret;
>
> /*
> * update unlocked shadow for OTP cleared by the rom code
> * only executed in SPL, it is done in TF-A for TFABOOT
> */
> - if (IS_ENABLED(CONFIG_SPL_BUILD)) {
> + if (IS_ENABLED(CONFIG_SPL_BUILD) && !data->ta) {
> plat = dev_get_plat(dev);
>
> - for (otp = 57; otp <= BSEC_OTP_MAX_VALUE; otp++)
> + /* here 57 is the value for STM32MP15x ROM code, only MPU with SPL support*/
> + for (otp = 57; otp < data->size; otp++)
> if (!bsec_read_SR_lock(plat->base, otp))
> bsec_shadow_register(dev, plat->base, otp);
> }
> @@ -762,9 +775,18 @@ static int stm32mp_bsec_probe(struct udevice *dev)
> return 0;
> }
>
> +static const struct stm32mp_bsec_drvdata stm32mp13_data = {
> + .size = 96,
> + .ta = true,
> +};
> +
> +static const struct stm32mp_bsec_drvdata stm32mp15_data = {
> + .size = 96,
> + .ta = false,
> +};
> static const struct udevice_id stm32mp_bsec_ids[] = {
> - { .compatible = "st,stm32mp13-bsec" },
> - { .compatible = "st,stm32mp15-bsec" },
> + { .compatible = "st,stm32mp13-bsec", .data = (ulong)&stm32mp13_data},
> + { .compatible = "st,stm32mp15-bsec", .data = (ulong)&stm32mp15_data},
> {}
> };
>
Applied to u-boot-stm32/master
Thanks
Patrice
More information about the U-Boot
mailing list