Skip to content

Commit

Permalink
stm32mp: bsec: add driver data
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Patrick Delaunay <[email protected]>
  • Loading branch information
patrickdelaunay authored and Patrice Chotard committed Jan 19, 2024
1 parent 5c76937 commit 0d0266c
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions arch/arm/mach-stm32mp/bsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -745,26 +752,41 @@ 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);
}

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},
{}
};

Expand Down

0 comments on commit 0d0266c

Please sign in to comment.