stm32mp: bsec: add driver data
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@foss.st.com> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
This commit is contained in:
committed by
Patrice Chotard
parent
5c76937659
commit
0d0266c46c
@@ -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},
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user