* [PATCH v2 1/3] nvmem: stm32: move STM32MP15_BSEC_NUM_LOWER in config
2022-10-17 15:49 [PATCH v2 0/3] nvmem: stm32: several minor improvements Patrick Delaunay
@ 2022-10-17 15:49 ` Patrick Delaunay
2022-10-17 15:49 ` [PATCH v2 2/3] nvmem: stm32: add warning when upper OTPs are updated Patrick Delaunay
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Patrick Delaunay @ 2022-10-17 15:49 UTC (permalink / raw)
To: Srinivas Kandagatla, Maxime Coquelin, Alexandre Torgue
Cc: Patrick Delaunay, linux-arm-kernel, linux-kernel, linux-stm32
Support STM32MP15_BSEC_NUM_LOWER in stm32 romem config to prepare
the next SoC in STM32MP family.
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---
Changes in v2:
- Add patch "move STM32MP15_BSEC_NUM_LOWER in config" in the serie,
solve dependency issue for "priv->lower" in patch "nvmem: stm32:
add warning when upper OTPs are updated"
drivers/nvmem/stm32-romem.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/drivers/nvmem/stm32-romem.c b/drivers/nvmem/stm32-romem.c
index 354be526897f..d93baee01d7b 100644
--- a/drivers/nvmem/stm32-romem.c
+++ b/drivers/nvmem/stm32-romem.c
@@ -22,16 +22,15 @@
/* shadow registers offest */
#define STM32MP15_BSEC_DATA0 0x200
-/* 32 (x 32-bits) lower shadow registers */
-#define STM32MP15_BSEC_NUM_LOWER 32
-
struct stm32_romem_cfg {
int size;
+ u8 lower;
};
struct stm32_romem_priv {
void __iomem *base;
struct nvmem_config cfg;
+ u8 lower;
};
static int stm32_romem_read(void *context, unsigned int offset, void *buf,
@@ -85,7 +84,7 @@ static int stm32_bsec_read(void *context, unsigned int offset, void *buf,
for (i = roffset; (i < roffset + rbytes); i += 4) {
u32 otp = i >> 2;
- if (otp < STM32MP15_BSEC_NUM_LOWER) {
+ if (otp < priv->lower) {
/* read lower data from shadow registers */
val = readl_relaxed(
priv->base + STM32MP15_BSEC_DATA0 + i);
@@ -159,6 +158,8 @@ static int stm32_romem_probe(struct platform_device *pdev)
priv->cfg.priv = priv;
priv->cfg.owner = THIS_MODULE;
+ priv->lower = 0;
+
cfg = (const struct stm32_romem_cfg *)
of_match_device(dev->driver->of_match_table, dev)->data;
if (!cfg) {
@@ -167,6 +168,7 @@ static int stm32_romem_probe(struct platform_device *pdev)
priv->cfg.reg_read = stm32_romem_read;
} else {
priv->cfg.size = cfg->size;
+ priv->lower = cfg->lower;
priv->cfg.reg_read = stm32_bsec_read;
priv->cfg.reg_write = stm32_bsec_write;
}
@@ -174,8 +176,17 @@ static int stm32_romem_probe(struct platform_device *pdev)
return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &priv->cfg));
}
+/*
+ * STM32MP15 BSEC OTP regions: 4096 OTP bits (with 3072 effective bits)
+ * => 96 x 32-bits data words
+ * - Lower: 1K bits, 2:1 redundancy, incremental bit programming
+ * => 32 (x 32-bits) lower shadow registers = words 0 to 31
+ * - Upper: 2K bits, ECC protection, word programming only
+ * => 64 (x 32-bits) = words 32 to 95
+ */
static const struct stm32_romem_cfg stm32mp15_bsec_cfg = {
- .size = 384, /* 96 x 32-bits data words */
+ .size = 384,
+ .lower = 32,
};
static const struct of_device_id stm32_romem_of_match[] = {
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] nvmem: stm32: add warning when upper OTPs are updated
2022-10-17 15:49 [PATCH v2 0/3] nvmem: stm32: several minor improvements Patrick Delaunay
2022-10-17 15:49 ` [PATCH v2 1/3] nvmem: stm32: move STM32MP15_BSEC_NUM_LOWER in config Patrick Delaunay
@ 2022-10-17 15:49 ` Patrick Delaunay
2022-10-17 15:49 ` [PATCH v2 3/3] nvmem: stm32: add nvmem type attribute Patrick Delaunay
2022-10-31 17:41 ` [PATCH v2 0/3] nvmem: stm32: several minor improvements Srinivas Kandagatla
3 siblings, 0 replies; 5+ messages in thread
From: Patrick Delaunay @ 2022-10-17 15:49 UTC (permalink / raw)
To: Srinivas Kandagatla, Maxime Coquelin, Alexandre Torgue
Cc: Patrick Delaunay, linux-arm-kernel, linux-kernel, linux-stm32
As the upper OTPs are ECC protected, they support only one 32 bits word
programming.
For a second modification of this word, these ECC become invalid and
this OTP will be no more accessible, the shadowed value is invalid.
This patch adds a warning to indicate an upper OTP update, because this
operation is dangerous as OTP is not locked by the driver after the first
update to avoid a second update.
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---
(no changes since v1)
drivers/nvmem/stm32-romem.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/nvmem/stm32-romem.c b/drivers/nvmem/stm32-romem.c
index d93baee01d7b..bb8aa72ba2f9 100644
--- a/drivers/nvmem/stm32-romem.c
+++ b/drivers/nvmem/stm32-romem.c
@@ -132,6 +132,9 @@ static int stm32_bsec_write(void *context, unsigned int offset, void *buf,
}
}
+ if (offset + bytes >= priv->lower * 4)
+ dev_warn(dev, "Update of upper OTPs with ECC protection (word programming, only once)\n");
+
return 0;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] nvmem: stm32: add nvmem type attribute
2022-10-17 15:49 [PATCH v2 0/3] nvmem: stm32: several minor improvements Patrick Delaunay
2022-10-17 15:49 ` [PATCH v2 1/3] nvmem: stm32: move STM32MP15_BSEC_NUM_LOWER in config Patrick Delaunay
2022-10-17 15:49 ` [PATCH v2 2/3] nvmem: stm32: add warning when upper OTPs are updated Patrick Delaunay
@ 2022-10-17 15:49 ` Patrick Delaunay
2022-10-31 17:41 ` [PATCH v2 0/3] nvmem: stm32: several minor improvements Srinivas Kandagatla
3 siblings, 0 replies; 5+ messages in thread
From: Patrick Delaunay @ 2022-10-17 15:49 UTC (permalink / raw)
To: Srinivas Kandagatla, Maxime Coquelin, Alexandre Torgue
Cc: Patrick Delaunay, linux-arm-kernel, linux-kernel, linux-stm32
Inform NVMEM framework of type attribute for stm32-romem as NVMEM_TYPE_OTP
so userspace is able to know how the data is stored in BSEC.
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---
(no changes since v1)
drivers/nvmem/stm32-romem.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/nvmem/stm32-romem.c b/drivers/nvmem/stm32-romem.c
index bb8aa72ba2f9..6de565639d5f 100644
--- a/drivers/nvmem/stm32-romem.c
+++ b/drivers/nvmem/stm32-romem.c
@@ -160,6 +160,7 @@ static int stm32_romem_probe(struct platform_device *pdev)
priv->cfg.dev = dev;
priv->cfg.priv = priv;
priv->cfg.owner = THIS_MODULE;
+ priv->cfg.type = NVMEM_TYPE_OTP;
priv->lower = 0;
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/3] nvmem: stm32: several minor improvements
2022-10-17 15:49 [PATCH v2 0/3] nvmem: stm32: several minor improvements Patrick Delaunay
` (2 preceding siblings ...)
2022-10-17 15:49 ` [PATCH v2 3/3] nvmem: stm32: add nvmem type attribute Patrick Delaunay
@ 2022-10-31 17:41 ` Srinivas Kandagatla
3 siblings, 0 replies; 5+ messages in thread
From: Srinivas Kandagatla @ 2022-10-31 17:41 UTC (permalink / raw)
To: Patrick Delaunay, Maxime Coquelin, Alexandre Torgue
Cc: linux-arm-kernel, linux-kernel, linux-stm32
On 17/10/2022 16:49, Patrick Delaunay wrote:
>
> Several minor improvement for BSEC driver = nvmem stm32 romem
> - move STM32MP15_BSEC_NUM_LOWER in config, to prepare introduction
> of next STM32MP products with more OTP
> - add warning when upper OTPs are updated to indicate possible ECC issue
> for second update
> - add nvmem type attribute so userspace is able to know how the data is
> stored in OTPs
>
> Changes in v2:
> - Add patch "move STM32MP15_BSEC_NUM_LOWER in config" in the serie,
> solve dependency issue for "priv->lower" in patch "nvmem: stm32:
> add warning when upper OTPs are updated"
>
> Patrick Delaunay (3):
> nvmem: stm32: move STM32MP15_BSEC_NUM_LOWER in config
> nvmem: stm32: add warning when upper OTPs are updated
> nvmem: stm32: add nvmem type attribute
>
Applied thanks,
--srini
> drivers/nvmem/stm32-romem.c | 25 ++++++++++++++++++++-----
> 1 file changed, 20 insertions(+), 5 deletions(-)
>
^ permalink raw reply [flat|nested] 5+ messages in thread